Skip to content

Commit

Permalink
Additional commit for Groups (CFM-38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Jun 20, 2022
1 parent e355ea2 commit 1770206
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
14 changes: 10 additions & 4 deletions app/src/Model/Table/CosTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,16 @@ public function findCOmanageCO(Query $query): Query {
*/

public function localAfterSave(\Cake\Event\EventInterface $event, \Cake\Datasource\EntityInterface $entity, \ArrayObject $options) {
if($entity->isNew() && !empty($entity->id)) {
// Run setup for new CO

$this->setup($entity->id);
if(!empty($entity->id)) {
if($entity->isNew()) {
// Run setup for new CO

$this->setup($entity->id);
} elseif($entity->getOriginal('name') != $entity->get('name')) {
// AR-CO-7 The name was changed, so we may need to update the system groups

$this->Groups->addDefaults(coId: $entity->id, couId: null, rename: true);
}
}

return true;
Expand Down
22 changes: 19 additions & 3 deletions app/src/Model/Table/CousTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,23 @@ public function buildRules(RulesChecker $rules): RulesChecker {
*/

public function localAfterSave(\Cake\Event\EventInterface $event, \Cake\Datasource\EntityInterface $entity, \ArrayObject $options) {
if(!empty($entity->id)) {
if($entity->isNew()) {
// Run setup for new COU

$this->setup(id: $entity->id, coId: $entity->co_id);
} elseif($entity->getOriginal('name') != $entity->get('name')) {
// AR-COU-5 The name was changed, so we may need to update the system groups

$this->Groups->addDefaults(coId: $entity->co_id, couId: $entity->id, rename: true);
}
}


if($entity->isNew() && !empty($entity->id)) {
// Run setup for new COU

$this->setup($entity->id, $entity->co_id);
$this->setup(id: $entity->id, coId: $entity->co_id);
}

return true;
Expand Down Expand Up @@ -187,7 +200,10 @@ public function potentialParents(int $coId, int $id=null, bool $hierarchy=false)
public function rulePotentialParent($entity, $options) {
// We want negative logic since we want to fail if we're editing the COmanage CO
if(!empty($entity->parent_id)) {
$potentialParents = $this->potentialParents($entity->co_id, (!empty($entity->id) ? $entity->id : null));
$potentialParents = $this->potentialParents(
coId: $entity->co_id,
id: (!empty($entity->id) ? $entity->id : null)
);

if(!isset($potentialParents[$entity->parent_id])) {
return __d('error', 'cou.parent');
Expand All @@ -208,7 +224,7 @@ public function rulePotentialParent($entity, $options) {

public function setup(int $id, int $coId): bool {
// AR-COU-4 Create the default groups
$this->Groups->addDefaults($coId, $id);
$this->Groups->addDefaults(coId: $coId, couId: $id);

return true;
}
Expand Down

0 comments on commit 1770206

Please sign in to comment.