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