use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole in project irida by phac-nml.
the class GroupsController method updateUserRole.
/**
* Update a user's role on a group
*
* @param groupId
* The ID of the group
* @param userId
* The ID of the user
* @param groupRole
* The role to set
* @param locale
* Locale of the logged in user
*
* @return message indicating update result
*/
@RequestMapping(path = "/{groupId}/members/editrole/{userId}", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> updateUserRole(@PathVariable final Long groupId, @PathVariable final Long userId, @RequestParam final String groupRole, final Locale locale) {
final UserGroup group = userGroupService.read(groupId);
final User user = userService.read(userId);
final UserGroupRole userGroupRole = UserGroupRole.fromString(groupRole);
final String roleName = messageSource.getMessage("group.users.role." + groupRole, new Object[] {}, locale);
try {
userGroupService.changeUserGroupRole(user, group, userGroupRole);
return ImmutableMap.of("success", messageSource.getMessage("group.members.edit.role.success", new Object[] { user.getLabel(), roleName }, locale));
} catch (final UserGroupWithoutOwnerException e) {
return ImmutableMap.of("failure", messageSource.getMessage("group.members.edit.role.failure", new Object[] { user.getLabel(), roleName }, locale));
}
}
use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole in project irida by phac-nml.
the class GroupsController method addUserToGroup.
/**
* Add a new user to the group.
*
* @param userGroupId
* the group to add to.
* @param userId
* the new member.
* @param groupRole
* the role this user should have.
* @param locale
* the locale of the browser.
* @return a message indicating success.
*/
@RequestMapping(path = "/{userGroupId}/members", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> addUserToGroup(@PathVariable final Long userGroupId, @RequestParam final Long userId, @RequestParam String groupRole, Locale locale) {
final User user = userService.read(userId);
final UserGroup group = userGroupService.read(userGroupId);
final UserGroupRole role = UserGroupRole.valueOf(groupRole);
userGroupService.addUserToGroup(user, group, role);
return ImmutableMap.of("result", messageSource.getMessage("group.users.add.notification.success", new Object[] { user.getLabel() }, locale));
}
Aggregations