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);
}
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);
}
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);
}
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));
}
}
Aggregations