Search in sources :

Example 6 with UserGroup

use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.

the class ProjectMembersController method addProjectGroupMember.

/**
 * Add a group to a project
 *
 * @param projectId
 *            The ID of the project
 * @param memberId
 *            The ID of the user
 * @param projectRole
 *            The role for the user on the project
 * @param locale
 *            the reported locale of the browser
 * @return map for showing success message.
 */
@RequestMapping(value = "/{projectId}/settings/groups", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> addProjectGroupMember(@PathVariable Long projectId, @RequestParam Long memberId, @RequestParam String projectRole, Locale locale) {
    logger.trace("Adding user " + memberId + " to project " + projectId);
    final Project project = projectService.read(projectId);
    final UserGroup userGroup = userGroupService.read(memberId);
    final ProjectRole role = ProjectRole.fromString(projectRole);
    projectService.addUserGroupToProject(project, userGroup, role);
    return ImmutableMap.of("result", messageSource.getMessage("project.members.add.success", new Object[] { userGroup.getLabel(), project.getLabel() }, locale));
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

Example 7 with UserGroup

use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.

the class ProjectMembersController method removeUserGroup.

/**
 * Remove a user group from a project
 *
 * @param projectId The project to remove from
 * @param userId    The user to remove
 * @param locale    Locale of the logged in user
 * @return Success or error message
 */
@RequestMapping(path = "{projectId}/settings/groups/{userId}", method = RequestMethod.DELETE)
@ResponseBody
public Map<String, String> removeUserGroup(@PathVariable final Long projectId, @PathVariable final Long userId, final Locale locale) {
    final Project project = projectService.read(projectId);
    final UserGroup userGroup = userGroupService.read(userId);
    try {
        projectService.removeUserGroupFromProject(project, userGroup);
        return ImmutableMap.of("success", messageSource.getMessage("project.members.edit.remove.success", new Object[] { userGroup.getLabel() }, locale));
    } catch (final ProjectWithoutOwnerException e) {
        return ImmutableMap.of("failure", messageSource.getMessage("project.members.edit.remove.nomanager", new Object[] { userGroup.getLabel() }, locale));
    }
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) ProjectWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

Example 8 with UserGroup

use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.

the class UpdateUserGroupPermission method customPermissionAllowed.

/**
 * {@inheritDoc}
 */
@Override
public boolean customPermissionAllowed(final Authentication authentication, final UserGroup g) {
    logger.trace("Checking if [" + authentication + "] can modify [" + g + "]");
    final User user = userRepository.loadUserByUsername(authentication.getName());
    final Optional<UserGroupJoin> userInGroup = userGroupJoinRepository.findUsersInGroup(g).stream().filter(j -> j.getSubject().equals(user)).findAny();
    if (userInGroup.isPresent()) {
        final UserGroupJoin j = userInGroup.get();
        if (j.getRole().equals(UserGroupRole.GROUP_OWNER)) {
            logger.trace("User [" + user + "] is GROUP_OWNER in group [" + g + "], access is GRANTED.");
            return true;
        } else {
            logger.trace("User [" + user + "] is *not* GROUP_OWNER in group [" + g + "], access is DENIED.");
            return false;
        }
    } else {
        logger.trace("User [" + user + "] is not in group [" + g + "], access is DENIED.");
        return false;
    }
}
Also used : UserRepository(ca.corefacility.bioinformatics.irida.repositories.user.UserRepository) Logger(org.slf4j.Logger) UserGroupJoinRepository(ca.corefacility.bioinformatics.irida.repositories.user.UserGroupJoinRepository) UserGroupRole(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole) LoggerFactory(org.slf4j.LoggerFactory) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) Autowired(org.springframework.beans.factory.annotation.Autowired) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) Component(org.springframework.stereotype.Component) UserGroupRepository(ca.corefacility.bioinformatics.irida.repositories.user.UserGroupRepository) BasePermission(ca.corefacility.bioinformatics.irida.security.permissions.BasePermission) Optional(java.util.Optional) User(ca.corefacility.bioinformatics.irida.model.user.User) Authentication(org.springframework.security.core.Authentication) User(ca.corefacility.bioinformatics.irida.model.user.User) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin)

Example 9 with UserGroup

use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.

the class UserGroupServiceImplIT method testRemoveUserFromGroupNoOwner.

@Test(expected = UserGroupWithoutOwnerException.class)
@WithMockUser(username = "differentUser", roles = "USER")
public void testRemoveUserFromGroupNoOwner() throws UserGroupWithoutOwnerException {
    final UserGroup ug = userGroupService.read(1L);
    final User u = userService.read(2L);
    userGroupService.removeUserFromGroup(u, ug);
}
Also used : WithMockUser(org.springframework.security.test.context.support.WithMockUser) User(ca.corefacility.bioinformatics.irida.model.user.User) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 10 with UserGroup

use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.

the class UserGroupServiceImplIT method testChangeRoleUserFromGroupNoOwner.

@Test(expected = UserGroupWithoutOwnerException.class)
@WithMockUser(username = "differentUser", roles = "USER")
public void testChangeRoleUserFromGroupNoOwner() throws UserGroupWithoutOwnerException {
    final UserGroup ug = userGroupService.read(1L);
    final User u = userService.read(2L);
    userGroupService.changeUserGroupRole(u, ug, UserGroupRole.GROUP_MEMBER);
}
Also used : WithMockUser(org.springframework.security.test.context.support.WithMockUser) User(ca.corefacility.bioinformatics.irida.model.user.User) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

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