use of org.hisp.dhis.user.UserAuthorityGroup in project dhis2-core by dhis2.
the class UserRoleController method removeUserFromRole.
@DeleteMapping("/{id}/users/{userId}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void removeUserFromRole(@PathVariable(value = "id") String pvId, @PathVariable("userId") String pvUserId, @CurrentUser User currentUser, HttpServletResponse response) throws WebMessageException {
UserAuthorityGroup userAuthorityGroup = userService.getUserAuthorityGroup(pvId);
if (userAuthorityGroup == null) {
throw new WebMessageException(notFound("UserRole does not exist: " + pvId));
}
User user = userService.getUser(pvUserId);
if (user == null) {
throw new WebMessageException(notFound("User does not exist: " + pvId));
}
if (!aclService.canUpdate(currentUser, userAuthorityGroup)) {
throw new DeleteAccessDeniedException("You don't have the proper permissions to delete this object.");
}
if (user.getUserAuthorityGroups().contains(userAuthorityGroup)) {
user.getUserAuthorityGroups().remove(userAuthorityGroup);
userService.updateUser(user);
}
}
Aggregations