@Test public void shouldReturnTrueIfUserHasGivenRightOnAWarehouse() { Right right1 = new Right(MANAGE_POD, FULFILLMENT); Right right2 = new Right(FACILITY_FILL_SHIPMENT, FULFILLMENT); List<Right> rights = new ArrayList<>(asList(right1,right2)); Long userId = 1L; Long orderId = 2L; Long facilityID = 12345L; when(roleRightsService.getRightsForUserAndWarehouse(userId, facilityID)).thenReturn(rights); Order order = mock(Order.class); when(order.getSupplyingFacility()).thenReturn(new Facility(facilityID)); when(orderService.getOrder(2l)).thenReturn(order); Boolean hasRight = fulfillmentPermissionService.hasPermission(userId, orderId, MANAGE_POD); assertThat(hasRight, is(true)); }
public Boolean hasPermission(Long userId, Long orderId, String rightName) { Order order = orderService.getOrder(orderId); List<Right> userRights = roleRightsService.getRightsForUserAndWarehouse(userId, order.getSupplyingFacility().getId()); return any(userRights, RightUtil.with(rightName)); }
FulfillmentPermissionService { public Boolean hasPermission(Long userId, Long orderId, String rightName) { Order order = orderService.getOrder(orderId); List<Right> userRights = roleRightsService.getRightsForUserAndWarehouse(userId, order.getSupplyingFacility().getId()); return any(userRights, RightUtil.with(rightName)); } }
FulfillmentPermissionService { public Boolean hasPermission(Long userId, Long orderId, String rightName) { Order order = orderService.getOrder(orderId); List<Right> userRights = roleRightsService.getRightsForUserAndWarehouse(userId, order.getSupplyingFacility().getId()); return any(userRights, RightUtil.with(rightName)); }  }
FulfillmentPermissionService { public Boolean hasPermission(Long userId, Long orderId, String rightName) { Order order = orderService.getOrder(orderId); List<Right> userRights = roleRightsService.getRightsForUserAndWarehouse(userId, order.getSupplyingFacility().getId()); return any(userRights, RightUtil.with(rightName)); }  Boolean hasPermission(Long userId, Long orderId, String rightName); Boolean hasPermissionOnWarehouse(Long userId, Long warehouseId, String rightName); }
FulfillmentPermissionService { public Boolean hasPermission(Long userId, Long orderId, String rightName) { Order order = orderService.getOrder(orderId); List<Right> userRights = roleRightsService.getRightsForUserAndWarehouse(userId, order.getSupplyingFacility().getId()); return any(userRights, RightUtil.with(rightName)); }  Boolean hasPermission(Long userId, Long orderId, String rightName); Boolean hasPermissionOnWarehouse(Long userId, Long warehouseId, String rightName);  }