fix: [encryptions] fixed adding encryption keys

pull/79/head
iglocska 2021-12-01 15:24:08 +01:00
parent 332f374e01
commit 4c7dc85d0e
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 8 additions and 5 deletions

View File

@ -62,16 +62,18 @@ class EncryptionKeysController extends AppController
'id' => $currentUser['individual_id']
];
}
$params['beforeSave'] = function($entity) {
$params['beforeSave'] = function($entity) use($currentUser) {
if ($entity['owner_model'] === 'organisation') {
$entity['owner_id'] = $currentUser['organisation_id'];
} else {
if ($currentUser['role']['perm_org_admin']) {
$validIndividuals = $this->Organisations->find('list', [
'fields' => ['distinct(id)'],
$this->loadModel('Alignments');
$validIndividuals = $this->Alignments->find('list', [
'keyField' => 'individual_id',
'valueField' => 'id',
'conditions' => ['organisation_id' => $currentUser['organisation_id']]
]);
if (!in_array($entity['owner_id'], $validIndividuals)) {
])->toArray();
if (!isset($validIndividuals[$entity['owner_id']])) {
throw new MethodNotAllowedException(__('Selected individual cannot be linked by the current user.'));
}
} else {
@ -80,6 +82,7 @@ class EncryptionKeysController extends AppController
}
}
}
return $entity;
};
}
$this->CRUD->add($params);