Skip to content

Commit

Permalink
fix: code improvement by first checking for the user instead of the a…
Browse files Browse the repository at this point in the history
…dmin role
  • Loading branch information
TangoBeeAkto committed Dec 12, 2024
1 parent cacd86a commit 66e4576
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,14 @@ public String deleteTestRole() {
return ERROR.toUpperCase();
}

RBAC.Role currentRoleForUser = RBACDao.getCurrentRoleForUser(user.getId(), Context.accountId.get());
if(!currentRoleForUser.equals(RBAC.Role.ADMIN) && !user.getLogin().equals(role.getCreatedBy())) {
addActionError("You do not have permission to delete this role.");
return ERROR.toUpperCase();
boolean noAccess = !user.getLogin().equals(role.getCreatedBy());

if(noAccess) {
RBAC.Role currentRoleForUser = RBACDao.getCurrentRoleForUser(user.getId(), Context.accountId.get());
if (!currentRoleForUser.equals(RBAC.Role.ADMIN)) {
addActionError("You do not have permission to delete this role.");
return ERROR.toUpperCase();
}
}

Bson roleFilterQ = Filters.eq(TestRoles.NAME, roleName);
Expand Down

0 comments on commit 66e4576

Please sign in to comment.