From ccd4a8c62419bd9eb4b9d730a213728d7067009c Mon Sep 17 00:00:00 2001 From: iglocska Date: Wed, 28 Aug 2024 15:38:53 +0200 Subject: [PATCH] new: [individuals] add individual auto-saves an alignment - if a non community admin enrolls an individual, set the alignment by default - this will prevent them from becoming uneditable --- src/Controller/IndividualsController.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Controller/IndividualsController.php b/src/Controller/IndividualsController.php index c37a0d2..ebd4539 100644 --- a/src/Controller/IndividualsController.php +++ b/src/Controller/IndividualsController.php @@ -62,7 +62,16 @@ class IndividualsController extends AppController public function add() { - $this->CRUD->add(); + $currentUser = $this->ACL->getUser(); + $params = [ + 'afterSave' => function($data) use ($currentUser) { + if (empty($currentUser['role']['perm_community_admin'])) { + $this->Individuals->Alignments->setAlignment($currentUser['organisation_id'], $data->id, 'Member'); + } + return $data; + } + ]; + $this->CRUD->add($params); $responsePayload = $this->CRUD->getResponsePayload(); if (!empty($responsePayload)) { return $responsePayload;