Skip to content

Commit

Permalink
Provide a "deleted" action and view for deletion within iframe views …
Browse files Browse the repository at this point in the history
…(CFM-392) (#233)

* Provide a "deleted" action and view for deletion within iframe views (CFM-392)

* Allow deleted action to conditionally self-close a modal window (CFM-392)

* Trivial refactoring to deleted.php view (CFM-392)

* Improve 'Add Attributes' dropdown (CFM-392)

* Modify a comment (CFM-392)
  • Loading branch information
arlen authored Oct 11, 2024
1 parent dc706b7 commit 8bda023
Show file tree
Hide file tree
Showing 28 changed files with 244 additions and 47 deletions.
6 changes: 6 additions & 0 deletions app/resources/locales/en_US/information.po
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ msgstr "Attribute Modal"
msgid "global.attributes"
msgstr "Attributes"

msgid "global.attributes.none"
msgstr "There are no attributes of this type"

msgid "global.processing"
msgstr "processing..."

msgid "global.records.none"
msgstr "There are no records to display."

Expand Down
3 changes: 3 additions & 0 deletions app/resources/locales/en_US/operation.po
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ msgstr "Add"
msgid "add.a"
msgstr "Add a New {0}"

msgid "add.attribute"
msgstr "Add Attribute"

msgid "add.member"
msgstr "Add member: "

Expand Down
16 changes: 14 additions & 2 deletions app/resources/locales/en_US/result.po
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ msgstr "{0} Activated"
msgid "added.mvea"
msgstr "{0} {1} Added: {2}"

msgid "AdHocAttribute.deleted"
msgstr "Ad hoc attribute deleted"

msgid "applied.schema"
msgstr "Successfully applied database schema"

Expand All @@ -40,14 +43,17 @@ msgid "deleted"
msgstr "Deleted"

msgid "deleted.a"
msgstr "{0} Deleted"
msgstr "{0} deleted"

msgid "deleted.mvea"
msgstr "{0} {1} Deleted: {2}"
msgstr "{0} {1} deleted: {2}"

msgid "edited.mvea"
msgstr "{0} {1} Edited: {2}"

msgid "EmailAddress.deleted"
msgstr "Email address deleted"

msgid "EmailAddresses.verify.forced"
msgstr "Email Address force verified"

Expand Down Expand Up @@ -81,6 +87,9 @@ msgstr "Added {0} to group {1} via nesting of group {2} ({3})"
msgid "GroupMembers.deleted"
msgstr "Removed {0} from group {1}"

msgid "GroupMember.deleted"
msgstr "Removed member from group"

msgid "GroupMembers.deleted.nesting"
msgstr "Removed {0} from group {1} via nesting of group {2} ({3})"

Expand Down Expand Up @@ -196,6 +205,9 @@ msgstr "Search Results"
msgid "search.retry"
msgstr "Please select an option from a menu, or try your search again."

msgid "TelephoneNumber.deleted"
msgstr "Telephone number deleted"

# These are specifically for test command
msgid "test.database.ok"
msgstr "Database connection established"
Expand Down
5 changes: 3 additions & 2 deletions app/src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ protected function primaryLinkLookup(): void

// At the end we need to have a Primary Link
if(empty($this->cur_pl->value)
&& !$this->$modelsName->allowEmptyPrimaryLink($this->request->getParam('action'))) {
&& !$this->$modelsName->allowEmptyPrimaryLink($this->request->getParam('action'))
&& $this->request->getParam('action') != 'deleted') {
throw new \RuntimeException(__d('error', 'primary_link'));
}
}
Expand Down Expand Up @@ -531,7 +532,7 @@ protected function populateAvailableCos() {
*/

protected function setCO() {
if($this->cur_co) {
if($this->cur_co || $this->request->getParam('action') == 'deleted') {
// Nothing to do...
return;
}
Expand Down
16 changes: 16 additions & 0 deletions app/src/Controller/GroupMembersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,20 @@ public function add() {

return parent::add();
}

/**
* Handle the deleted action for a Group Member.
* This is used to set a flash message and override the target window.
*
* @since COmanage Registry v5.0.0
*/

public function deleted() {
// Add a flash message
$this->Flash->information(__d('result','GroupMember.deleted'));
// Set the target window
$this->set('vv_target_window', 'top');

return parent::deleted();
}
}
4 changes: 2 additions & 2 deletions app/src/Controller/MVEAController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function beforeFilter(\Cake\Event\EventInterface $event) {
// $this->name = Models
$modelsName = $this->name;

if(!$this->request->is('restful')) {
if(!$this->request->is('restful') && $this->request->getParam('action') != 'deleted') {
// Provide additional hints to BreadcrumbsComponent. This needs to be here
// and not in beforeRender because the component beforeRender will run first.

Expand Down Expand Up @@ -143,7 +143,7 @@ public function beforeRender(\Cake\Event\EventInterface $event) {
// field = model (or model_name)
$fieldName = Inflector::underscore(Inflector::singularize($modelsName));

if(!$this->request->is('restful')) {
if(!$this->request->is('restful') && $this->request->getParam('action') != 'deleted') {
// If there is a default type setting for this model, pass it to the view
if($this->$modelsName->getSchema()->hasColumn('type_id')) {
$defaultTypeField = "default_" . $fieldName . "_type_id";
Expand Down
2 changes: 1 addition & 1 deletion app/src/Controller/NamesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class NamesController extends MVEAController {
*/

public function beforeRender(\Cake\Event\EventInterface $event) {
if(!$this->request->is('restful')) {
if(!$this->request->is('restful') && $this->request->getParam('action') != 'deleted') {
// Get the set of permitted name fields to pass to the view.
// (We don't need required name fields since FormHelper will handle that.)

Expand Down
42 changes: 38 additions & 4 deletions app/src/Controller/StandardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Cake\ORM\TableRegistry;
use InvalidArgumentException;
use \Cake\Http\Exception\BadRequestException;
use Cake\Utility\Inflector;
use \App\Lib\Enum\ProvisioningContextEnum;
use \App\Lib\Enum\SuspendableStatusEnum;
use \App\Lib\Util\{StringUtilities, FunctionUtilities};
Expand Down Expand Up @@ -169,8 +170,10 @@ public function beforeRender(\Cake\Event\EventInterface $event) {
$table = $this->$modelsName;

// Provide some hints to the views
$this->getFieldTypes();
$this->getRequiredFields();
if($this->request->getParam('action') != 'deleted') {
$this->getFieldTypes();
$this->getRequiredFields();
}

// Set the display field as a view var to make it available to the views
$this->set('vv_display_field', $table->getDisplayField());
Expand Down Expand Up @@ -307,6 +310,34 @@ public function delete($id) {
return $this->redirect(['action' => 'edit', $id]);
}

/**
* Handle a deleted action for a Standard object.
*
* @since COmanage Registry v5.0.0
*/

public function deleted() {
// Set the title when not set at the individual controller
if(empty($this->viewBuilder()->getVar('vv_title'))) {
$modelsName = $this->name;
$fieldName = Inflector::singularize($modelsName);
if(__d('result', $fieldName . '.deleted') != $fieldName . '.deleted') {
// Use the standard (singular) deleted message for the field when it exists
$this->set('vv_title', __d('result', $fieldName . '.deleted'));
} else {
// Build the result from the generic 'deleted.a' language key
$this->set('vv_title', __d('result', 'deleted.a', [$fieldName]));
}
}
// Set the target window when not set at the individual controller.
// This should be 'self' (default) or 'top'.
if (empty($this->viewBuilder()->getVar('vv_target_window'))) {
$this->set('vv_target_window', 'self');
}
// Render the view
$this->render('/Standard/deleted');
}

/**
* Handle an edit action for a Standard object.
*
Expand Down Expand Up @@ -451,8 +482,11 @@ public function generateRedirect($entity) {
$redirectGoal = 'index';
}
}

if($redirectGoal == 'self'

if($redirectGoal == 'deleted') {
// Immediately redirect to the (mostly blank) deleted view
return $this->redirect(['action' => 'deleted']);
} elseif($redirectGoal == 'self'
&& $entity
&& in_array($this->request->getParam('action'), ['add', 'edit'])) {
// We typically want to redirect to the edit view of the record,
Expand Down
2 changes: 1 addition & 1 deletion app/src/Controller/TelephoneNumbersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class TelephoneNumbersController extends MVEAController {
*/

public function beforeRender(\Cake\Event\EventInterface $event) {
if(!$this->request->is('restful')) {
if(!$this->request->is('restful') && $this->request->getParam('action') != 'deleted') {
$CoSettings = TableRegistry::getTableLocator()->get('CoSettings');

$settings = $CoSettings->find()->where(['co_id' => $this->getCOID()])->firstOrFail();
Expand Down
2 changes: 1 addition & 1 deletion app/src/Lib/Traits/PrimaryLinkTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ public function setPrimaryLink($fields) {
*/

public function setRedirectGoal(string $goal, string $action='*') {
if(!in_array($goal, ['index', 'pluggableLink', 'primaryLink', 'self', 'special'])) {
if(!in_array($goal, ['deleted', 'index', 'pluggableLink', 'primaryLink', 'self', 'special'])) {
throw new \InvalidArgumentException(__d('error', 'invalid', [$goal]));
}

Expand Down
4 changes: 3 additions & 1 deletion app/src/Model/Table/AdHocAttributesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function initialize(array $config): void {
$this->setPrimaryLink(['external_identity_id', 'external_identity_role_id', 'person_id', 'person_role_id']);
$this->setRequiresCO(true);
$this->setRedirectGoal('self');
$this->setRedirectGoal(action: 'delete', goal: 'deleted');
$this->setAllowLookupPrimaryLink(['unfreeze']);
$this->setEditContains(['ExternalIdentities', 'ExternalIdentityRoles', 'SourceAdHocAttributes']);

Expand All @@ -103,7 +104,8 @@ public function initialize(array $config): void {
// Actions that operate over a table (ie: do not require an $id)
'table' => [
'add' => ['platformAdmin', 'coAdmin'],
'index' => ['platformAdmin', 'coAdmin']
'index' => ['platformAdmin', 'coAdmin'],
'deleted' => ['platformAdmin', 'coAdmin']
]
]);
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/Model/Table/AddressesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function initialize(array $config): void {
// Models that AcceptCoId should be expicitly added to StandardApiController::initialize()
$this->setAcceptsCoId(true);
$this->setRedirectGoal('self');
$this->setRedirectGoal(action: 'delete', goal: 'deleted');
$this->setAllowLookupPrimaryLink(['unfreeze']);
$this->setEditContains(['ExternalIdentities', 'ExternalIdentityRoles', 'SourceAddresses']);

Expand Down Expand Up @@ -131,7 +132,8 @@ public function initialize(array $config): void {
// Actions that operate over a table (ie: do not require an $id)
'table' => [
'add' => ['platformAdmin', 'coAdmin'],
'index' => ['platformAdmin', 'coAdmin']
'index' => ['platformAdmin', 'coAdmin'],
'deleted' => ['platformAdmin', 'coAdmin']
]
]);
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/Model/Table/EmailAddressesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function initialize(array $config): void {
$this->setAllowLookupPrimaryLink(['primary']);
$this->setRequiresCO(true);
$this->setRedirectGoal('self');
$this->setRedirectGoal(action: 'delete', goal: 'deleted');
$this->setAllowLookupPrimaryLink(['forceVerify', 'unfreeze']);
$this->setEditContains(['ExternalIdentities', 'SourceEmailAddresses']);

Expand All @@ -133,7 +134,8 @@ public function initialize(array $config): void {
// Actions that operate over a table (ie: do not require an $id)
'table' => [
'add' => ['platformAdmin', 'coAdmin'],
'index' => ['platformAdmin', 'coAdmin']
'index' => ['platformAdmin', 'coAdmin'],
'deleted' => ['platformAdmin', 'coAdmin']
]
]);
}
Expand Down
6 changes: 4 additions & 2 deletions app/src/Model/Table/GroupMembersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class GroupMembersTable extends Table {
*/
public function getLayout(string $action = ''): string {
return match($action) {
'add','edit','view' => 'iframe',
'add','edit','view','deleted' => 'iframe',
default => 'default'
};
}
Expand Down Expand Up @@ -93,6 +93,7 @@ public function initialize(array $config): void {
$this->setPrimaryLink(['group_id', 'person_id']);
$this->setRequiresCO(true);
$this->setRedirectGoal('self');
$this->setRedirectGoal(action: 'delete', goal: 'deleted');

$this->setEditContains(['Groups', 'People.PrimaryName']);
$this->setViewContains(['Groups', 'People.PrimaryName']);
Expand Down Expand Up @@ -125,7 +126,8 @@ public function initialize(array $config): void {
// Actions that operate over a table (ie: do not require an $id)
'table' => [
'add' => ['platformAdmin', 'coAdmin'],
'index' => ['platformAdmin', 'coAdmin']
'index' => ['platformAdmin', 'coAdmin'],
'deleted' => ['platformAdmin', 'coAdmin']
]
]);

Expand Down
4 changes: 3 additions & 1 deletion app/src/Model/Table/IdentifiersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function initialize(array $config): void {
$this->setPrimaryLink(['external_identity_id', 'group_id', 'person_id']);
$this->setRequiresCO(true);
$this->setRedirectGoal('self');
$this->setRedirectGoal(action: 'delete', goal: 'deleted');
$this->setAllowLookupPrimaryLink(['unfreeze']);
$this->setEditContains(['ExternalIdentities', 'SourceIdentifiers']);

Expand Down Expand Up @@ -146,7 +147,8 @@ public function initialize(array $config): void {
// Actions that operate over a table (ie: do not require an $id)
'table' => [
'add' => ['platformAdmin', 'coAdmin'],
'index' => ['platformAdmin', 'coAdmin']
'index' => ['platformAdmin', 'coAdmin'],
'deleted' => ['platformAdmin', 'coAdmin']
],
// Related models whose permissions we'll need, typically for table views
'related' => [
Expand Down
4 changes: 3 additions & 1 deletion app/src/Model/Table/NamesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function initialize(array $config): void {
// Models that AcceptCoId should be explicitly added to StandardApiController::initialize()
$this->setAcceptsCoId(true);
$this->setRedirectGoal('self');
$this->setRedirectGoal(action: 'delete', goal: 'deleted');
$this->setEditContains(['ExternalIdentities', 'SourceNames']);

$this->setAutoViewVars([
Expand Down Expand Up @@ -137,7 +138,8 @@ public function initialize(array $config): void {
// Actions that operate over a table (ie: do not require an $id)
'table' => [
'add' => ['platformAdmin', 'coAdmin'],
'index' => ['platformAdmin', 'coAdmin']
'index' => ['platformAdmin', 'coAdmin'],
'deleted' => ['platformAdmin', 'coAdmin']
]
]);
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/Model/Table/PronounsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function initialize(array $config): void {
$this->setPrimaryLink(['external_identity_id', 'person_id']);
$this->setRequiresCO(true);
$this->setRedirectGoal('self');
$this->setRedirectGoal(action: 'delete', goal: 'deleted');
$this->setAllowLookupPrimaryLink(['unfreeze']);
$this->setEditContains(['ExternalIdentities', 'SourcePronouns']);

Expand Down Expand Up @@ -123,7 +124,8 @@ public function initialize(array $config): void {
// Actions that operate over a table (ie: do not require an $id)
'table' => [
'add' => ['platformAdmin', 'coAdmin'],
'index' => ['platformAdmin', 'coAdmin']
'index' => ['platformAdmin', 'coAdmin'],
'deleted' => ['platformAdmin', 'coAdmin']
]
]);
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/Model/Table/TelephoneNumbersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function initialize(array $config): void {
// Models that AcceptCoId should be expicitly added to StandardApiController::initialize()
$this->setAcceptsCoId(true);
$this->setRedirectGoal('self');
$this->setRedirectGoal(action: 'delete', goal: 'deleted');
$this->setAllowLookupPrimaryLink(['unfreeze']);
$this->setEditContains(['ExternalIdentities', 'ExternalIdentityRoles', 'SourceTelephoneNumbers']);

Expand All @@ -128,7 +129,8 @@ public function initialize(array $config): void {
// Actions that operate over a table (ie: do not require an $id)
'table' => [
'add' => ['platformAdmin', 'coAdmin'],
'index' => ['platformAdmin', 'coAdmin']
'index' => ['platformAdmin', 'coAdmin'],
'deleted' => ['platformAdmin', 'coAdmin']
]
]);
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/Model/Table/UrlsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function initialize(array $config): void {
$this->setPrimaryLink(['external_identity_id', 'person_id']);
$this->setRequiresCO(true);
$this->setRedirectGoal('self');
$this->setRedirectGoal(action: 'delete', goal: 'deleted');
$this->setAllowLookupPrimaryLink(['unfreeze']);
$this->setEditContains(['ExternalIdentities', 'ExternalIdentityRoles', 'SourceUrls']);

Expand All @@ -119,7 +120,8 @@ public function initialize(array $config): void {
// Actions that operate over a table (ie: do not require an $id)
'table' => [
'add' => ['platformAdmin', 'coAdmin'],
'index' => ['platformAdmin', 'coAdmin']
'index' => ['platformAdmin', 'coAdmin'],
'deleted' => ['platformAdmin', 'coAdmin']
]
]);
}
Expand Down
Loading

0 comments on commit 8bda023

Please sign in to comment.