Search in sources :

Example 6 with ProjectWithoutOwnerException

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);
}
Also used : ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) LaunchesProjectEvent(ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with ProjectWithoutOwnerException

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));
    }
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException)

Example 8 with ProjectWithoutOwnerException

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

ProjectWithoutOwnerException (ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException)8 LaunchesProjectEvent (ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent)4 Project (ca.corefacility.bioinformatics.irida.model.project.Project)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 Transactional (org.springframework.transaction.annotation.Transactional)4 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)2 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)2 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)2 User (ca.corefacility.bioinformatics.irida.model.user.User)2 UserGroup (ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)2 UserGroupProjectJoin (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin)2