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