From 7fa0537cfd0577648b75092eea43131589b2485f Mon Sep 17 00:00:00 2001 From: iglocska Date: Sat, 27 Nov 2021 23:51:32 +0100 Subject: [PATCH] fix: [encryption keys] only show valid options when creating keys as a user --- src/Controller/EncryptionKeysController.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Controller/EncryptionKeysController.php b/src/Controller/EncryptionKeysController.php index 78bec89..ae2a55b 100644 --- a/src/Controller/EncryptionKeysController.php +++ b/src/Controller/EncryptionKeysController.php @@ -50,16 +50,25 @@ class EncryptionKeysController extends AppController public function add() { $orgConditions = []; + $individualConditions = []; $currentUser = $this->ACL->getUser(); $params = ['redirect' => $this->referer()]; if (empty($currentUser['role']['perm_admin'])) { + $orgConditions = [ + 'id' => $currentUser['organisation_id'] + ]; + if (empty($currentUser['role']['perm_org_admin'])) { + $individualConditions = [ + 'id' => $currentUser['individual_id'] + ]; + } $params['beforeSave'] = function($entity) { if ($entity['owner_model'] === 'organisation') { $entity['owner_id'] = $currentUser['organisation_id']; } else { if ($currentUser['role']['perm_org_admin']) { - $validIndividuals = $this->Organisations->Alignments->find('list', [ - 'fields' => ['distinct(individual_id)'], + $validIndividuals = $this->Organisations->find('list', [ + 'fields' => ['distinct(id)'], 'conditions' => ['organisation_id' => $currentUser['organisation_id']] ]); if (!in_array($entity['owner_id'], $validIndividuals)) { @@ -86,7 +95,8 @@ class EncryptionKeysController extends AppController 'conditions' => $orgConditions ]), 'individual' => $this->Individuals->find('list', [ - 'sort' => ['email' => 'asc'] + 'sort' => ['email' => 'asc'], + 'conditions' => $individualConditions ]) ]; $this->set(compact('dropdownData'));