Skip to content

Commit

Permalink
SqlSource display field
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Sep 16, 2025
1 parent 4972cbd commit 9115bfc
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
msgid "controller.SqlProvisioners"
msgstr "{0,plural,=1{SQL Provisioner} other{SQL Provisioners}}"

msgid "display.SqlSource"
msgstr "{0} Source"

msgid "enumeration.SqlSourceTableModeEnum.FL"
msgstr "Flat"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class SqlSourcesTable extends Table {
use \App\Lib\Traits\LabeledLogTrait;
use \App\Lib\Traits\PermissionsTrait;
use \App\Lib\Traits\PrimaryLinkTrait;
use \App\Lib\Traits\QueryModificationTrait;
use \App\Lib\Traits\TabTrait;
use \App\Lib\Traits\TableMetaTrait;
use \App\Lib\Traits\ValidationTrait;
Expand Down Expand Up @@ -106,6 +107,16 @@ public function initialize(array $config): void {

$this->setPrimaryLink(['external_identity_source_id']);
$this->setRequiresCO(true);

$this->setEditContains([
'Servers' => ['SqlServers'],
'ExternalIdentitySources',
]);

$this->setViewContains([
'Servers' => ['SqlServers'],
'ExternalIdentitySources',
]);

$this->setAutoViewVars([
'addressTypes' => [
Expand Down Expand Up @@ -230,6 +241,18 @@ protected function getChanges(
return false;
}

/**
* Table specific logic to generate a display field.
*
* @since COmanage Registry v5.2.0
* @param \SqlConnector\Model\Entity\SqlSource $entity Entity to generate display field for
* @return string Display field
*/
public function generateDisplayField(\SqlConnector\Model\Entity\SqlSource $entity): string {
return __d('sql_connector', 'display.SqlSource', [$entity->external_identity_source->description]);
}


/**
* Obtain the set of changed records from the source database.
*
Expand Down
3 changes: 3 additions & 0 deletions app/plugins/EnvSource/resources/locales/en_US/env_source.po
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ msgstr "{0,plural,=1{Env Source} other{Env Sources}}"
msgid "controller.PetitionEnvIdentities"
msgstr "{0,plural,=1{Petition Env Identity} other{Petition Env Identities}}"

msgid "display.EnvSource"
msgstr "{0} Source"

msgid "enumeration.EnvSourceSpModeEnum.O"
msgstr "Other"

Expand Down
20 changes: 20 additions & 0 deletions app/plugins/EnvSource/src/Model/Table/EnvSourcesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class EnvSourcesTable extends Table {
use \App\Lib\Traits\LabeledLogTrait;
use \App\Lib\Traits\PermissionsTrait;
use \App\Lib\Traits\PrimaryLinkTrait;
use \App\Lib\Traits\QueryModificationTrait;
use \App\Lib\Traits\TabTrait;
use \App\Lib\Traits\TableMetaTrait;
use \App\Lib\Traits\ValidationTrait;
Expand Down Expand Up @@ -97,6 +98,14 @@ public function initialize(array $config): void {
$this->setPrimaryLink(['external_identity_source_id']);
$this->setRequiresCO(true);

$this->setEditContains([
'ExternalIdentitySources',
]);

$this->setViewContains([
'ExternalIdentitySources',
]);

// All the tabs share the same configuration in the ModelTable file
$this->setTabsConfig(
[
Expand Down Expand Up @@ -156,6 +165,17 @@ public function initialize(array $config): void {
]);
}

/**
* Table specific logic to generate a display field.
*
* @since COmanage Registry v5.2.0
* @param \EnvSource\Model\Entity\EnvSource $entity Entity to generate display field for
* @return string Display field
*/
public function generateDisplayField(\EnvSource\Model\Entity\EnvSource $entity): string {
return __d('env_source', 'display.EnvSource', [$entity->external_identity_source->description]);
}

/**
* Obtain the set of changed records from the source database.
*
Expand Down
37 changes: 24 additions & 13 deletions app/src/Controller/Component/BreadcrumbComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ public function injectPrimaryLink(object $link, bool $index = true, string $link
);

return $canEdit ? 'edit' : ($canView ? 'view' : '');
}
},
forChainItem: true
);

$linkTable = \Cake\ORM\TableRegistry::getTableLocator()->get($linkModelFqn);
Expand Down Expand Up @@ -391,30 +392,38 @@ private function resolveContainList($table, string $mappedAction): array
* @param int|null $currentId Current entity ID
* @param array $pagePermissions Permissions for the current page
* @param callable $peopleActionOverride Override callback for People actions
* @param bool $forChainItem Explicit call for a chain item (e.g. add)
* @return string Mapped action name
* @since COmanage Registry v5.2.0
*/
private function mapActionForBreadcrumb(
string $requestAction,
?int $currentId,
array $pagePermissions,
callable $peopleActionOverride
callable $peopleActionOverride,
bool $forChainItem
): string {
// Custom override for People if provided
$override = $peopleActionOverride();
if ($override !== '') {
return $override;
}

if (in_array($requestAction, ['index', 'view', 'delete', 'add', 'edit'], true)) {
return $requestAction;
}

if ($currentId !== null) {
return (!empty($pagePermissions['edit'])) ? 'edit' : 'view';
if ($forChainItem) {
// Never render 'add' for chain items
if ($requestAction === 'add') {
return 'index';
}
// If the current page is edit/view/delete (and thus has an entity), prefer edit/view
if (in_array($requestAction, ['edit', 'view', 'delete'], true) && $currentId !== null) {
return (!empty($pagePermissions['edit'])) ? 'edit' : 'view';
}
return in_array($requestAction, ['index', 'view', 'delete', 'edit'], true)
? $requestAction
: 'index';
}

return 'index';
// If you ever reuse this for non-chain items, decide appropriate behavior here
return $requestAction;
}

/**
Expand All @@ -427,15 +436,17 @@ private function mapActionForBreadcrumb(
*/
private function determineEntityAction($entity, string $mappedAction): string
{
if ($mappedAction === 'add' || $mappedAction === 'delete') {
return $mappedAction;
// Only allow 'delete' to pass through; never return 'add' for existing entities
if ($mappedAction === 'delete') {
return 'delete';
}

if (method_exists($entity, 'isReadOnly')) {
return $entity->isReadOnly() ? 'view' : 'edit';
}

return $mappedAction;
// Fall back to mapped action when not 'add'/'delete'
return $mappedAction === 'add' ? 'view' : $mappedAction;
}

/**
Expand Down

0 comments on commit 9115bfc

Please sign in to comment.