SamPermissionsImpl implements PermissionsInterface { @Override public void removePermission(User user, Workflow workflow, String email, Role role) { checkEmailNotOriginalOwner(email, workflow); ResourcesApi resourcesApi = getResourcesApi(user); String encodedPath = encodedWorkflowResource(workflow, resourcesApi.getApiClient()); try { List<AccessPolicyResponseEntry> entries = resourcesApi.listResourcePolicies(SamConstants.RESOURCE_TYPE, encodedPath); for (AccessPolicyResponseEntry entry : entries) { if (permissionSamMap.get(role).equals(entry.getPolicyName())) { if (entry.getPolicy().getMemberEmails().contains(email)) { resourcesApi.removeUserFromPolicy(SamConstants.RESOURCE_TYPE, encodedPath, entry.getPolicyName(), email); } } } } catch (ApiException e) { LOG.error(MessageFormat.format("Error removing {0} from workflow {1}", email, encodedPath), e); throw new CustomWebApplicationException("Error removing permissions", e.getCode()); } } SamPermissionsImpl(TokenDAO tokenDAO, DockstoreWebserviceConfiguration config); @Override List<Permission> setPermission(User requester, Workflow workflow, Permission permission); @Override Map<Role, List<String>> workflowsSharedWithUser(User user); @Override List<Permission> getPermissionsForWorkflow(User user, Workflow workflow); @Override List<Role.Action> getActionsForWorkflow(User user, Workflow workflow); @Override void removePermission(User user, Workflow workflow, String email, Role role); @Override boolean canDoAction(User user, Workflow workflow, Role.Action action); @Override void selfDestruct(User user); @Override boolean isSharing(User user);  }
@Test public void removePermissionTest() throws ApiException { when(resourcesApiMock.listResourcePolicies(SamConstants.RESOURCE_TYPE, SamConstants.WORKFLOW_PREFIX + FOO_WORKFLOW_NAME)) .thenReturn(Collections.singletonList(readerAccessPolicyResponseEntry), Collections.singletonList(readerAccessPolicyResponseEntry), Collections.EMPTY_LIST); final List<Permission> permissions = samPermissionsImpl.getPermissionsForWorkflow(userMock, workflowInstance); Assert.assertEquals(permissions.size(), 1); try { samPermissionsImpl.removePermission(userMock, workflowInstance, JANE_DOE_GMAIL_COM, Role.READER); } catch (CustomWebApplicationException e) { Assert.fail(); } }