use of org.broadinstitute.consent.http.enumeration.UserRoles in project consent by DataBiosphere.
the class DarCollectionResource method cancelDarCollectionByCollectionId.
@PUT
@Path("{id}/cancel")
@Produces("application/json")
@RolesAllowed({ ADMIN, CHAIRPERSON, RESEARCHER })
public Response cancelDarCollectionByCollectionId(@Auth AuthUser authUser, @PathParam("id") Integer collectionId, @QueryParam("roleName") String roleName) {
try {
User user = userService.findUserByEmail(authUser.getEmail());
DarCollection collection = darCollectionService.getByCollectionId(collectionId);
isCollectionPresent(collection);
// Default to the least impactful role if none provided.
UserRoles actingRole = UserRoles.RESEARCHER;
if (Objects.nonNull(roleName)) {
validateUserHasRoleName(user, roleName);
UserRoles requestedRole = UserRoles.getUserRoleFromName(roleName);
if (Objects.nonNull(requestedRole)) {
actingRole = requestedRole;
}
}
DarCollection cancelledCollection;
switch(actingRole) {
case ADMIN:
cancelledCollection = darCollectionService.cancelDarCollectionElectionsAsAdmin(collection);
break;
case CHAIRPERSON:
cancelledCollection = darCollectionService.cancelDarCollectionElectionsAsChair(collection, user);
break;
default:
validateUserIsCreator(user, collection);
cancelledCollection = darCollectionService.cancelDarCollectionAsResearcher(collection);
break;
}
return Response.ok().entity(cancelledCollection).build();
} catch (Exception e) {
return createExceptionResponse(e);
}
}
use of org.broadinstitute.consent.http.enumeration.UserRoles in project consent by DataBiosphere.
the class DarCollectionService method getCollectionsForUserByRoleName.
public List<DarCollection> getCollectionsForUserByRoleName(User user, String roleName) {
List<DarCollection> collections = new ArrayList<>();
UserRoles selectedRole = UserRoles.getUserRoleFromName(roleName);
if (Objects.nonNull(selectedRole) && user.hasUserRole(selectedRole)) {
switch(selectedRole) {
case ADMIN:
collections.addAll(getAllCollections());
break;
case CHAIRPERSON:
case MEMBER:
collections.addAll(getCollectionsByUserDacs(user));
break;
case SIGNINGOFFICIAL:
collections.addAll(getCollectionsByUserInstitution(user));
break;
default:
collections.addAll(getCollectionsForUser(user));
}
} else {
collections.addAll(getCollectionsForUser(user));
}
return collections;
}
use of org.broadinstitute.consent.http.enumeration.UserRoles in project consent by DataBiosphere.
the class DataAccessRequestResource method describeManageDataAccessRequestsV2.
@GET
@Produces("application/json")
@Path("/manage/v2")
@RolesAllowed({ ADMIN, CHAIRPERSON, MEMBER, SIGNINGOFFICIAL, RESEARCHER })
public Response describeManageDataAccessRequestsV2(@Auth AuthUser authUser, @QueryParam("roleName") Optional<String> roleName) {
try {
User user = userService.findUserByEmail(authUser.getEmail());
String roleNameValue = roleName.orElse(null);
UserRoles queriedUserRole = UserRoles.getUserRoleFromName(roleNameValue);
if (roleName.isPresent()) {
// if a roleName was passed in but it is not in the UserRoles enum throw exception
if (Objects.isNull(queriedUserRole)) {
throw new BadRequestException("Invalid role name: " + roleNameValue);
} else {
// if there is a valid roleName but it is not SO or Researcher then throw an exception
if (queriedUserRole != UserRoles.RESEARCHER && queriedUserRole != UserRoles.SIGNINGOFFICIAL) {
throw new BadRequestException("Unsupported role name: " + queriedUserRole.getRoleName());
}
// if the user does not have the given roleName throw NotFoundException
if (!user.hasUserRole(queriedUserRole)) {
throw new NotFoundException("User: " + user.getDisplayName() + ", does not have " + queriedUserRole.getRoleName() + " role.");
}
}
// if no roleName was passed in, find the user's role
} else {
if (user.hasUserRole(UserRoles.ADMIN)) {
queriedUserRole = UserRoles.ADMIN;
} else if (user.hasUserRole(UserRoles.CHAIRPERSON)) {
queriedUserRole = UserRoles.CHAIRPERSON;
} else if (user.hasUserRole(UserRoles.MEMBER)) {
queriedUserRole = UserRoles.MEMBER;
}
}
List<DataAccessRequestManage> dars = dataAccessRequestService.describeDataAccessRequestManageV2(user, queriedUserRole);
return Response.ok().entity(dars).build();
} catch (Exception e) {
return createExceptionResponse(e);
}
}
Aggregations