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()
|
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'));
|
||||||
|
|
Loading…
Reference in New Issue