Search in sources :

Example 1 with ProjectRole

use of ca.corefacility.bioinformatics.irida.model.enums.ProjectRole in project irida by phac-nml.

the class ProjectMembersController method updateUserRole.

/**
 * Update a user'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 error message
 */
@RequestMapping(path = "{projectId}/settings/members/editrole/{userId}", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> updateUserRole(@PathVariable final Long projectId, @PathVariable final Long userId, @RequestParam final String projectRole, final Locale locale) {
    final Project project = projectService.read(projectId);
    final User user = userService.read(userId);
    final ProjectRole role = ProjectRole.fromString(projectRole);
    final String roleName = messageSource.getMessage("projectRole." + projectRole, new Object[] {}, locale);
    try {
        projectService.updateUserProjectRole(project, user, role);
        return ImmutableMap.of("success", messageSource.getMessage("project.members.edit.role.success", new Object[] { user.getLabel(), roleName }, locale));
    } catch (final ProjectWithoutOwnerException e) {
        return ImmutableMap.of("failure", messageSource.getMessage("project.members.edit.role.failure.nomanager", new Object[] { user.getLabel(), roleName }, locale));
    }
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)

Example 2 with ProjectRole

use of ca.corefacility.bioinformatics.irida.model.enums.ProjectRole in project irida by phac-nml.

the class ProjectMembersController method addProjectMember.

/**
 * Add a member 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/members", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> addProjectMember(@PathVariable Long projectId, @RequestParam Long memberId, @RequestParam String projectRole, Locale locale) {
    logger.trace("Adding user " + memberId + " to project " + projectId);
    Project project = projectService.read(projectId);
    User user = userService.read(memberId);
    ProjectRole role = ProjectRole.fromString(projectRole);
    projectService.addUserToProject(project, user, role);
    return ImmutableMap.of("result", messageSource.getMessage("project.members.add.success", new Object[] { user.getLabel(), project.getLabel() }, locale));
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)

Example 3 with ProjectRole

use of ca.corefacility.bioinformatics.irida.model.enums.ProjectRole 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 4 with ProjectRole

use of ca.corefacility.bioinformatics.irida.model.enums.ProjectRole in project irida by phac-nml.

the class ProjectServiceImplTest method testUpdateProjectUserJoinNotExists.

@Test(expected = EntityNotFoundException.class)
public void testUpdateProjectUserJoinNotExists() throws ProjectWithoutOwnerException {
    Project project = new Project("Project 1");
    User user = new User();
    ProjectRole projectRole = ProjectRole.PROJECT_USER;
    when(pujRepository.getProjectJoinForUser(project, user)).thenReturn(null);
    projectService.updateUserProjectRole(project, user, projectRole);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) Test(org.junit.Test)

Example 5 with ProjectRole

use of ca.corefacility.bioinformatics.irida.model.enums.ProjectRole in project irida by phac-nml.

the class ProjectServiceImplTest method testUpdateProjectUserJoinIllegalChange.

@Test(expected = ProjectWithoutOwnerException.class)
public void testUpdateProjectUserJoinIllegalChange() throws ProjectWithoutOwnerException {
    Project project = new Project("Project 1");
    User user = new User();
    ProjectRole projectRole = ProjectRole.PROJECT_USER;
    ProjectUserJoin oldJoin = new ProjectUserJoin(project, user, ProjectRole.PROJECT_OWNER);
    @SuppressWarnings("unchecked") List<Join<Project, User>> owners = Lists.newArrayList(new ProjectUserJoin(project, user, ProjectRole.PROJECT_OWNER));
    when(pujRepository.getProjectJoinForUser(project, user)).thenReturn(oldJoin);
    when(pujRepository.getUsersForProjectByRole(project, ProjectRole.PROJECT_OWNER)).thenReturn(owners);
    projectService.updateUserProjectRole(project, user, projectRole);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectReferenceFileJoin(ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) Test(org.junit.Test)

Aggregations

ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)14 Project (ca.corefacility.bioinformatics.irida.model.project.Project)14 User (ca.corefacility.bioinformatics.irida.model.user.User)12 Test (org.junit.Test)8 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)5 ProjectWithoutOwnerException (ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException)2 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)2 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)2 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)2 ProjectReferenceFileJoin (ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin)2 UserGroup (ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)2 UserGroupProjectJoin (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin)2 LabelledRelationshipResource (ca.corefacility.bioinformatics.irida.web.assembler.resource.LabelledRelationshipResource)2 ModelMap (org.springframework.ui.ModelMap)2 RESTUsersController (ca.corefacility.bioinformatics.irida.web.controller.api.RESTUsersController)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1 Link (org.springframework.hateoas.Link)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1