@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"))); }
@Override public GraphQLFieldDefinition getFieldDefinition(GraphQLFieldsContainer fieldsContainer, String fieldName) { Iterator<GraphQLFieldDefinition> graphQlFieldDefinitionIterator = fieldsContainer.getFieldDefinitions().iterator(); while (graphQlFieldDefinitionIterator.hasNext()) { GraphQLFieldDefinition graphQlFieldDefinition = graphQlFieldDefinitionIterator.next(); if (!dataSetNamesWithOutReadPermission.contains(graphQlFieldDefinition.getName()) && graphQlFieldDefinition.getName().equals(fieldName)) { return graphQlFieldDefinition; } } return null; }
PermissionBasedFieldVisibility implements GraphqlFieldVisibility { @Override public GraphQLFieldDefinition getFieldDefinition(GraphQLFieldsContainer fieldsContainer, String fieldName) { Iterator<GraphQLFieldDefinition> graphQlFieldDefinitionIterator = fieldsContainer.getFieldDefinitions().iterator(); while (graphQlFieldDefinitionIterator.hasNext()) { GraphQLFieldDefinition graphQlFieldDefinition = graphQlFieldDefinitionIterator.next(); if (!dataSetNamesWithOutReadPermission.contains(graphQlFieldDefinition.getName()) && graphQlFieldDefinition.getName().equals(fieldName)) { return graphQlFieldDefinition; } } return null; } }
PermissionBasedFieldVisibility implements GraphqlFieldVisibility { @Override public GraphQLFieldDefinition getFieldDefinition(GraphQLFieldsContainer fieldsContainer, String fieldName) { Iterator<GraphQLFieldDefinition> graphQlFieldDefinitionIterator = fieldsContainer.getFieldDefinitions().iterator(); while (graphQlFieldDefinitionIterator.hasNext()) { GraphQLFieldDefinition graphQlFieldDefinition = graphQlFieldDefinitionIterator.next(); if (!dataSetNamesWithOutReadPermission.contains(graphQlFieldDefinition.getName()) && graphQlFieldDefinition.getName().equals(fieldName)) { return graphQlFieldDefinition; } } return null; } PermissionBasedFieldVisibility(UserPermissionCheck userPermissionCheck, DataSetRepository dataSetRepository); }
PermissionBasedFieldVisibility implements GraphqlFieldVisibility { @Override public GraphQLFieldDefinition getFieldDefinition(GraphQLFieldsContainer fieldsContainer, String fieldName) { Iterator<GraphQLFieldDefinition> graphQlFieldDefinitionIterator = fieldsContainer.getFieldDefinitions().iterator(); while (graphQlFieldDefinitionIterator.hasNext()) { GraphQLFieldDefinition graphQlFieldDefinition = graphQlFieldDefinitionIterator.next(); if (!dataSetNamesWithOutReadPermission.contains(graphQlFieldDefinition.getName()) && graphQlFieldDefinition.getName().equals(fieldName)) { return graphQlFieldDefinition; } } return null; } PermissionBasedFieldVisibility(UserPermissionCheck userPermissionCheck, DataSetRepository dataSetRepository); @Override List<GraphQLFieldDefinition> getFieldDefinitions(GraphQLFieldsContainer fieldsContainer); @Override GraphQLFieldDefinition getFieldDefinition(GraphQLFieldsContainer fieldsContainer, String fieldName); }
PermissionBasedFieldVisibility implements GraphqlFieldVisibility { @Override public GraphQLFieldDefinition getFieldDefinition(GraphQLFieldsContainer fieldsContainer, String fieldName) { Iterator<GraphQLFieldDefinition> graphQlFieldDefinitionIterator = fieldsContainer.getFieldDefinitions().iterator(); while (graphQlFieldDefinitionIterator.hasNext()) { GraphQLFieldDefinition graphQlFieldDefinition = graphQlFieldDefinitionIterator.next(); if (!dataSetNamesWithOutReadPermission.contains(graphQlFieldDefinition.getName()) && graphQlFieldDefinition.getName().equals(fieldName)) { return graphQlFieldDefinition; } } return null; } PermissionBasedFieldVisibility(UserPermissionCheck userPermissionCheck, DataSetRepository dataSetRepository); @Override List<GraphQLFieldDefinition> getFieldDefinitions(GraphQLFieldsContainer fieldsContainer); @Override GraphQLFieldDefinition getFieldDefinition(GraphQLFieldsContainer fieldsContainer, String fieldName);  }