use of org.broadinstitute.consent.http.models.Role 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.Role 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.Role 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.Role in project consent by DataBiosphere.
the class UserRoleDAOTest method testRemoveSingleUserRole.
@Test
public void testRemoveSingleUserRole() {
User user = createUserWithRole(UserRoles.RESEARCHER.getRoleId());
List<UserRole> userRoles = userRoleDAO.findRolesByUserId(user.getDacUserId());
Assert.assertFalse(userRoles.isEmpty());
List<Role> roles = userRoleDAO.findRoles();
roles.forEach(r -> userRoleDAO.removeSingleUserRole(user.getDacUserId(), r.getRoleId()));
List<UserRole> newUserRoles = userRoleDAO.findRolesByUserId(user.getDacUserId());
Assert.assertTrue(newUserRoles.isEmpty());
}
use of org.broadinstitute.consent.http.models.Role in project consent by DataBiosphere.
the class DacServiceTest method testAddDacMember.
@Test
public void testAddDacMember() {
Gson gson = new Gson();
User user = getDacUsers().get(0);
Dac dac = getDacs().get(0);
when(userDAO.findUserById(any())).thenReturn(user);
when(userDAO.findUserById(any())).thenReturn(user);
when(dacDAO.findUserRolesForUser(any())).thenReturn(getDacUsers().get(0).getRoles());
List<Election> elections = getElections().stream().map(e -> {
Election newE = gson.fromJson(gson.toJson(e), Election.class);
newE.setElectionType(ElectionType.DATA_ACCESS.getValue());
newE.setReferenceId(UUID.randomUUID().toString());
return newE;
}).collect(Collectors.toList());
DataAccessRequest dar = new DataAccessRequest();
dar.setData(new DataAccessRequestData());
dar.getData().setRestriction(new Everything());
when(dataAccessRequestDAO.findByReferenceId(any())).thenReturn(dar);
when(electionDAO.findOpenElectionsByDacId(any())).thenReturn(elections);
when(voteService.createVotes(any(), any(), anyBoolean())).thenReturn(Collections.emptyList());
doNothing().when(dacDAO).addDacMember(anyInt(), anyInt(), anyInt());
initService();
Role role = new Role(UserRoles.CHAIRPERSON.getRoleId(), UserRoles.CHAIRPERSON.getRoleName());
User user1 = service.addDacMember(role, user, dac);
Assert.assertNotNull(user1);
Assert.assertFalse(user1.getRoles().isEmpty());
verify(voteService, times(elections.size())).createVotesForUser(any(), any(), any(), anyBoolean());
}
Aggregations