diff --git a/src/Controller/Component/ACLComponent.php b/src/Controller/Component/ACLComponent.php index d403c28..1689fc0 100644 --- a/src/Controller/Component/ACLComponent.php +++ b/src/Controller/Component/ACLComponent.php @@ -342,6 +342,9 @@ class ACLComponent extends Component if (!$currentUser['role']['perm_org_admin']) { return false; } else { + if ($currentUser['id'] == $user['id']) { + return true; + } if ($currentUser['organisation_id'] !== $user['organisation_id']) { return false; } diff --git a/src/Controller/UsersController.php b/src/Controller/UsersController.php index 574d344..698021c 100644 --- a/src/Controller/UsersController.php +++ b/src/Controller/UsersController.php @@ -51,7 +51,7 @@ class UsersController extends AppController } $this->set( 'validRoles', - $this->Users->Roles->find('list')->select(['id', 'name'])->order(['name' => 'asc'])->where(['perm_admin' => 0])->all()->toArray() + $this->Users->Roles->find('list')->select(['id', 'name'])->order(['name' => 'asc'])->where(['perm_admin' => 0, 'perm_org_admin' => 0])->all()->toArray() ); $this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate'); } @@ -259,7 +259,7 @@ class UsersController extends AppController $params['fields'][] = 'disabled'; if (!$currentUser['role']['perm_admin']) { $params['afterFind'] = function ($data, &$params) use ($currentUser, $validRoles) { - if (!in_array($data['role_id'], array_keys($validRoles))) { + if (!in_array($data['role_id'], array_keys($validRoles)) && $this->ACL->getUser()['id'] != $data['id']) { throw new MethodNotAllowedException(__('You cannot edit the given privileged user.')); } if (!$this->ACL->canEditUser($currentUser, $data)) { @@ -268,7 +268,7 @@ class UsersController extends AppController return $data; }; $params['beforeSave'] = function ($data) use ($currentUser, $validRoles) { - if (!in_array($data['role_id'], array_keys($validRoles))) { + if (!in_array($data['role_id'], array_keys($validRoles)) && $this->ACL->getUser()['id'] != $data['id']) { throw new MethodNotAllowedException(__('You cannot assign the chosen role to a user.')); } return $data; @@ -284,6 +284,9 @@ class UsersController extends AppController if (empty($currentUser['role']['perm_admin'])) { $org_conditions = ['id' => $currentUser['organisation_id']]; } + if ($this->ACL->getUser()['id'] == $id) { + $validRoles[$this->ACL->getUser()['role']['id']] = $this->ACL->getUser()['role']['name']; // include the current role of the user + } $dropdownData = [ 'role' => $validRoles, 'organisation' => $this->Users->Organisations->find('list', [ diff --git a/templates/Users/index.php b/templates/Users/index.php index 6fae052..f9388cb 100644 --- a/templates/Users/index.php +++ b/templates/Users/index.php @@ -127,6 +127,9 @@ echo $this->element('genericElements/IndexTable/index_table', [ ], 'function' => function ($row, $options) use ($loggedUser, $validRoles) { if (empty($loggedUser['role']['perm_admin'])) { + if ($row['id'] == $loggedUser['id']) { + return true; + } if (empty($loggedUser['role']['perm_org_admin'])) { return false; }