fix: [group admin] be able to add users for the administered orgs
parent
6967c03d8b
commit
b233241e87
|
@ -117,7 +117,14 @@ class UsersController extends AppController
|
|||
$data['role_id'] = $defaultRole['id'];
|
||||
}
|
||||
if (!$currentUser['role']['perm_admin']) {
|
||||
$validOrgs = $this->Users->getValidOrgsForUser($currentUser);
|
||||
if ($currentUser['role']['perm_group_admin']) {
|
||||
if (!empty($data['organisation_id']) && !in_array($currentUser['organisation_id'], $validOrgs)) {
|
||||
throw new MethodNotAllowedException(__('You do not have permission to assign that organisation.'));
|
||||
}
|
||||
} else {
|
||||
$data['organisation_id'] = $currentUser['organisation_id'];
|
||||
}
|
||||
if (!in_array($data['role_id'], array_keys($validRoles))) {
|
||||
throw new MethodNotAllowedException(__('You do not have permission to assign that role.'));
|
||||
}
|
||||
|
@ -171,7 +178,8 @@ class UsersController extends AppController
|
|||
*/
|
||||
$org_conditions = [];
|
||||
if (empty($currentUser['role']['perm_admin'])) {
|
||||
$org_conditions = ['id' => $currentUser['organisation_id']];
|
||||
$validOrgs = $this->Users->getValidOrgsForUser($currentUser);
|
||||
$org_conditions = ['id IN' => $validOrgs];
|
||||
}
|
||||
$dropdownData = [
|
||||
'role' => $validRoles,
|
||||
|
|
|
@ -293,8 +293,18 @@ class UsersTable extends AppTable
|
|||
return true;
|
||||
}
|
||||
|
||||
public function getAllOrganisations($currentUser) {
|
||||
public function getAllOrganisations(\App\Model\Entity\User $currentUser)
|
||||
{
|
||||
$this->Individuals = TableRegistry::get('Individuals');
|
||||
return $this->Individuals->getAllOrganisations($currentUser);
|
||||
}
|
||||
|
||||
public function getValidOrgsForUser(\App\Model\Entity\User $user): array
|
||||
{
|
||||
if (!empty($user['role']['perm_group_admin'])) {
|
||||
return $this->Organisations->OrgGroups->getGroupOrgIdsForUser($user);
|
||||
} else {
|
||||
return [$user['organisation_id']];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue