use of org.broadinstitute.consent.http.models.Dac in project consent by DataBiosphere.
the class DacResource method addDacChair.
@POST
@Path("{dacId}/chair/{userId}")
@RolesAllowed({ ADMIN, CHAIRPERSON })
public Response addDacChair(@Auth AuthUser authUser, @PathParam("dacId") Integer dacId, @PathParam("userId") Integer userId) {
checkUserExistsInDac(dacId, userId);
Role role = dacService.getChairpersonRole();
User user = findDacUser(userId);
Dac dac = findDacById(dacId);
checkUserRoleInDac(dac, authUser);
try {
User member = dacService.addDacMember(role, user, dac);
return Response.ok().entity(member).build();
} catch (Exception e) {
return createExceptionResponse(e);
}
}
use of org.broadinstitute.consent.http.models.Dac in project consent by DataBiosphere.
the class DacResource method checkUserRoleInDac.
/**
* - Admins can make any modifications to any Dac chairs or members
* - Chairpersons can only make modifications to chairs and members in a DAC that they are a
* chairperson in.
*
* @param dac The Dac
* @param authUser The AuthUser
* @throws NotAuthorizedException Not authorized
*/
private void checkUserRoleInDac(Dac dac, AuthUser authUser) throws NotAuthorizedException {
User user = userService.findUserByEmail(authUser.getEmail());
if (user.getRoles().stream().anyMatch(ur -> ur.getRoleId().equals(UserRoles.ADMIN.getRoleId()))) {
return;
}
NotAuthorizedException e = new NotAuthorizedException("User not authorized");
if (Objects.isNull(dac.getChairpersons()) || dac.getChairpersons().isEmpty()) {
throw e;
}
Optional<User> chair = dac.getChairpersons().stream().filter(u -> u.getDacUserId().equals(user.getDacUserId())).findFirst();
if (chair.isEmpty()) {
throw e;
}
}
use of org.broadinstitute.consent.http.models.Dac in project consent by DataBiosphere.
the class DacResource method updateDac.
@PUT
@Produces("application/json")
@RolesAllowed({ ADMIN })
public Response updateDac(@Auth AuthUser authUser, String json) {
Dac dac = new Gson().fromJson(json, Dac.class);
if (dac == null) {
throw new BadRequestException("DAC is required");
}
if (dac.getDacId() == null) {
throw new BadRequestException("DAC ID is required");
}
if (dac.getName() == null) {
throw new BadRequestException("DAC Name is required");
}
if (dac.getDescription() == null) {
throw new BadRequestException("DAC Description is required");
}
dacService.updateDac(dac.getName(), dac.getDescription(), dac.getDacId());
Dac savedDac = dacService.findById(dac.getDacId());
return Response.ok().entity(savedDac).build();
}
use of org.broadinstitute.consent.http.models.Dac in project consent by DataBiosphere.
the class DacResource method removeDacChair.
@DELETE
@Path("{dacId}/chair/{userId}")
@RolesAllowed({ ADMIN, CHAIRPERSON })
public Response removeDacChair(@Auth AuthUser authUser, @PathParam("dacId") Integer dacId, @PathParam("userId") Integer userId) {
Role role = dacService.getChairpersonRole();
User user = findDacUser(userId);
Dac dac = findDacById(dacId);
checkUserRoleInDac(dac, authUser);
try {
dacService.removeDacMember(role, user, dac);
return Response.ok().build();
} catch (Exception e) {
return createExceptionResponse(e);
}
}
use of org.broadinstitute.consent.http.models.Dac in project consent by DataBiosphere.
the class DacResource method removeDacMember.
@DELETE
@Path("{dacId}/member/{userId}")
@RolesAllowed({ ADMIN, CHAIRPERSON })
public Response removeDacMember(@Auth AuthUser authUser, @PathParam("dacId") Integer dacId, @PathParam("userId") Integer userId) {
Role role = dacService.getMemberRole();
User user = findDacUser(userId);
Dac dac = findDacById(dacId);
checkUserRoleInDac(dac, authUser);
try {
dacService.removeDacMember(role, user, dac);
return Response.ok().build();
} catch (Exception e) {
return createExceptionResponse(e);
}
}
Aggregations