Search in sources :

Example 21 with UserGroup

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));
    }
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) ProjectWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

Example 22 with UserGroup

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;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

Example 23 with UserGroup

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));
    }
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) UserGroupWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.UserGroupWithoutOwnerException) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

Example 24 with UserGroup

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;
    }
}
Also used : UserGroupWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.UserGroupWithoutOwnerException) java.util(java.util) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroupSpecification(ca.corefacility.bioinformatics.irida.repositories.specification.UserGroupSpecification) EntityExistsException(ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) Model(org.springframework.ui.Model) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) ImmutableList(com.google.common.collect.ImmutableList) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) ConstraintViolation(javax.validation.ConstraintViolation) DTGroupMember(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTGroupMember) MessageSource(org.springframework.context.MessageSource) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) Role(ca.corefacility.bioinformatics.irida.model.user.Role) DataTablesRequest(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.config.DataTablesRequest) UserGroupRole(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) PageRequest(org.springframework.data.domain.PageRequest) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) UserGroupService(ca.corefacility.bioinformatics.irida.service.user.UserGroupService) Principal(java.security.Principal) ConstraintViolationException(javax.validation.ConstraintViolationException) UserService(ca.corefacility.bioinformatics.irida.service.user.UserService) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) User(ca.corefacility.bioinformatics.irida.model.user.User) DataTablesParams(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin)

Example 25 with UserGroup

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;
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

Aggregations

UserGroup (ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)30 User (ca.corefacility.bioinformatics.irida.model.user.User)18 DTUserGroup (ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup)12 UserGroupJoin (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin)11 Test (org.junit.Test)10 Project (ca.corefacility.bioinformatics.irida.model.project.Project)9 UserGroupRole (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole)7 Authentication (org.springframework.security.core.Authentication)7 UserGroupWithoutOwnerException (ca.corefacility.bioinformatics.irida.exceptions.UserGroupWithoutOwnerException)6 EntityExistsException (ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException)5 ConstraintViolation (javax.validation.ConstraintViolation)5 ConstraintViolationException (javax.validation.ConstraintViolationException)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)5 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)5 WithMockUser (org.springframework.security.test.context.support.WithMockUser)5 DataTablesResponse (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)4 DataTablesResponseModel (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel)4