chg: [user add] form defaults
- org will default to own org for site admins - role will default to the default role (if set)cli-modification-summary
parent
05daa5470a
commit
1ca0f21b86
|
@ -49,9 +49,13 @@ class UsersController extends AppController
|
|||
} else {
|
||||
$validRoles = $this->Users->Roles->find('list')->order(['name' => 'asc'])->all()->toArray();
|
||||
}
|
||||
$defaultRole = $this->Users->Roles->find()->select(['id'])->first()->toArray();
|
||||
|
||||
$this->CRUD->add([
|
||||
'beforeSave' => function($data) use ($currentUser, $validRoles) {
|
||||
'beforeSave' => function($data) use ($currentUser, $validRoles, $defaultRole) {
|
||||
if (!isset($data['role_id']) && !empty($defaultRole)) {
|
||||
$data['role_id'] = $defaultRole['id'];
|
||||
}
|
||||
if (!$currentUser['role']['perm_admin']) {
|
||||
$data['organisation_id'] = $currentUser['organisation_id'];
|
||||
if (!in_array($data['role_id'], array_keys($validRoles))) {
|
||||
|
@ -89,6 +93,7 @@ class UsersController extends AppController
|
|||
])
|
||||
];
|
||||
$this->set(compact('dropdownData'));
|
||||
$this->set('defaultRole', $defaultRole['id'] ?? null);
|
||||
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
'field' => 'organisation_id',
|
||||
'type' => 'dropdown',
|
||||
'label' => __('Associated organisation'),
|
||||
'options' => $dropdownData['organisation']
|
||||
'options' => $dropdownData['organisation'],
|
||||
'default' => $loggedUser['organisation_id']
|
||||
],
|
||||
[
|
||||
'field' => 'password',
|
||||
|
@ -39,7 +40,8 @@
|
|||
'field' => 'role_id',
|
||||
'type' => 'dropdown',
|
||||
'label' => __('Role'),
|
||||
'options' => $dropdownData['role']
|
||||
'options' => $dropdownData['role'],
|
||||
'default' => $defaultRole ?? null
|
||||
],
|
||||
[
|
||||
'field' => 'disabled',
|
||||
|
|
Loading…
Reference in New Issue