@PreAuthorize("isOrganizationAdmin(#organizationId) or hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/manager/removeOrganizationUsers", method = RequestMethod.POST)
public
@ResponseBody
Result removeUsers(@RequestParam Long organizationId, @RequestParam(value = "userIds[]") List<Long> userIds) {
Result result = new Result();
List<Long> userIdsRemoved = new ArrayList<Long>();
try {
checkRequiredEntity(organizationService, organizationId);
} catch (EntityNotFoundException ex) {
log.info(String.format("Attempted to update member role for non-existent organization: %s", organizationId));
result.setResult(false);
return result;
}
User user = userService.getUserFromSecurityContext();
if (organizationId != null && organizationId > 0 && userIds != null) {
for (Long userId : userIds) {
if (user != null && !userId.equals(user.getId())) {
organizationService.removeUserFromOrganization(organizationId, userId);
userIdsRemoved.add(userId);
}
}
}
if (userIdsRemoved.size() != userIds.size()) {
result.setResult(false);
} else {
result.setResult(true);
}
result.setValue(userIdsRemoved);
return result;
}