fix: [encryption keys] only show valid options when creating keys as a user
parent
c71c978761
commit
7fa0537cfd
|
@ -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'));
|
||||
|
|
Loading…
Reference in New Issue