use of ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException in project irida by phac-nml.
the class ProjectServiceImpl method updateUserProjectRole.
/**
* {@inheritDoc}
*/
@Override
@Transactional
@LaunchesProjectEvent(UserRoleSetProjectEvent.class)
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#project,'canManageLocalProjectSettings')")
public Join<Project, User> updateUserProjectRole(Project project, User user, ProjectRole projectRole) throws ProjectWithoutOwnerException {
ProjectUserJoin projectJoinForUser = pujRepository.getProjectJoinForUser(project, user);
if (projectJoinForUser == null) {
throw new EntityNotFoundException("Join between this project and user does not exist. User: " + user + " Project: " + project);
}
if (!allowRoleChange(projectJoinForUser.getSubject(), projectJoinForUser.getProjectRole())) {
throw new ProjectWithoutOwnerException("This role change would leave the project without an owner");
}
projectJoinForUser.setProjectRole(projectRole);
return pujRepository.save(projectJoinForUser);
}
use of ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException in project irida by phac-nml.
the class ProjectMembersController method removeUser.
/**
* Remove a user from a project
*
* @param projectId The project to remove from
* @param userId The user to remove
* @param locale The locale of the logged in user
* @return Success or failure message if user was removed
*/
@RequestMapping(path = "{projectId}/settings/members/{userId}", method = RequestMethod.DELETE)
@ResponseBody
public Map<String, String> removeUser(@PathVariable final Long projectId, @PathVariable final Long userId, final Locale locale) {
Project project = projectService.read(projectId);
User user = userService.read(userId);
try {
projectService.removeUserFromProject(project, user);
return ImmutableMap.of("success", messageSource.getMessage("project.members.edit.remove.success", new Object[] { user.getLabel() }, locale));
} catch (final ProjectWithoutOwnerException e) {
return ImmutableMap.of("failure", messageSource.getMessage("project.members.edit.remove.nomanager", new Object[] { user.getLabel() }, locale));
}
}
use of ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException 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