fix: [encryptions] fixed adding encryption keys
parent
332f374e01
commit
4c7dc85d0e
|
@ -62,16 +62,18 @@ class EncryptionKeysController extends AppController
|
||||||
'id' => $currentUser['individual_id']
|
'id' => $currentUser['individual_id']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$params['beforeSave'] = function($entity) {
|
$params['beforeSave'] = function($entity) use($currentUser) {
|
||||||
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->find('list', [
|
$this->loadModel('Alignments');
|
||||||
'fields' => ['distinct(id)'],
|
$validIndividuals = $this->Alignments->find('list', [
|
||||||
|
'keyField' => 'individual_id',
|
||||||
|
'valueField' => 'id',
|
||||||
'conditions' => ['organisation_id' => $currentUser['organisation_id']]
|
'conditions' => ['organisation_id' => $currentUser['organisation_id']]
|
||||||
]);
|
])->toArray();
|
||||||
if (!in_array($entity['owner_id'], $validIndividuals)) {
|
if (!isset($validIndividuals[$entity['owner_id']])) {
|
||||||
throw new MethodNotAllowedException(__('Selected individual cannot be linked by the current user.'));
|
throw new MethodNotAllowedException(__('Selected individual cannot be linked by the current user.'));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -80,6 +82,7 @@ class EncryptionKeysController extends AppController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return $entity;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
$this->CRUD->add($params);
|
$this->CRUD->add($params);
|
||||||
|
|
Loading…
Reference in New Issue