Search in sources :

Example 1 with RightDto

use of org.openlmis.stockmanagement.dto.referencedata.RightDto in project openlmis-stockmanagement by OpenLMIS.

the class StockoutNotifier method getEditors.

private Collection<UserDto> getEditors(StockCard stockCard) {
    RightDto right = rightReferenceDataService.findRight(STOCK_INVENTORIES_EDIT);
    SupervisoryNodeDto supervisoryNode = supervisoryNodeReferenceDataService.findSupervisoryNode(stockCard.getProgramId(), stockCard.getFacilityId());
    if (supervisoryNode == null) {
        throw new IllegalArgumentException(String.format("There is no supervisory node for program %s and facility %s", stockCard.getProgramId(), stockCard.getFacilityId()));
    }
    return supervisingUsersReferenceDataService.findAll(supervisoryNode.getId(), right.getId(), stockCard.getProgramId());
}
Also used : RightDto(org.openlmis.stockmanagement.dto.referencedata.RightDto) SupervisoryNodeDto(org.openlmis.stockmanagement.dto.referencedata.SupervisoryNodeDto)

Example 2 with RightDto

use of org.openlmis.stockmanagement.dto.referencedata.RightDto in project openlmis-stockmanagement by OpenLMIS.

the class AuthenticationHelperTest method shouldReturnRight.

@Test
public void shouldReturnRight() throws Exception {
    // given
    RightDto right = mock(RightDto.class);
    when(rightReferenceDataService.findRight(anyString())).thenReturn(right);
    // when
    RightDto dto = authenticationHelper.getRight("rightName");
    // then
    assertNotNull(dto);
    assertThat(dto, is(right));
}
Also used : RightDto(org.openlmis.stockmanagement.dto.referencedata.RightDto) Test(org.junit.Test)

Example 3 with RightDto

use of org.openlmis.stockmanagement.dto.referencedata.RightDto in project openlmis-stockmanagement by OpenLMIS.

the class PermissionService method checkUserToken.

private ResultDto<Boolean> checkUserToken(String rightName, UUID program, UUID facility, UUID warehouse) {
    UserDto user = authenticationHelper.getCurrentUser();
    RightDto right = authenticationHelper.getRight(rightName);
    try {
        return userReferenceDataService.hasRight(user.getId(), right.getId(), program, facility, warehouse);
    } catch (HttpClientErrorException httpException) {
        throw new PermissionMessageException(new Message(ERROR_PERMISSION_CHECK_FAILED, httpException.getMessage()), httpException);
    }
}
Also used : RightDto(org.openlmis.stockmanagement.dto.referencedata.RightDto) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) Message(org.openlmis.stockmanagement.util.Message) UserDto(org.openlmis.stockmanagement.dto.referencedata.UserDto) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException)

Aggregations

RightDto (org.openlmis.stockmanagement.dto.referencedata.RightDto)3 Test (org.junit.Test)1 SupervisoryNodeDto (org.openlmis.stockmanagement.dto.referencedata.SupervisoryNodeDto)1 UserDto (org.openlmis.stockmanagement.dto.referencedata.UserDto)1 PermissionMessageException (org.openlmis.stockmanagement.exception.PermissionMessageException)1 Message (org.openlmis.stockmanagement.util.Message)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1