use of graphql.schema.GraphQLFieldsContainer in project timbuctoo by HuygensING.
the class PermissionBasedFieldVisibility method getFieldDefinitions.
@Override
public List<GraphQLFieldDefinition> getFieldDefinitions(GraphQLFieldsContainer fieldsContainer) {
List<GraphQLFieldDefinition> graphQlFieldDefinitions = new ArrayList<>();
Collection<DataSet> dataSets = dataSetRepository.getDataSets();
Set<String> dataSetNamesWithOutReadPermission = dataSets.stream().filter(dataSet -> !userPermissionCheck.getPermissions(dataSet.getMetadata()).contains(Permission.READ)).map(dataSet -> dataSet.getMetadata().getCombinedId()).collect(Collectors.toSet());
Iterator<GraphQLFieldDefinition> graphQlFieldDefinitionIterator = fieldsContainer.getFieldDefinitions().iterator();
while (graphQlFieldDefinitionIterator.hasNext()) {
GraphQLFieldDefinition graphQlFieldDefinition = graphQlFieldDefinitionIterator.next();
if (!dataSetNamesWithOutReadPermission.contains(graphQlFieldDefinition.getName())) {
graphQlFieldDefinitions.add(graphQlFieldDefinition);
}
}
return graphQlFieldDefinitions;
}
use of graphql.schema.GraphQLFieldsContainer in project timbuctoo by HuygensING.
the class PermissionBasedFieldVisibilityTest method getFieldDefinitionReturnsFieldDefinitionIfUserHasPermission.
@Test
public void getFieldDefinitionReturnsFieldDefinitionIfUserHasPermission() 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");
GraphQLFieldDefinition retrievedGraphQlFieldDefinition = permissionBasedFieldVisibility.getFieldDefinition(graphQlFieldsContainer, "user__dataSetUserHasAccessTo");
assertThat(retrievedGraphQlFieldDefinition, hasProperty("name", is("user__dataSetUserHasAccessTo")));
}
use of graphql.schema.GraphQLFieldsContainer in project timbuctoo by HuygensING.
the class PermissionBasedFieldVisibilityTest method createGraphQlFieldsContainer.
private GraphQLFieldsContainer createGraphQlFieldsContainer(String... fieldNames) {
List<GraphQLFieldDefinition> graphQlFieldDefinitions = new ArrayList<>();
final GraphQLFieldsContainer graphQlFieldsContainer = mock(GraphQLFieldsContainer.class);
for (String fieldName : fieldNames) {
GraphQLFieldDefinition graphQlFieldDefinition = createGraphQlFieldDefinition(fieldName);
graphQlFieldDefinitions.add(graphQlFieldDefinition);
given(graphQlFieldsContainer.getFieldDefinition(fieldName)).willReturn(graphQlFieldDefinition);
}
given(graphQlFieldsContainer.getFieldDefinitions()).willReturn(graphQlFieldDefinitions);
return graphQlFieldsContainer;
}
use of graphql.schema.GraphQLFieldsContainer in project timbuctoo by HuygensING.
the class PermissionBasedFieldVisibilityTest method getFieldDefinitionReturnsNullIfUserHasNoPermission.
@Test
public void getFieldDefinitionReturnsNullIfUserHasNoPermission() 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");
GraphQLFieldDefinition retrievedGraphQlFieldDefinition = permissionBasedFieldVisibility.getFieldDefinition(graphQlFieldsContainer, "user__dataSetUserDoesNotHasAccessTo");
assertThat(retrievedGraphQlFieldDefinition, is(nullValue()));
}
use of graphql.schema.GraphQLFieldsContainer in project timbuctoo by HuygensING.
the class PermissionBasedFieldVisibilityTest method getFieldDefinitionsShowsOnlyDataSetsThatUserHasAccessTo.
@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"))));
}
Aggregations