@Test public void getFieldDefinitionsShowsOnlyDataSetsThatUserHasAccessTo() throws Exception { final DataSetRepository dataSetRepository = mock(DataSetRepository.class); DataSet dataSet = createDataSetWithUserPermissions( "user__dataSetUserHasAccessTo", Sets.newHashSet(Permission.READ) ); DataSet dataSet2 = createDataSetWithUserPermissions( "user__dataSetUserDoesNotHasAccessTo", Sets.newHashSet() ); Collection<DataSet> dataSetCollection = Sets.newHashSet(dataSet, dataSet2); given(dataSetRepository.getDataSets()).willReturn(dataSetCollection); final PermissionBasedFieldVisibility permissionBasedFieldVisibility = new PermissionBasedFieldVisibility(userPermissionCheck, dataSetRepository); final GraphQLFieldsContainer graphQlFieldsContainer = createGraphQlFieldsContainer( "user__dataSetUserHasAccessTo", "user__dataSetUserDoesNotHasAccessTo" ); List<GraphQLFieldDefinition> retrievedGraphQlFieldDefinitions = permissionBasedFieldVisibility .getFieldDefinitions(graphQlFieldsContainer); assertThat(retrievedGraphQlFieldDefinitions, contains(hasProperty("name", is("user__dataSetUserHasAccessTo")))); }
@Override public List<GraphQLFieldDefinition> getFieldDefinitions(GraphQLFieldsContainer fieldsContainer) { List<GraphQLFieldDefinition> graphQlFieldDefinitions = new ArrayList<>(); Iterator<GraphQLFieldDefinition> graphQlFieldDefinitionIterator = fieldsContainer.getFieldDefinitions().iterator(); while (graphQlFieldDefinitionIterator.hasNext()) { GraphQLFieldDefinition graphQlFieldDefinition = graphQlFieldDefinitionIterator.next(); if (!dataSetNamesWithOutReadPermission.contains(graphQlFieldDefinition.getName())) { graphQlFieldDefinitions.add(graphQlFieldDefinition); } } return graphQlFieldDefinitions; }
PermissionBasedFieldVisibility implements GraphqlFieldVisibility { @Override public List<GraphQLFieldDefinition> getFieldDefinitions(GraphQLFieldsContainer fieldsContainer) { List<GraphQLFieldDefinition> graphQlFieldDefinitions = new ArrayList<>(); Iterator<GraphQLFieldDefinition> graphQlFieldDefinitionIterator = fieldsContainer.getFieldDefinitions().iterator(); while (graphQlFieldDefinitionIterator.hasNext()) { GraphQLFieldDefinition graphQlFieldDefinition = graphQlFieldDefinitionIterator.next(); if (!dataSetNamesWithOutReadPermission.contains(graphQlFieldDefinition.getName())) { graphQlFieldDefinitions.add(graphQlFieldDefinition); } } return graphQlFieldDefinitions; } }
PermissionBasedFieldVisibility implements GraphqlFieldVisibility { @Override public List<GraphQLFieldDefinition> getFieldDefinitions(GraphQLFieldsContainer fieldsContainer) { List<GraphQLFieldDefinition> graphQlFieldDefinitions = new ArrayList<>(); Iterator<GraphQLFieldDefinition> graphQlFieldDefinitionIterator = fieldsContainer.getFieldDefinitions().iterator(); while (graphQlFieldDefinitionIterator.hasNext()) { GraphQLFieldDefinition graphQlFieldDefinition = graphQlFieldDefinitionIterator.next(); if (!dataSetNamesWithOutReadPermission.contains(graphQlFieldDefinition.getName())) { graphQlFieldDefinitions.add(graphQlFieldDefinition); } } return graphQlFieldDefinitions; } PermissionBasedFieldVisibility(UserPermissionCheck userPermissionCheck, DataSetRepository dataSetRepository); }
PermissionBasedFieldVisibility implements GraphqlFieldVisibility { @Override public List<GraphQLFieldDefinition> getFieldDefinitions(GraphQLFieldsContainer fieldsContainer) { List<GraphQLFieldDefinition> graphQlFieldDefinitions = new ArrayList<>(); Iterator<GraphQLFieldDefinition> graphQlFieldDefinitionIterator = fieldsContainer.getFieldDefinitions().iterator(); while (graphQlFieldDefinitionIterator.hasNext()) { GraphQLFieldDefinition graphQlFieldDefinition = graphQlFieldDefinitionIterator.next(); if (!dataSetNamesWithOutReadPermission.contains(graphQlFieldDefinition.getName())) { graphQlFieldDefinitions.add(graphQlFieldDefinition); } } return graphQlFieldDefinitions; } PermissionBasedFieldVisibility(UserPermissionCheck userPermissionCheck, DataSetRepository dataSetRepository); @Override List<GraphQLFieldDefinition> getFieldDefinitions(GraphQLFieldsContainer fieldsContainer); @Override GraphQLFieldDefinition getFieldDefinition(GraphQLFieldsContainer fieldsContainer, String fieldName); }
PermissionBasedFieldVisibility implements GraphqlFieldVisibility { @Override public List<GraphQLFieldDefinition> getFieldDefinitions(GraphQLFieldsContainer fieldsContainer) { List<GraphQLFieldDefinition> graphQlFieldDefinitions = new ArrayList<>(); Iterator<GraphQLFieldDefinition> graphQlFieldDefinitionIterator = fieldsContainer.getFieldDefinitions().iterator(); while (graphQlFieldDefinitionIterator.hasNext()) { GraphQLFieldDefinition graphQlFieldDefinition = graphQlFieldDefinitionIterator.next(); if (!dataSetNamesWithOutReadPermission.contains(graphQlFieldDefinition.getName())) { graphQlFieldDefinitions.add(graphQlFieldDefinition); } } return graphQlFieldDefinitions; } PermissionBasedFieldVisibility(UserPermissionCheck userPermissionCheck, DataSetRepository dataSetRepository); @Override List<GraphQLFieldDefinition> getFieldDefinitions(GraphQLFieldsContainer fieldsContainer); @Override GraphQLFieldDefinition getFieldDefinition(GraphQLFieldsContainer fieldsContainer, String fieldName);  }