From 07dbd357d18623c44f98c2cbebd5451eedf774bf Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Tue, 23 Sep 2025 19:14:21 +0300 Subject: [PATCH] Fix login identifier breadcrumbs --- .../Model/Table/IdentifierMappersTable.php | 2 +- .../Model/Table/LoginIdentifierTypesTable.php | 11 +++++ .../src/Model/Table/SqlSourcesTable.php | 3 +- .../src/Model/Table/EnvSourcesTable.php | 3 +- .../Model/Table/SshKeyAuthenticatorsTable.php | 2 +- .../Controller/StandardPluginController.php | 45 +++++++++++++++++-- app/src/Lib/Traits/BreadcrumbsTrait.php | 2 +- app/src/Model/Table/PetitionsTable.php | 2 +- 8 files changed, 61 insertions(+), 9 deletions(-) diff --git a/app/availableplugins/PipelineToolkit/src/Model/Table/IdentifierMappersTable.php b/app/availableplugins/PipelineToolkit/src/Model/Table/IdentifierMappersTable.php index 95ea8c9af..80f494689 100644 --- a/app/availableplugins/PipelineToolkit/src/Model/Table/IdentifierMappersTable.php +++ b/app/availableplugins/PipelineToolkit/src/Model/Table/IdentifierMappersTable.php @@ -157,7 +157,7 @@ public function buildRelatedAttributes( * @return string Display field */ public function generateDisplayField(\PipelineToolkit\Model\Entity\IdentifierMapper $entity): string { - return $entity->flange->description; + return $entity->name ?? $entity->description ?? $entity->flange->description; } /** diff --git a/app/availableplugins/PipelineToolkit/src/Model/Table/LoginIdentifierTypesTable.php b/app/availableplugins/PipelineToolkit/src/Model/Table/LoginIdentifierTypesTable.php index a207b9587..2b0daa643 100644 --- a/app/availableplugins/PipelineToolkit/src/Model/Table/LoginIdentifierTypesTable.php +++ b/app/availableplugins/PipelineToolkit/src/Model/Table/LoginIdentifierTypesTable.php @@ -118,6 +118,17 @@ public function buildRules(RulesChecker $rules): RulesChecker { return $rules; } + /** + * Table specific logic to generate a display field. + * + * @since COmanage Registry v5.2.0 + * @param \PipelineToolkit\Model\Entity\LoginIdentifierType $entity Entity to generate display field for + * @return string Display field + */ + public function generateDisplayField(\PipelineToolkit\Model\Entity\LoginIdentifierType $entity): string { + return __d('pipeline_toolkit', 'controller.LoginIdentifierTypes', [1]); + } + /** * Application Rule to determine if a specific Type is already configured. * diff --git a/app/availableplugins/SqlConnector/src/Model/Table/SqlSourcesTable.php b/app/availableplugins/SqlConnector/src/Model/Table/SqlSourcesTable.php index 9d71f7d51..a311196e1 100644 --- a/app/availableplugins/SqlConnector/src/Model/Table/SqlSourcesTable.php +++ b/app/availableplugins/SqlConnector/src/Model/Table/SqlSourcesTable.php @@ -249,7 +249,8 @@ protected function getChanges( * @return string Display field */ public function generateDisplayField(\SqlConnector\Model\Entity\SqlSource $entity): string { - return __d('sql_connector', 'display.SqlSource', [$entity->external_identity_source->description]); + $value = $entity->name ?? $entity->description ?? $entity->external_identity_source->description; + return __d('sql_connector', 'display.SqlSource', [$value]); } diff --git a/app/plugins/EnvSource/src/Model/Table/EnvSourcesTable.php b/app/plugins/EnvSource/src/Model/Table/EnvSourcesTable.php index 398a231eb..2eec1c233 100644 --- a/app/plugins/EnvSource/src/Model/Table/EnvSourcesTable.php +++ b/app/plugins/EnvSource/src/Model/Table/EnvSourcesTable.php @@ -173,7 +173,8 @@ public function initialize(array $config): void { * @return string Display field */ public function generateDisplayField(\EnvSource\Model\Entity\EnvSource $entity): string { - return __d('env_source', 'display.EnvSource', [$entity->external_identity_source->description]); + $value = $entity->name ?? $entity->description ?? $entity->external_identity_source->description; + return __d('env_source', 'display.EnvSource', [$value]); } /** diff --git a/app/plugins/SshKeyAuthenticator/src/Model/Table/SshKeyAuthenticatorsTable.php b/app/plugins/SshKeyAuthenticator/src/Model/Table/SshKeyAuthenticatorsTable.php index 1a6978365..979ac48ae 100644 --- a/app/plugins/SshKeyAuthenticator/src/Model/Table/SshKeyAuthenticatorsTable.php +++ b/app/plugins/SshKeyAuthenticator/src/Model/Table/SshKeyAuthenticatorsTable.php @@ -106,7 +106,7 @@ public function initialize(array $config): void { * @return string Display field */ public function generateDisplayField(\SshKeyAuthenticator\Model\Entity\SshKeyAuthenticator $entity): string { - return $entity->authenticator->description; + return $entity->name ?? $entity->description ?? $entity->authenticator->description; } /** diff --git a/app/src/Controller/StandardPluginController.php b/app/src/Controller/StandardPluginController.php index 972e19ab2..c9ab7382f 100644 --- a/app/src/Controller/StandardPluginController.php +++ b/app/src/Controller/StandardPluginController.php @@ -139,8 +139,10 @@ public function beforeRender(\Cake\Event\EventInterface $event) { // For the Pipeline Toolkit if($this->getPlugin() == 'PipelineToolkit') { $identifierMapperTable = $this->fetchTable(IdentifierMappersTable::class); + $identifierMapperEntity = null; + // Edit/View - if ($this->viewBuilder()->getVar('vv_obj') && $request->getParam('action') != 'add') { + if ($this->viewBuilder()->getVar('vv_obj') && $request->getParam('action') !== 'add') { $obj = $this->viewBuilder()->getVar('vv_obj'); // Load IdentifierMapper if identifier_mapper_id is set if (empty($obj->identifier_mapper_id) && $obj->getSource() !== 'PipelineToolkit.IdentifierMappers') { @@ -159,9 +161,46 @@ public function beforeRender(\Cake\Event\EventInterface $event) { throw new \RuntimeException('Identifier Mapper Record not found'); } $this->set('vv_identifier_mapper', $identifierMapperEntity); - $breadcrumbs = $this->buildPipelineBreadcrumbs($identifierMapperEntity); + + // Always add pipeline/flange breadcrumbs from the mapper entity + $pipelineCrumbs = $this->buildPipelineBreadcrumbs($identifierMapperEntity); + + // Conditionally add the two extra crumbs ONLY when the current entity has identifier_mapper_id + $extraCrumbs = []; + $vvObj = $this->viewBuilder()->getVar('vv_obj'); + if ($request->getParam('action') === 'edit' + && $vvObj instanceof \Cake\Datasource\EntityInterface + && (int)($vvObj->get('identifier_mapper_id') ?? 0) > 0) { + + $identifierMapperId = (int)$vvObj->get('identifier_mapper_id'); + + // Identifier Mapper edit + $extraCrumbs['identifier_mappers:' . $identifierMapperId] = [ + 'label' => __('Identifier Mappers'), + 'target' => [ + 'plugin' => 'PipelineToolkit', + 'controller' => 'IdentifierMappers', + 'action' => 'edit', + $identifierMapperId, + ], + ]; + + // Current entity index filtered by identifier_mapper_id + $controller = (string)$request->getParam('controller'); + $plugin = (string)($request->getParam('plugin') ?? ''); + $extraCrumbs[strtolower($controller) . ':index:' . $identifierMapperId] = [ + 'label' => \App\Lib\Util\StringUtilities::localizeController($controller, $plugin ?: null, true), + 'target' => [ + 'plugin' => $plugin ?: null, + 'controller' => $controller, + 'action' => 'index', + '?' => ['identifier_mapper_id' => $identifierMapperId], + ], + ]; + } + $vv_bc_parents = (array)$this->viewBuilder()->getVar('vv_bc_parents'); - $this->set('vv_bc_parents', [...$breadcrumbs, ...$vv_bc_parents]); + $this->set('vv_bc_parents', [...$pipelineCrumbs, ...$extraCrumbs, ...$vv_bc_parents]); } return parent::beforeRender($event); diff --git a/app/src/Lib/Traits/BreadcrumbsTrait.php b/app/src/Lib/Traits/BreadcrumbsTrait.php index c90902bda..be4614cbf 100644 --- a/app/src/Lib/Traits/BreadcrumbsTrait.php +++ b/app/src/Lib/Traits/BreadcrumbsTrait.php @@ -297,4 +297,4 @@ protected function buildPipelineBreadcrumbs(EntityInterface $entity): array return $parents; } -} \ No newline at end of file +} diff --git a/app/src/Model/Table/PetitionsTable.php b/app/src/Model/Table/PetitionsTable.php index 4ee4ecac6..402120408 100644 --- a/app/src/Model/Table/PetitionsTable.php +++ b/app/src/Model/Table/PetitionsTable.php @@ -150,7 +150,7 @@ public function initialize(array $config): void { 'type' => 'enum', 'class' => 'PetitionStatusEnum' ], - 'couIds' => [ + 'cous' => [ 'type' => 'select', 'model' => 'Cous' ]