fix: [encryption keys] only show valid options when creating keys as a user

pull/79/head
iglocska 2021-11-27 23:51:32 +01:00
parent c71c978761
commit 7fa0537cfd
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 13 additions and 3 deletions

View File

@ -50,16 +50,25 @@ class EncryptionKeysController extends AppController
public function add() public function add()
{ {
$orgConditions = []; $orgConditions = [];
$individualConditions = [];
$currentUser = $this->ACL->getUser(); $currentUser = $this->ACL->getUser();
$params = ['redirect' => $this->referer()]; $params = ['redirect' => $this->referer()];
if (empty($currentUser['role']['perm_admin'])) { 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) { $params['beforeSave'] = function($entity) {
if ($entity['owner_model'] === 'organisation') { if ($entity['owner_model'] === 'organisation') {
$entity['owner_id'] = $currentUser['organisation_id']; $entity['owner_id'] = $currentUser['organisation_id'];
} else { } else {
if ($currentUser['role']['perm_org_admin']) { if ($currentUser['role']['perm_org_admin']) {
$validIndividuals = $this->Organisations->Alignments->find('list', [ $validIndividuals = $this->Organisations->find('list', [
'fields' => ['distinct(individual_id)'], 'fields' => ['distinct(id)'],
'conditions' => ['organisation_id' => $currentUser['organisation_id']] 'conditions' => ['organisation_id' => $currentUser['organisation_id']]
]); ]);
if (!in_array($entity['owner_id'], $validIndividuals)) { if (!in_array($entity['owner_id'], $validIndividuals)) {
@ -86,7 +95,8 @@ class EncryptionKeysController extends AppController
'conditions' => $orgConditions 'conditions' => $orgConditions
]), ]),
'individual' => $this->Individuals->find('list', [ 'individual' => $this->Individuals->find('list', [
'sort' => ['email' => 'asc'] 'sort' => ['email' => 'asc'],
'conditions' => $individualConditions
]) ])
]; ];
$this->set(compact('dropdownData')); $this->set(compact('dropdownData'));