SamPermissionsImpl implements PermissionsInterface { @Override public List<Role.Action> getActionsForWorkflow(User user, Workflow workflow) { List<Role.Action> list = new ArrayList<>(); if (workflow.getUsers().contains(user) || canDoAction(user, workflow, Role.Action.SHARE)) { list.addAll(Arrays.asList(Role.Action.values())); } else if (canDoAction(user, workflow, Role.Action.WRITE)) { list.add(Role.Action.WRITE); list.add(Role.Action.READ); } else if (canDoAction(user, workflow, Role.Action.READ)) { list.add(Role.Action.READ); } return list; } 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 testOwnersActions() throws ApiException { final String resourceId = SamConstants.WORKFLOW_PREFIX + FOO_WORKFLOW_NAME; when(resourcesApiMock.resourceAction(SamConstants.RESOURCE_TYPE, resourceId, SamConstants.toSamAction(Role.Action.SHARE))) .thenReturn(Boolean.TRUE); final List<Role.Action> actions = samPermissionsImpl.getActionsForWorkflow(userMock, workflowInstance); Assert.assertEquals(Role.Action.values().length, actions.size()); }
@Test public void testWritersActions() throws ApiException { final String resourceId = SamConstants.WORKFLOW_PREFIX + FOO_WORKFLOW_NAME; when(resourcesApiMock.resourceAction(SamConstants.RESOURCE_TYPE, resourceId, SamConstants.toSamAction(Role.Action.SHARE))) .thenReturn(Boolean.FALSE); when(resourcesApiMock.resourceAction(SamConstants.RESOURCE_TYPE, resourceId, SamConstants.toSamAction(Role.Action.WRITE))) .thenReturn(Boolean.TRUE); final List<Role.Action> actions = samPermissionsImpl.getActionsForWorkflow(userMock, workflowInstance); Assert.assertEquals(2, actions.size()); Assert.assertTrue(actions.contains(Role.Action.WRITE) && actions.contains(Role.Action.READ)); }
@Test public void testReadersActions() throws ApiException { final String resourceId = SamConstants.WORKFLOW_PREFIX + FOO_WORKFLOW_NAME; when(resourcesApiMock.resourceAction(SamConstants.RESOURCE_TYPE, resourceId, SamConstants.toSamAction(Role.Action.SHARE))) .thenReturn(Boolean.FALSE); when(resourcesApiMock.resourceAction(SamConstants.RESOURCE_TYPE, resourceId, SamConstants.toSamAction(Role.Action.WRITE))) .thenReturn(Boolean.FALSE); when(resourcesApiMock.resourceAction(SamConstants.RESOURCE_TYPE, resourceId, SamConstants.toSamAction(Role.Action.READ))) .thenReturn(Boolean.TRUE); final List<Role.Action> actions = samPermissionsImpl.getActionsForWorkflow(userMock, workflowInstance); Assert.assertEquals(1, actions.size()); Assert.assertTrue(actions.contains(Role.Action.READ)); }
@Test public void testDockstoreOwnerNoSamPermissions() { when(workflowInstance.getUsers()).thenReturn(new HashSet<>(Collections.singletonList(userMock))); final List<Role.Action> actions = samPermissionsImpl.getActionsForWorkflow(userMock, workflowInstance); Assert.assertEquals(Role.Action.values().length, actions.size()); }