fix: [users] edit
- various issues fixed with the edit function - re-added the chance to change organisations of a user as a site admin - tighter checks on the options for the drop downscli-modification-summary
parent
32a559cc3b
commit
4575406b33
|
@ -143,8 +143,17 @@ class UsersController extends AppController
|
||||||
{
|
{
|
||||||
$currentUser = $this->ACL->getUser();
|
$currentUser = $this->ACL->getUser();
|
||||||
$validRoles = [];
|
$validRoles = [];
|
||||||
|
$individuals_params = [
|
||||||
|
'sort' => ['email' => 'asc']
|
||||||
|
];
|
||||||
|
$individual_ids = [];
|
||||||
if (!$currentUser['role']['perm_admin']) {
|
if (!$currentUser['role']['perm_admin']) {
|
||||||
$validRoles = $this->Users->Roles->find('list')->select(['id', 'name'])->order(['name' => 'asc'])->where(['perm_admin' => 0, 'perm_org_admin' => 0])->all()->toArray();
|
$validRoles = $this->Users->Roles->find('list')->select(['id', 'name'])->order(['name' => 'asc'])->where(['perm_admin' => 0, 'perm_org_admin' => 0])->all()->toArray();
|
||||||
|
$individual_ids = $this->Users->Individuals->find('aligned', ['organisation_id' => $currentUser['organisation_id']])->all()->extract('id')->toArray();
|
||||||
|
if (empty($individual_ids)) {
|
||||||
|
$individual_ids = [-1];
|
||||||
|
}
|
||||||
|
$individuals_params['conditions'] = ['id IN' => $individual_ids];
|
||||||
} else {
|
} else {
|
||||||
$validRoles = $this->Users->Roles->find('list')->order(['name' => 'asc'])->all()->toArray();
|
$validRoles = $this->Users->Roles->find('list')->order(['name' => 'asc'])->all()->toArray();
|
||||||
}
|
}
|
||||||
|
@ -168,7 +177,10 @@ class UsersController extends AppController
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
if ($this->request->is(['get'])) {
|
if ($this->request->is(['get'])) {
|
||||||
$params['fields'] = array_merge($params['fields'], ['individual_id', 'role_id', 'disabled', 'username']);
|
$params['fields'] = array_merge($params['fields'], ['individual_id', 'role_id', 'disabled']);
|
||||||
|
if (!empty($this->ACL->getUser()['role']['perm_admin'])) {
|
||||||
|
$params['fields'][] = 'organisation_id';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($this->request->is(['post', 'put']) && !empty($this->ACL->getUser()['role']['perm_admin'])) {
|
if ($this->request->is(['post', 'put']) && !empty($this->ACL->getUser()['role']['perm_admin'])) {
|
||||||
$params['fields'][] = 'individual_id';
|
$params['fields'][] = 'individual_id';
|
||||||
|
@ -210,6 +222,18 @@ class UsersController extends AppController
|
||||||
'sort' => ['name' => 'asc']
|
'sort' => ['name' => 'asc']
|
||||||
])
|
])
|
||||||
];
|
];
|
||||||
|
$org_conditions = [];
|
||||||
|
if (empty($currentUser['role']['perm_admin'])) {
|
||||||
|
$org_conditions = ['id' => $currentUser['organisation_id']];
|
||||||
|
}
|
||||||
|
$dropdownData = [
|
||||||
|
'role' => $validRoles,
|
||||||
|
'individual' => $this->Users->Individuals->find('list', $individuals_params)->toArray(),
|
||||||
|
'organisation' => $this->Users->Organisations->find('list', [
|
||||||
|
'sort' => ['name' => 'asc'],
|
||||||
|
'conditions' => $org_conditions
|
||||||
|
])
|
||||||
|
];
|
||||||
$this->set(compact('dropdownData'));
|
$this->set(compact('dropdownData'));
|
||||||
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
|
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
|
||||||
$this->render('add');
|
$this->render('add');
|
||||||
|
|
Loading…
Reference in New Issue