From 21c132941faf4109e881f8f4a6e09612774d370b Mon Sep 17 00:00:00 2001 From: Benn Oshrin Date: Mon, 31 Mar 2025 16:22:34 +0100 Subject: [PATCH] Disable renaming of Matchgrid table_name (CO-2441) --- app/resources/locales/en_US/default.po | 3 +++ app/src/Model/Table/MatchgridsTable.php | 24 ++++++++++++++++++++++++ app/templates/Matchgrids/columns.inc | 3 +++ 3 files changed, 30 insertions(+) diff --git a/app/resources/locales/en_US/default.po b/app/resources/locales/en_US/default.po index 4caee09a9..26730c74e 100644 --- a/app/resources/locales/en_US/default.po +++ b/app/resources/locales/en_US/default.po @@ -357,6 +357,9 @@ msgstr "A Matchgrid with table name {0} already exists" msgid "match.er.mg.notfound" msgstr "Matchgrid table not found, was the Matchgrid built? ({0})" +msgid "match.er.mg.rename" +msgstr "A Matchgrid cannot be renamed" + msgid "match.er.mgid" msgstr "Could not find Matchgrid ID in request" diff --git a/app/src/Model/Table/MatchgridsTable.php b/app/src/Model/Table/MatchgridsTable.php index 83c63ec04..c8ad0a8c4 100644 --- a/app/src/Model/Table/MatchgridsTable.php +++ b/app/src/Model/Table/MatchgridsTable.php @@ -162,6 +162,12 @@ public function buildRules(RulesChecker $rules): RulesChecker { 'isActive', ['errorField' => 'status']); + // The Matchgrid table name cannot be changed once created. For a discussion of + // the complexities of renaming a Matchgrid, see CO-2441. + $rules->addUpdate([$this, 'ruleMatchgridRenamed'], + 'matchgridRenamed', + ['errorField' => 'table_name']); + return $rules; } @@ -277,6 +283,24 @@ public function ruleIsUnique($entity, array $options): bool|string { return true; } + + /** + * Application Rule to determine if the Matchgrid is being renamed. + * + * @param Entity $entity Entity to be validated + * @param array $options Application rule options + * + * @return bool|string true if the Rule check passes, false otherwise + * @since COmanage Match v1.2.2 + */ + + public function ruleMatchgridRenamed($entity, array $options): bool|string { + if($entity->isDirty('table_name')) { + return __('match.er.mg.rename'); + } + + return true; + } /** * Determine if the Matchgrid table exists. diff --git a/app/templates/Matchgrids/columns.inc b/app/templates/Matchgrids/columns.inc index c001f7bee..e4cfd69ae 100644 --- a/app/templates/Matchgrids/columns.inc +++ b/app/templates/Matchgrids/columns.inc @@ -30,6 +30,9 @@ $indexColumns = [ 'type' => 'link', 'cssClass' => 'row-link' ], + 'description' => [ + 'type' => 'echo' + ], 'status' => [ 'type' => 'enum', 'class' => 'StatusEnum'