Skip to content

Commit

Permalink
Fix implementation of AR-COU-2 (CO-2966)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Mar 7, 2026
1 parent cb5b71d commit 940a406
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/resources/locales/en_US/error.po
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ msgstr "Authenticator is not currently locked"
msgid "Cos.active"
msgstr "Requested CO {0} is not active"

msgid "Cous.children"
msgstr "Cous has {0} child(ren) and cannot be deleted"

msgid "EmailAddresses.mail.delivery"
msgstr "No verified Email Address is available for Person {0}"

Expand Down
26 changes: 26 additions & 0 deletions app/src/Model/Table/CousTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ public function initialize(array $config): void {
*/

public function buildRules(RulesChecker $rules): RulesChecker {
// AR-COU-2 A COU may not be deleted if it has any children.
$rules->addDelete([$this, 'ruleHasChildren'],
'hasChildrenDelete',
['errorField' => 'parent_id']);

// AR-COU-3 Two COUs within the same CO cannot share the same name
$rules->add($rules->isUnique(['name', 'co_id'], __d('error', 'exists', [__d('controller', 'Cous', [1])])));

Expand Down Expand Up @@ -284,6 +289,27 @@ public function postClone(
dataSource: $targetDataSource
);
}

/**
* Application Rule to determine if the group has children.
*
* @since COmanage Registry v5.2.0
* @param Entity $entity Entity to be validated
* @param array $options Application rule options
* @return boolean true if the Rule check passes, false otherwise
*/

public function ruleHasChildren($entity, $options) {
$count = $this->find('all')
->where(['parent_id' => $entity->id])
->count();

if($count > 0) {
return __d('error', 'Cous.children', [$count]);
}

return true;
}

/**
* Perform initial setup for a COU.
Expand Down

0 comments on commit 940a406

Please sign in to comment.