Skip to content

Commit

Permalink
Utility that calculates the view and breadcrump title
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Jan 26, 2024
1 parent f88f44e commit 66b4e70
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 140 deletions.
6 changes: 0 additions & 6 deletions app/resources/locales/en_US/operation.po
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ msgstr "Edit"
msgid "edit.a"
msgstr "Edit {0}"

msgid "edit.ai"
msgstr "Edit {0}"

msgid "ExternalIdentitySourceRecords.retrieve"
msgstr "Retrieve from External Identity Source"

Expand Down Expand Up @@ -186,6 +183,3 @@ msgstr "View"
msgid "view.a"
msgstr "View {0}"

msgid "view.ai"
msgstr "View {0}"

7 changes: 6 additions & 1 deletion app/src/Controller/ApiUsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

namespace App\Controller;

use App\Lib\Util\StringUtilities;

class ApiUsersController extends StandardController {
public $paginate = [
'order' => [
Expand Down Expand Up @@ -56,7 +58,10 @@ public function generate(string $id) {

// Let the view render, but tell it to use a different fields file
$this->set('vv_fields_inc', 'fields-generate.inc');
$this->set('vv_title', __d('operation', 'api.key.generate'));
[$title, , ] = StringUtilities::entityAndActionToTitle(null,
'api.key',
$this->request->getParam('action'));
$this->set('vv_title', $title);

$this->render('/Standard/add-edit-view');
}
Expand Down
32 changes: 16 additions & 16 deletions app/src/Controller/Component/BreadcrumbComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ public function injectPrimaryLink(object $link, bool $index=true, string $linkLa

// Construct the get<Request Action>Contains function name
$requestAction = $this->getController()->getRequest()->getParam('action');
// In the case we are dealing with non-standard actions we need to fallback to a standard one
// in order to get access to the contain array. We will use the permissions to decide which
// action to fallback to
if(!in_array($requestAction, [
'index', 'view', 'delete', 'add', 'edit'
])) {
$permissionsArray = $this->getController()->RegistryAuth->calculatePermissionsForView($requestAction);
$id = $this->getController()->getRequest()->getParam('pass')[0] ?? null;
if (isset($id)) {
$requestAction = ( isset($permissionsArray['edit']) && $permissionsArray['edit'] ) ? 'edit' : 'view';
} else {
$requestAction = 'index';
}
}
$containsList = "get" . ucfirst($requestAction) . "Contains";

$linkTable = TableRegistry::getTableLocator()->get($modelPath);
Expand Down Expand Up @@ -226,21 +240,7 @@ public function injectPrimaryLink(object $link, bool $index=true, string $linkLa
'edit';

// The action in the following injectParents dictates the action here
// XXX This is a duplicate from StandardController.
if(method_exists($linkTable, 'generateDisplayField')) {
// We don't use a trait for this since each table will implement different logic

$label = __d('operation', "{$breadcrumbAction}.ai", $linkTable->generateDisplayField($linkObj));
} else {
// Default view title is edit object display field
$field = $linkTable->getDisplayField();

if(!empty($obj->$field)) {
$label = __d('operation', "{$breadcrumbAction}.ai", $obj->$field);
} else {
$label = __d('operation', "{$breadcrumbAction}.ai", __d('controller', $modelsName, [1]));
}
}
[$title,,] = StringUtilities::entityAndActionToTitle($linkObj, $modelPath, $breadcrumbAction);

$this->injectParents[ $linkTable->getTable() . $linkObj->id ] = [
'target' => [
Expand All @@ -249,7 +249,7 @@ public function injectPrimaryLink(object $link, bool $index=true, string $linkLa
'action' => $breadcrumbAction,
$linkObj->id
],
'label' => $linkLabel ?? $label
'label' => $linkLabel ?? $title
];
}

Expand Down
101 changes: 55 additions & 46 deletions app/src/Controller/DashboardsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
namespace App\Controller;

// XXX not doing anything with Log yet
use App\Lib\Util\StringUtilities;
use Cake\Log\Log;
use Cake\ORM\TableRegistry;
use Cake\Utility\Hash;
Expand All @@ -45,14 +46,14 @@ class DashboardsController extends StandardController {

public function initialize(): void {
parent::initialize();

// Configure breadcrumb rendering
$this->Breadcrumb->skipConfig([
'/^\/dashboards\/artifacts/',
'/^\/dashboards\/dashboard/',
'/^\/dashboards\/registries/',
'/^\/dashboards\/search/'
]);
'/^\/dashboards\/artifacts/',
'/^\/dashboards\/dashboard/',
'/^\/dashboards\/registries/',
'/^\/dashboards\/search/'
]);
// There is currently no inventory of dashboards, so we skip parents
// for configuration, dashboard, and registries actions
$this->Breadcrumb->skipParents(['/^\/dashboards/']);
Expand All @@ -63,19 +64,23 @@ public function initialize(): void {
*
* @since COmanage Registry v5.0.0
*/

public function configuration() {
$cur_co = $this->getCO();

$this->set('vv_title', __d('menu', 'co.features.all'));


[$title, , ] = StringUtilities::entityAndActionToTitle(null,
'co.features',
'all',
'menu');
$this->set('vv_title', $title);

// Construct the set of configuration items. For everything except CO Settings
// we want to order by the localized text string.

// We're assuming that the permission for each of these items is the same as for
// configuration() itself, ie: CMP or CO Admin. But plausibly some of this stuff
// could be delegated to (eg) a COU Admin at some point...

$configMenuItems = [
__d('controller', 'ApiUsers', [99]) => [
'icon' => 'vpn_key',
Expand Down Expand Up @@ -107,7 +112,7 @@ public function configuration() {
'controller' => 'provisioning_targets',
'action' => 'index'
],
// XXX restore when Reports are ready to be exposed.
// XXX restore when Reports are ready to be exposed.
// __d('controller', 'Reports', [99]) => [
// 'icon' => 'summarize',
// 'controller' => 'reports',
Expand All @@ -119,27 +124,27 @@ public function configuration() {
'action' => 'index'
]
];

ksort($configMenuItems);

// Insert CO Settings to the front of the list

$configMenuItems = array_merge([
__d('controller', 'CoSettings', [99]) => [
'icon' => 'settings',
'controller' => 'co_settings',
'action' => 'manage'
]],
$configMenuItems
__d('controller', 'CoSettings', [99]) => [
'icon' => 'settings',
'controller' => 'co_settings',
'action' => 'manage'
]],
$configMenuItems
);

$this->set('vv_configuration_menu_items', $configMenuItems);

$platformMenuItems = [];

if($this->getCOID() == 1) {
// Also pass the platform menu items

$platformMenuItems = [
__d('controller', 'Cos', [99]) => [
'icon' => 'home',
Expand All @@ -153,11 +158,10 @@ public function configuration() {
]
];
}

ksort($platformMenuItems);

$this->set('vv_platform_menu_items', $platformMenuItems);

$registryMenuItems = [
__d('controller', 'Groups', [99]) => [
'icon' => 'people',
Expand All @@ -175,11 +179,11 @@ public function configuration() {
'action' => 'index'
]
];

ksort($registryMenuItems);

$this->set('vv_registries_menu_items', $registryMenuItems);

$artifactMenuItems = [
__d('controller', 'ExtIdentitySourceRecords', [99]) => [
'icon' => 'assignment',
Expand All @@ -192,19 +196,18 @@ public function configuration() {
'action' => 'index'
]
];

ksort($artifactMenuItems);

$this->set('vv_artifacts_menu_items', $artifactMenuItems);
}

/**
* Render a Dashboard.
*
* @since COmanage Registry v5.0.0
* @param int $id Dashboard ID
*/

public function dashboard(?int $id=null) {
// XXX placeholder
}
Expand All @@ -214,15 +217,15 @@ public function dashboard(?int $id=null) {
*
* @since COmanage Registry v5.0.0
*/

public function search() {
/* To add a new backend to search:
* (1) Implement $model->search($id, $q, $limit)
* (2) Add the model to $models here, and define which roles can query it
* (3) Update documentation at https://spaces.at.internet2.edu/pages/viewpage.action?pageId=243078053
*/
$models = [

$models = [
'Addresses' => [
'parent' => ['People' => 'person_id', 'PersonRoles' => 'person_role_id'],
'roles' => ['platformAdmin', 'coAdmin'],
Expand Down Expand Up @@ -293,7 +296,7 @@ public function search() {
// A search was passed in from the form on the Global Search bar.
$q = trim($this->request->getData('q'));
}

// Only process the request if we have a string of non-space characters
if(!empty($q)) {

Expand Down Expand Up @@ -358,7 +361,7 @@ public function search() {
// or if there is a single result overall, redirect to that result.
if((count($results['Cos']) == 0
&& (count($results['People']) + count($results['Groups'])) == 1)
||
||
(count($results['Cos']) == 1
&& (count($results['People']) + count($results['Groups'])) == 0)) {
// Figure out which model matched, as well as the target model to redirect to
Expand All @@ -373,18 +376,18 @@ public function search() {
$matchClass = array_key_first($results[$m][$targetRecordId]);
}
}

$this->Flash->information(__d('result',
'search.exact',
[filter_var($this->request->getData('q'), FILTER_SANITIZE_SPECIAL_CHARS),
__d('controller', $matchClass, [1])]));
__d('controller', $matchClass, [1])]));

// Redirect to the matchClass controller
return $this->redirect([
'controller' => Inflector::dasherize($targetClass),
'action' => 'edit',
$targetRecordId
]);
'controller' => Inflector::dasherize($targetClass),
'action' => 'edit',
$targetRecordId
]);

// XXX handle plugins
} elseif(count($results['Cos'])
Expand All @@ -394,6 +397,12 @@ public function search() {
}

$this->set('vv_results', $results);
$this->set('vv_title', __d('result', 'search.results'));
// XXX The action is search and the result is not a modelPath. In this use the pattern is reversed. We should
// probably reconsider the po naming for the result domain
[$title, , ] = StringUtilities::entityAndActionToTitle(null,
'search',
'results',
'result');
$this->set('vv_title', $title);
}
}
31 changes: 19 additions & 12 deletions app/src/Controller/ExternalIdentitySourcesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
namespace App\Controller;

// XXX not doing anything with Log yet
use App\Lib\Util\StringUtilities;
use Cake\Log\Log;
use Cake\ORM\TableRegistry;

Expand Down Expand Up @@ -109,15 +110,19 @@ public function retrieve(string $id) {

$this->set('vv_eis_record', $this->ExternalIdentitySources->retrieve((int)$id, $source_key));

$this->set('vv_external_identity_record', $this->ExternalIdentitySources
->ExtIdentitySourceRecords
->find()
->where(['ExtIdentitySourceRecords.source_key' => $source_key,
'ExtIdentitySourceRecords.external_identity_source_id' => $id])
->contain(['ExternalIdentities'])
->first());

$this->set('vv_title', __d('operation', 'view.a', [$source_key]));
$externalIdentityRecordObj = $this->ExternalIdentitySources
->ExtIdentitySourceRecords
->find()
->where(['ExtIdentitySourceRecords.source_key' => $source_key,
'ExtIdentitySourceRecords.external_identity_source_id' => $id])
->contain(['ExternalIdentities'])
->first();
$this->set('vv_external_identity_record', $externalIdentityRecordObj);

[$title, , ] = StringUtilities::entityAndActionToTitle($externalIdentityRecordObj,
StringUtilities::entityToClassName($externalIdentityRecordObj),
'view');
$this->set('vv_title', $title);
}
catch(\Exception $e) {
$this->Flash->error($e->getMessage());
Expand Down Expand Up @@ -152,7 +157,10 @@ public function search(string $id) {

$this->set('vv_search_attrs', $this->ExternalIdentitySources->searchableAttributes((int)$id));

$this->set('vv_title', __d('operation', 'ExternalIdentitySources.search'));
[$title, , ] = StringUtilities::entityAndActionToTitle(null,
$this->getName(),
$this->request->getParam('action'));
$this->set('vv_title', $title);
}

/**
Expand All @@ -167,9 +175,8 @@ public function sync(string $id) {
$source_key = $this->request->getQuery('source_key');

$this->ExternalIdentitySources->sync((int)$id, $source_key);
// XXX Sync does not have a view. We do not need to set a title. Yet need to fetch the updated Identity
$this->set('vv_eis_record', $this->ExternalIdentitySources->retrieve((int)$id, $source_key));

$this->set('vv_title', __d('operation', 'view.a', [$source_key]));

$this->Flash->success(__d('result', 'ExternalIdentitySources.synced'));
}
Expand Down
Loading

0 comments on commit 66b4e70

Please sign in to comment.