From a87f1810a98de3d0381ac91172de0fa3cc59a020 Mon Sep 17 00:00:00 2001 From: Arlen Johnson Date: Fri, 23 May 2025 12:39:22 -0400 Subject: [PATCH] Improve Relink UI and add People Picker (CFM-125) --- app/resources/locales/en_US/field.po | 3 ++ .../ExternalIdentitiesController.php | 4 ++- app/src/Lib/Util/StringUtilities.php | 16 ++++++++++ .../Model/Table/ExternalIdentitiesTable.php | 10 ++++++ app/templates/ExternalIdentities/relink.php | 32 ++++++++++++++++--- app/templates/element/form/listItem.php | 2 +- 6 files changed, 61 insertions(+), 6 deletions(-) diff --git a/app/resources/locales/en_US/field.po b/app/resources/locales/en_US/field.po index 8350a7254..d72e729d5 100644 --- a/app/resources/locales/en_US/field.po +++ b/app/resources/locales/en_US/field.po @@ -471,6 +471,9 @@ msgstr "Redirect on Duplicate" msgid "EnrollmentFlows.redirect_on_finalize" msgstr "Redirect on Finalize" +msgid "ExternalIdentitySources.target_person_id" +msgstr "Target Person" + msgid "ExternalIdentitySources.hash_source_record" msgstr "Hash Source Records" diff --git a/app/src/Controller/ExternalIdentitiesController.php b/app/src/Controller/ExternalIdentitiesController.php index 3fb9427ab..bcea82618 100644 --- a/app/src/Controller/ExternalIdentitiesController.php +++ b/app/src/Controller/ExternalIdentitiesController.php @@ -31,6 +31,7 @@ use Cake\Event\EventInterface; use Cake\Http\Response; +use \App\Lib\Util\StringUtilities; use Cake\ORM\TableRegistry; // Use extend MVEAController for breadcrumb rendering. ExternalIdentities is @@ -87,6 +88,7 @@ public function beforeRender(EventInterface $event) { // Pull the Person name for breadcrumb rendering $link = $this->getPrimaryLink(true); + $this->populateAutoViewVars(); if(!empty($link->value)) { $this->set('vv_bc_parent_obj', $this->ExternalIdentities->People->get($link->value)); @@ -112,7 +114,7 @@ public function relink(string $id) { try { $Pipelines = TableRegistry::getTableLocator()->get('Pipelines'); - $Pipelines->relink((int)$id, (int)$reqData['target_person_id']); + $Pipelines->relink((int)$id, StringUtilities::extractPeoplePickerPersonId($reqData['target_person_id'])); $this->Flash->success(__d('result', 'ExternalIdentities.relinked', [$id, $reqData['target_person_id']])); diff --git a/app/src/Lib/Util/StringUtilities.php b/app/src/Lib/Util/StringUtilities.php index ba4da3cd7..370530b13 100644 --- a/app/src/Lib/Util/StringUtilities.php +++ b/app/src/Lib/Util/StringUtilities.php @@ -225,6 +225,22 @@ public static function entityAndActionToTitle($entity, return [$title, $supertitle, $subtitle]; } + /** + * Extract and return the Person ID from a People Picker string + * + * @since COmanage Registry v5.2.0 + * @param string $s Person string from the People Picker widget, e.g. "Jane+Doe+(ID:+2125)" + * @return int extracted Person ID (converted to int from the extracted string) + */ + + public static function extractPeoplePickerPersonId(string $s): int { + // Regular expression for handling People Picker input + $re = '/^.*\(ID: (\d+)\)$/m'; + // Extract the People Picker Person ID + preg_match_all($re, $s, $matchesTarget, PREG_SET_ORDER, 0); + return (int)$matchesTarget[0][1]; + } + /** * Determine the class name from a foreign key (eg: report_id -> Reports). * diff --git a/app/src/Model/Table/ExternalIdentitiesTable.php b/app/src/Model/Table/ExternalIdentitiesTable.php index c3f91fad0..6ba9a0d78 100644 --- a/app/src/Model/Table/ExternalIdentitiesTable.php +++ b/app/src/Model/Table/ExternalIdentitiesTable.php @@ -149,6 +149,16 @@ public function initialize(array $config): void { 'type' => 'enum', // XXX maybe this (and EIRoles) should be SuspendableStatusEnum? 'class' => 'StatusEnum' + ], + // Required for peoplePicker (for re-linking) + 'cosettings' => [ + 'type' => 'auxiliary', + 'model' => 'CoSettings' + ], + // Required for peoplePicker (for re-linking) + 'types' => [ + 'type' => 'auxiliary', + 'model' => 'Types' ] ]); diff --git a/app/templates/ExternalIdentities/relink.php b/app/templates/ExternalIdentities/relink.php index ea7d1ae42..61ece15dd 100644 --- a/app/templates/ExternalIdentities/relink.php +++ b/app/templates/ExternalIdentities/relink.php @@ -43,9 +43,33 @@ ]); print $this->Form->hidden('external_identity_id', ['default' => $vv_external_identity->id]); -// This label isn't localized, but it should go away when the UX is fixed - print $this->Form->control('target_person_id', ['type' => 'integer', 'label' => 'Target Person ID']); - - print $this->Form->submit(); +?> + +Form->end(); \ No newline at end of file diff --git a/app/templates/element/form/listItem.php b/app/templates/element/form/listItem.php index 0705a57b1..83cee28df 100644 --- a/app/templates/element/form/listItem.php +++ b/app/templates/element/form/listItem.php @@ -29,7 +29,7 @@ declare(strict_types = 1); // Make the element configuration available downstream -// XXX Unfortunately CAKEPHP doe not create a viewvar space for the element +// XXX Unfortunately CAKEPHP does not create a viewvar space for the element // parameters. As a result we do not know which one is which unless we: // - add a prefix and create a namespace // - wrap them in an array.