@Test public void shouldReturnTrueIfUserCanApproveARnr() throws Exception { Long supervisoryNodeId = 1L; Rnr rnr = make(a(RequisitionBuilder.defaultRequisition, with(status, AUTHORIZED))); rnr.setSupervisoryNodeId(supervisoryNodeId); final RoleAssignment assignment = roleAssignmentWithSupervisoryNodeId(supervisoryNodeId, 3l); List<RoleAssignment> roleAssignments = new ArrayList<RoleAssignment>() {{ add(assignment); }}; when(roleAssignmentService.getRoleAssignments(APPROVE_REQUISITION, userId)).thenReturn(roleAssignments); assertThat(requisitionPermissionService.hasPermission(userId, rnr, APPROVE_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);  }