Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ public function editUser(string $userId, string $key, string $value): DataRespon
} else {
// Check if admin / subadmin
$subAdminManager = $this->groupManager->getSubAdmin();
if ($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
|| $this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())
|| $subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
// They have permissions over the user
$permittedFields[] = 'display';
$permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
Expand Down
36 changes: 25 additions & 11 deletions lib/private/SubAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,25 @@ public function deleteSubAdmin(IUser $user, IGroup $group): void {
* @return IGroup[]
*/
public function getSubAdminsGroups(IUser $user): array {
$groupIds = $this->getSubAdminsGroupIds($user);

$groups = [];
foreach ($groupIds as $groupId) {
$group = $this->groupManager->get($groupId);
if ($group !== null) {
$groups[$group->getGID()] = $group;
}
}

return $groups;
}

/**
* Get group ids of a SubAdmin
* @param IUser $user the SubAdmin
* @return string[]
*/
public function getSubAdminsGroupIds(IUser $user): array {
$qb = $this->dbConn->getQueryBuilder();

$result = $qb->select('gid')
Expand All @@ -119,10 +138,7 @@ public function getSubAdminsGroups(IUser $user): array {

$groups = [];
while ($row = $result->fetch()) {
$group = $this->groupManager->get($row['gid']);
if (!is_null($group)) {
$groups[$group->getGID()] = $group;
}
$groups[] = $row['gid'];
}
$result->closeCursor();

Expand Down Expand Up @@ -255,13 +271,11 @@ public function isUserAccessible(IUser $subadmin, IUser $user): bool {
if ($this->groupManager->isAdmin($user->getUID())) {
return false;
}
$accessibleGroups = $this->getSubAdminsGroups($subadmin);
foreach ($accessibleGroups as $accessibleGroup) {
if ($accessibleGroup->inGroup($user)) {
return true;
}
}
return false;

$accessibleGroups = $this->getSubAdminsGroupIds($subadmin);
$userGroups = $this->groupManager->getUserGroupIds($user);

return !empty(array_intersect($accessibleGroups, $userGroups));
}

/**
Expand Down