Search in sources :

Example 1 with Role

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);
    }
}
Also used : Role(org.broadinstitute.consent.http.models.Role) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) Dac(org.broadinstitute.consent.http.models.Dac) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST)

Example 2 with Role

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);
    }
}
Also used : Role(org.broadinstitute.consent.http.models.Role) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) Dac(org.broadinstitute.consent.http.models.Dac) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 3 with Role

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);
    }
}
Also used : Role(org.broadinstitute.consent.http.models.Role) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) Dac(org.broadinstitute.consent.http.models.Dac) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 4 with Role

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());
}
Also used : UserRole(org.broadinstitute.consent.http.models.UserRole) Role(org.broadinstitute.consent.http.models.Role) User(org.broadinstitute.consent.http.models.User) UserRole(org.broadinstitute.consent.http.models.UserRole) Test(org.junit.Test)

Example 5 with Role

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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoAnnotations.openMocks(org.mockito.MockitoAnnotations.openMocks) IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Mock(org.mockito.Mock) DatasetDTO(org.broadinstitute.consent.http.models.dto.DatasetDTO) UserRoles(org.broadinstitute.consent.http.enumeration.UserRoles) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) ArrayList(java.util.ArrayList) DatasetDAO(org.broadinstitute.consent.http.db.DatasetDAO) Gson(com.google.gson.Gson) ElectionType(org.broadinstitute.consent.http.enumeration.ElectionType) AuthUser(org.broadinstitute.consent.http.models.AuthUser) BadRequestException(javax.ws.rs.BadRequestException) Role(org.broadinstitute.consent.http.models.Role) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) UserDAO(org.broadinstitute.consent.http.db.UserDAO) Before(org.junit.Before) DataAccessRequestData(org.broadinstitute.consent.http.models.DataAccessRequestData) DataSet(org.broadinstitute.consent.http.models.DataSet) DacDAO(org.broadinstitute.consent.http.db.DacDAO) DataAccessRequestDAO(org.broadinstitute.consent.http.db.DataAccessRequestDAO) ConsentManage(org.broadinstitute.consent.http.models.ConsentManage) Collection(java.util.Collection) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Set(java.util.Set) UserRole(org.broadinstitute.consent.http.models.UserRole) Mockito.times(org.mockito.Mockito.times) User(org.broadinstitute.consent.http.models.User) Test(org.junit.Test) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Dac(org.broadinstitute.consent.http.models.Dac) Mockito.verify(org.mockito.Mockito.verify) ElectionDAO(org.broadinstitute.consent.http.db.ElectionDAO) List(java.util.List) Stream(java.util.stream.Stream) Election(org.broadinstitute.consent.http.models.Election) Everything(org.broadinstitute.consent.http.models.grammar.Everything) Assert(org.junit.Assert) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Consent(org.broadinstitute.consent.http.models.Consent) DataAccessRequestData(org.broadinstitute.consent.http.models.DataAccessRequestData) Role(org.broadinstitute.consent.http.models.Role) UserRole(org.broadinstitute.consent.http.models.UserRole) Everything(org.broadinstitute.consent.http.models.grammar.Everything) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) Dac(org.broadinstitute.consent.http.models.Dac) Gson(com.google.gson.Gson) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election) Test(org.junit.Test)

Aggregations

Role (org.broadinstitute.consent.http.models.Role)11 User (org.broadinstitute.consent.http.models.User)10 AuthUser (org.broadinstitute.consent.http.models.AuthUser)9 Dac (org.broadinstitute.consent.http.models.Dac)9 BadRequestException (javax.ws.rs.BadRequestException)8 UserRole (org.broadinstitute.consent.http.models.UserRole)7 Test (org.junit.Test)6 NotFoundException (javax.ws.rs.NotFoundException)5 RolesAllowed (javax.annotation.security.RolesAllowed)4 NotAuthorizedException (javax.ws.rs.NotAuthorizedException)4 Path (javax.ws.rs.Path)4 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 DELETE (javax.ws.rs.DELETE)2 POST (javax.ws.rs.POST)2 DacDAO (org.broadinstitute.consent.http.db.DacDAO)2