use of org.broadinstitute.consent.http.models.AuthUser in project consent by DataBiosphere.
the class DACUserResource method describe.
@GET
@Path("/{email}")
@Produces("application/json")
@PermitAll
public User describe(@Auth AuthUser authUser, @PathParam("email") String email) {
User searchUser = userService.findUserByEmail(email);
validateAuthedRoleUser(Stream.of(UserRoles.ADMIN, UserRoles.CHAIRPERSON, UserRoles.MEMBER).collect(Collectors.toList()), findByAuthUser(authUser), searchUser.getDacUserId());
return searchUser;
}
use of org.broadinstitute.consent.http.models.AuthUser 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);
}
}
use of org.broadinstitute.consent.http.models.AuthUser 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.AuthUser 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.AuthUser 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);
}
}
Aggregations