Search in sources :

Example 1 with ProjectWithoutOwnerException

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));
    }
}
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) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)

Example 2 with ProjectWithoutOwnerException

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

Example 3 with ProjectWithoutOwnerException

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

Example 4 with ProjectWithoutOwnerException

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

Example 5 with ProjectWithoutOwnerException

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

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