@Test public void getPatientAccessForwardsCallsCorrectly() throws ComponentLookupException { EntityPermissionsManager internal = this.mocker.getInstance(EntityPermissionsManager.class, "secure"); Patient patient = mock(Patient.class); DocumentReference patientReference = mock(DocumentReference.class); when(patient.getDocumentReference()).thenReturn(patientReference); EntityAccess internalAccess = mock(EntityAccess.class); when(internal.getEntityAccess(patient)).thenReturn(internalAccess); User currentUser = mock(User.class); UserManager userManager = this.mocker.getInstance(UserManager.class); when(userManager.getCurrentUser()).thenReturn(currentUser); String testID = "TESTID"; PrimaryEntityResolver patientRepo = this.mocker.getInstance(PrimaryEntityResolver.class); when(patientRepo.resolveEntity(testID)).thenReturn(patient); AuthorizationService access = this.mocker.getInstance(AuthorizationService.class); when(access.hasAccess(currentUser, Right.VIEW, patientReference)).thenReturn(true); EntityAccess result1 = this.mocker.getComponentUnderTest().getEntityAccess(testID); Assert.assertSame(internalAccess, result1); when(access.hasAccess(currentUser, Right.VIEW, patientReference)).thenReturn(false); EntityAccess result2 = this.mocker.getComponentUnderTest().getEntityAccess(testID); Assert.assertNull(result2); }
public EntityAccess getEntityAccess(PrimaryEntity entity) { if (entity == null) { return null; } if (!this.access.hasAccess(this.userManager.getCurrentUser(), Right.VIEW, entity.getDocumentReference())) { return null; } return this.manager.getEntityAccess(entity); }
EntityPermissionsManagerScriptService implements ScriptService { public EntityAccess getEntityAccess(PrimaryEntity entity) { if (entity == null) { return null; } if (!this.access.hasAccess(this.userManager.getCurrentUser(), Right.VIEW, entity.getDocumentReference())) { return null; } return this.manager.getEntityAccess(entity); } }
EntityPermissionsManagerScriptService implements ScriptService { public EntityAccess getEntityAccess(PrimaryEntity entity) { if (entity == null) { return null; } if (!this.access.hasAccess(this.userManager.getCurrentUser(), Right.VIEW, entity.getDocumentReference())) { return null; } return this.manager.getEntityAccess(entity); }  }
EntityPermissionsManagerScriptService implements ScriptService { public EntityAccess getEntityAccess(PrimaryEntity entity) { if (entity == null) { return null; } if (!this.access.hasAccess(this.userManager.getCurrentUser(), Right.VIEW, entity.getDocumentReference())) { return null; } return this.manager.getEntityAccess(entity); }  Collection<Visibility> listVisibilityOptions(); Collection<Visibility> listAllVisibilityOptions(); Visibility getDefaultVisibility(); Visibility resolveVisibility(String name); Collection<AccessLevel> listAccessLevels(); AccessLevel resolveAccessLevel(String name); EntityAccess getEntityAccess(PrimaryEntity entity); EntityAccess getEntityAccess(String entityId); void fireRightsUpdateEvent(String targetEntityId); }
EntityPermissionsManagerScriptService implements ScriptService { public EntityAccess getEntityAccess(PrimaryEntity entity) { if (entity == null) { return null; } if (!this.access.hasAccess(this.userManager.getCurrentUser(), Right.VIEW, entity.getDocumentReference())) { return null; } return this.manager.getEntityAccess(entity); }  Collection<Visibility> listVisibilityOptions(); Collection<Visibility> listAllVisibilityOptions(); Visibility getDefaultVisibility(); Visibility resolveVisibility(String name); Collection<AccessLevel> listAccessLevels(); AccessLevel resolveAccessLevel(String name); EntityAccess getEntityAccess(PrimaryEntity entity); EntityAccess getEntityAccess(String entityId); void fireRightsUpdateEvent(String targetEntityId);  }