@Test public void shouldReturnTrueIfUserHasRequiredPermissionOnProgramAndFacility() throws Exception { List<Right> rights = asList(new Right(CREATE_REQUISITION, REQUISITION)); when(programSupportedService.getByFacilityIdAndProgramId(facilityId, programId)).thenReturn(make(a(defaultProgramSupported))); when(roleRightsService.getRightsForUserAndFacilityProgram(eq(userId), any(Facility.class), any(Program.class))).thenReturn(rights); assertThat(requisitionPermissionService.hasPermission(userId, new Facility(facilityId), new Program(programId), CREATE_REQUISITION), is(true)); }
public Boolean hasPermission(Long userId, Facility facility, Program program, String rightName) { ProgramSupported programSupported = programSupportedService.getByFacilityIdAndProgramId(facility.getId(), program.getId()); if (!(programSupported != null && programSupported.getActive() && programSupported.getProgram().getActive())) { return false; } List<Right> userRights = roleRightsService.getRightsForUserAndFacilityProgram(userId, facility, program); return any(userRights, with(rightName)); }
RequisitionPermissionService { public Boolean hasPermission(Long userId, Facility facility, Program program, String rightName) { ProgramSupported programSupported = programSupportedService.getByFacilityIdAndProgramId(facility.getId(), program.getId()); if (!(programSupported != null && programSupported.getActive() && programSupported.getProgram().getActive())) { return false; } List<Right> userRights = roleRightsService.getRightsForUserAndFacilityProgram(userId, facility, program); return any(userRights, with(rightName)); } }
RequisitionPermissionService { public Boolean hasPermission(Long userId, Facility facility, Program program, String rightName) { ProgramSupported programSupported = programSupportedService.getByFacilityIdAndProgramId(facility.getId(), program.getId()); if (!(programSupported != null && programSupported.getActive() && programSupported.getProgram().getActive())) { return false; } List<Right> userRights = roleRightsService.getRightsForUserAndFacilityProgram(userId, facility, program); return any(userRights, with(rightName)); }  }
RequisitionPermissionService { public Boolean hasPermission(Long userId, Facility facility, Program program, String rightName) { ProgramSupported programSupported = programSupportedService.getByFacilityIdAndProgramId(facility.getId(), program.getId()); if (!(programSupported != null && programSupported.getActive() && programSupported.getProgram().getActive())) { return false; } List<Right> userRights = roleRightsService.getRightsForUserAndFacilityProgram(userId, facility, program); return any(userRights, with(rightName)); }  Boolean hasPermission(Long userId, Facility facility, Program program, String rightName); Boolean hasPermission(Long userId, Rnr rnr, String rightName); boolean hasPermissionToSave(Long userId, Rnr rnr); boolean hasPermission(Long userId, String rightName); }
RequisitionPermissionService { public Boolean hasPermission(Long userId, Facility facility, Program program, String rightName) { ProgramSupported programSupported = programSupportedService.getByFacilityIdAndProgramId(facility.getId(), program.getId()); if (!(programSupported != null && programSupported.getActive() && programSupported.getProgram().getActive())) { return false; } List<Right> userRights = roleRightsService.getRightsForUserAndFacilityProgram(userId, facility, program); return any(userRights, with(rightName)); }  Boolean hasPermission(Long userId, Facility facility, Program program, String rightName); Boolean hasPermission(Long userId, Rnr rnr, String rightName); boolean hasPermissionToSave(Long userId, Rnr rnr); boolean hasPermission(Long userId, String rightName);  }