Apply suggestions from code review
Co-authored-by: Eldad A. Fux <eldad.fux@gmail.com>
This commit is contained in:
parent
df3f2d73e3
commit
3b74a92ab3
1 changed files with 1 additions and 15 deletions
|
@ -508,24 +508,10 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId')
|
||||||
throw new Exception('Membership not found', 404);
|
throw new Exception('Membership not found', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$memberships = $projectDB->getCollection([
|
|
||||||
'limit' => 2000,
|
|
||||||
'offset' => 0,
|
|
||||||
'filters' => [
|
|
||||||
'$collection='.Database::SYSTEM_COLLECTION_MEMBERSHIPS,
|
|
||||||
'teamId='.$team->getId(),
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$isPrivilegedUser = Auth::isPrivilegedUser(Authorization::$roles);
|
$isPrivilegedUser = Auth::isPrivilegedUser(Authorization::$roles);
|
||||||
$isAppUser = Auth::isAppUser(Authorization::$roles);
|
$isAppUser = Auth::isAppUser(Authorization::$roles);
|
||||||
$isOwner = false;
|
$isOwner = Authorization::isRole('team:'.$team->getId().'/owner');;
|
||||||
|
|
||||||
foreach ($memberships as $member) {
|
|
||||||
if ($member->getAttribute('userId') == $user->getId() && \in_array('owner', $member->getAttribute('roles', []))) {
|
|
||||||
$isOwner = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$isOwner && !$isPrivilegedUser && !$isAppUser) { // Not owner, not admin, not app (server)
|
if (!$isOwner && !$isPrivilegedUser && !$isAppUser) { // Not owner, not admin, not app (server)
|
||||||
throw new Exception('User is not allowed to modify roles', 401);
|
throw new Exception('User is not allowed to modify roles', 401);
|
||||||
|
|
Loading…
Reference in a new issue