Search in sources :

Example 11 with ProjectRole

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

the class ProjectMembersControllerTest method testUdateUserRole.

@Test
public void testUdateUserRole() throws ProjectWithoutOwnerException {
    Long projectId = 1L;
    Long userId = 2L;
    Project project = new Project();
    User user = new User(userId, "tom", null, null, "Tom", "Matthews", null);
    ProjectRole projectRole = ProjectRole.PROJECT_USER;
    when(projectService.read(projectId)).thenReturn(project);
    when(userService.read(userId)).thenReturn(user);
    when(messageSource.getMessage(any(), any(), any())).thenReturn("");
    controller.updateUserRole(projectId, userId, projectRole.toString(), null);
    verify(projectService).read(projectId);
    verify(userService).read(userId);
    verify(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 12 with ProjectRole

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

the class ProjectServiceImplTest method testUpdateProjectUserJoin.

@Test
public void testUpdateProjectUserJoin() throws ProjectWithoutOwnerException {
    Project project = new Project("Project 1");
    User user = new User();
    User user2 = 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), new ProjectUserJoin(project, user2, ProjectRole.PROJECT_OWNER));
    when(pujRepository.getProjectJoinForUser(project, user)).thenReturn(oldJoin);
    when(pujRepository.save(oldJoin)).thenReturn(oldJoin);
    when(pujRepository.getUsersForProjectByRole(project, ProjectRole.PROJECT_OWNER)).thenReturn(owners);
    Join<Project, User> updateUserProjectRole = projectService.updateUserProjectRole(project, user, projectRole);
    assertNotNull(updateUserProjectRole);
    ProjectUserJoin newJoin = (ProjectUserJoin) updateUserProjectRole;
    assertEquals(projectRole, newJoin.getProjectRole());
    verify(pujRepository).getProjectJoinForUser(project, user);
    verify(pujRepository).getUsersForProjectByRole(project, ProjectRole.PROJECT_OWNER);
    verify(pujRepository).save(oldJoin);
}
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)

Example 13 with ProjectRole

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

the class ProjectServiceImplTest method testAddUserToProject.

@Test
public void testAddUserToProject() {
    User u = new User("test", "test@nowhere.com", "PASSWOD!1", "Test", "User", "1234");
    u.setId(new Long(1111));
    Project p = project();
    ProjectRole r = ProjectRole.PROJECT_USER;
    ProjectUserJoin join = new ProjectUserJoin(p, u, r);
    when(pujRepository.save(join)).thenReturn(join);
    projectService.addUserToProject(p, u, r);
    verify(pujRepository).save(join);
}
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) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) Test(org.junit.Test)

Example 14 with ProjectRole

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

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