Switch ACL to Relay Global Id (#6495)
This commit is contained in:
@@ -17,6 +17,7 @@ const { SubscriptionClient } = require('subscriptions-transport-ws');
|
|||||||
const { WebSocketLink } = require('apollo-link-ws');
|
const { WebSocketLink } = require('apollo-link-ws');
|
||||||
const ApolloClient = require('apollo-client').default;
|
const ApolloClient = require('apollo-client').default;
|
||||||
const gql = require('graphql-tag');
|
const gql = require('graphql-tag');
|
||||||
|
const { toGlobalId } = require('graphql-relay');
|
||||||
const {
|
const {
|
||||||
GraphQLObjectType,
|
GraphQLObjectType,
|
||||||
GraphQLString,
|
GraphQLString,
|
||||||
@@ -8284,6 +8285,18 @@ describe('ParseGraphQLServer', () => {
|
|||||||
|
|
||||||
await parseGraphQLServer.parseGraphQLSchema.databaseController.schemaCache.clear();
|
await parseGraphQLServer.parseGraphQLSchema.databaseController.schemaCache.clear();
|
||||||
|
|
||||||
|
const gqlUser = (
|
||||||
|
await apolloClient.query({
|
||||||
|
query: gql`
|
||||||
|
query getUser($id: ID!) {
|
||||||
|
user(id: $id) {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
variables: { id: user.id },
|
||||||
|
})
|
||||||
|
).data.user;
|
||||||
const {
|
const {
|
||||||
data: { createSomeClass },
|
data: { createSomeClass },
|
||||||
} = await apolloClient.mutate({
|
} = await apolloClient.mutate({
|
||||||
@@ -8317,7 +8330,7 @@ describe('ParseGraphQLServer', () => {
|
|||||||
fields: {
|
fields: {
|
||||||
ACL: {
|
ACL: {
|
||||||
users: [
|
users: [
|
||||||
{ userId: user.id, read: true, write: true },
|
{ userId: gqlUser.id, read: true, write: true },
|
||||||
{ userId: user2.id, read: true, write: false },
|
{ userId: user2.id, read: true, write: false },
|
||||||
],
|
],
|
||||||
roles: [
|
roles: [
|
||||||
@@ -8334,13 +8347,13 @@ describe('ParseGraphQLServer', () => {
|
|||||||
__typename: 'ACL',
|
__typename: 'ACL',
|
||||||
users: [
|
users: [
|
||||||
{
|
{
|
||||||
userId: user.id,
|
userId: toGlobalId('_User', user.id),
|
||||||
read: true,
|
read: true,
|
||||||
write: true,
|
write: true,
|
||||||
__typename: 'UserACL',
|
__typename: 'UserACL',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
userId: user2.id,
|
userId: toGlobalId('_User', user2.id),
|
||||||
read: true,
|
read: true,
|
||||||
write: false,
|
write: false,
|
||||||
__typename: 'UserACL',
|
__typename: 'UserACL',
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
GraphQLBoolean,
|
GraphQLBoolean,
|
||||||
GraphQLUnionType,
|
GraphQLUnionType,
|
||||||
} from 'graphql';
|
} from 'graphql';
|
||||||
|
import { toGlobalId } from 'graphql-relay';
|
||||||
import { GraphQLUpload } from 'graphql-upload';
|
import { GraphQLUpload } from 'graphql-upload';
|
||||||
|
|
||||||
class TypeValidationError extends Error {
|
class TypeValidationError extends Error {
|
||||||
@@ -553,7 +554,7 @@ const ACL = new GraphQLObjectType({
|
|||||||
Object.keys(p).forEach(rule => {
|
Object.keys(p).forEach(rule => {
|
||||||
if (rule !== '*' && rule.indexOf('role:') !== 0) {
|
if (rule !== '*' && rule.indexOf('role:') !== 0) {
|
||||||
users.push({
|
users.push({
|
||||||
userId: rule,
|
userId: toGlobalId('_User', rule),
|
||||||
read: p[rule].read ? true : false,
|
read: p[rule].read ? true : false,
|
||||||
write: p[rule].write ? true : false,
|
write: p[rule].write ? true : false,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -99,6 +99,10 @@ const transformers = {
|
|||||||
}
|
}
|
||||||
if (value.users) {
|
if (value.users) {
|
||||||
value.users.forEach(rule => {
|
value.users.forEach(rule => {
|
||||||
|
const globalIdObject = fromGlobalId(rule.userId);
|
||||||
|
if (globalIdObject.type === '_User') {
|
||||||
|
rule.userId = globalIdObject.id;
|
||||||
|
}
|
||||||
parseACL[rule.userId] = {
|
parseACL[rule.userId] = {
|
||||||
read: rule.read,
|
read: rule.read,
|
||||||
write: rule.write,
|
write: rule.write,
|
||||||
|
|||||||
Reference in New Issue
Block a user