use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.
the class ProjectMembersController method updateUserGroupRole.
/**
* Update a user group's role on a project
*
* @param projectId The ID of the project
* @param userId The ID of the user
* @param projectRole The role to set
* @param locale Locale of the logged in user
* @return Success or failure message
*/
@RequestMapping(path = "{projectId}/settings/groups/editrole/{userId}", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> updateUserGroupRole(@PathVariable final Long projectId, @PathVariable final Long userId, @RequestParam final String projectRole, final Locale locale) {
final Project project = projectService.read(projectId);
final UserGroup userGroup = userGroupService.read(userId);
final ProjectRole role = ProjectRole.fromString(projectRole);
final String roleName = messageSource.getMessage("projectRole." + projectRole, new Object[] {}, locale);
try {
projectService.updateUserGroupProjectRole(project, userGroup, role);
return ImmutableMap.of("success", messageSource.getMessage("project.members.edit.role.success", new Object[] { userGroup.getLabel(), roleName }, locale));
} catch (final ProjectWithoutOwnerException e) {
return ImmutableMap.of("failure", messageSource.getMessage("project.members.edit.role.failure.nomanager", new Object[] { userGroup.getLabel(), roleName }, locale));
}
}
use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.
the class ProjectMembersController method getGroupsAvailableForProject.
/**
* Search the list of users who could be added to a project
*
* @param projectId
* The ID of the project
* @param term
* A search term
* @return A {@code Map<Long,String>} of the userID and user label
*/
@RequestMapping("/{projectId}/settings/ajax/availablegroupmembers")
@ResponseBody
public Collection<UserGroup> getGroupsAvailableForProject(@PathVariable Long projectId, @RequestParam String term) {
final Project project = projectService.read(projectId);
final List<UserGroup> groupsAvailableForProject = userGroupService.getUserGroupsNotOnProject(project, term);
return groupsAvailableForProject;
}
use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.
the class GroupsController method removeUserFromGroup.
/**
* Remove a user from a group.
*
* @param userGroupId
* the group to remove from.
* @param userId
* the user to remove.
* @param locale
* the locale of the browser.
* @return a message indicating success.
*/
@RequestMapping(path = "/{userGroupId}/members/{userId}", method = RequestMethod.DELETE)
@ResponseBody
public Map<String, String> removeUserFromGroup(@PathVariable final Long userGroupId, @PathVariable final Long userId, Locale locale) {
final User user = userService.read(userId);
final UserGroup group = userGroupService.read(userGroupId);
try {
userGroupService.removeUserFromGroup(user, group);
return ImmutableMap.of("success", messageSource.getMessage("group.users.remove.notification.success", new Object[] { user.getLabel() }, locale));
} catch (final UserGroupWithoutOwnerException e) {
return ImmutableMap.of("failure", messageSource.getMessage("group.users.remove.notification.failure", new Object[] { user.getLabel() }, locale));
}
}
use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.
the class GroupsController method isGroupOwner.
/**
* Convenience method for checking whether or not the specified user is an
* owner of the group.
*
* @param user
* the {@link User} to check.
* @param group
* the {@link UserGroup} to check.
* @return true if owner, false otherwise.
*/
private boolean isGroupOwner(final User user, final UserGroup group) {
final Collection<UserGroupJoin> groupUsers = userGroupService.getUsersForGroup(group);
final Optional<UserGroupJoin> currentUserGroup = groupUsers.stream().filter(j -> j.getSubject().equals(user)).findAny();
if (currentUserGroup.isPresent()) {
final UserGroupJoin j = currentUserGroup.get();
return j.getRole().equals(UserGroupRole.GROUP_OWNER);
} else {
return false;
}
}
use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.
the class GroupsController method getDetailsPage.
/**
* Get the details page for a {@link UserGroup}.
*
* @param userGroupId
* the {@link UserGroup} to retrieve.
* @param principal
* the user that's currently logged in.
* @param model
* the model to write attributes to.
* @return the route to the group details page.
*/
@RequestMapping("/{userGroupId}")
public String getDetailsPage(@PathVariable final Long userGroupId, final Principal principal, final Model model) {
final UserGroup group = userGroupService.read(userGroupId);
final Collection<UserGroupJoin> groupUsers = userGroupService.getUsersForGroup(group);
final User currentUser = userService.getUserByUsername(principal.getName());
final boolean isOwner = isGroupOwner(currentUser, group);
model.addAttribute("group", group);
model.addAttribute("isAdmin", currentUser.getSystemRole().equals(Role.ROLE_ADMIN));
model.addAttribute("isOwner", isOwner);
model.addAttribute("users", groupUsers);
model.addAttribute("groupRoles", ImmutableList.of(UserGroupRole.GROUP_MEMBER, UserGroupRole.GROUP_OWNER));
return GROUP_DETAILS;
}
Aggregations