GraphQL: ACL (#5957)

* Spec

Fix Spec

* Add ACL Type + Input

* Improvements

* Fix
This commit is contained in:
Antoine Cormouls
2019-10-02 06:47:56 +02:00
committed by Antonio Davi Macedo Coelho de Castro
parent 9cf3b52bef
commit 2290145e82
10 changed files with 465 additions and 187 deletions

View File

@@ -53,7 +53,7 @@ const transformInputTypeToGraphQL = (
case 'Bytes':
return defaultGraphQLTypes.BYTES;
case 'ACL':
return defaultGraphQLTypes.OBJECT;
return defaultGraphQLTypes.ACL_INPUT;
default:
return undefined;
}

View File

@@ -60,6 +60,7 @@ const transformTypes = async (
}
});
await Promise.all(promises);
if (fields.ACL) fields.ACL = transformers.ACL(fields.ACL);
}
return fields;
};
@@ -73,6 +74,32 @@ const transformers = {
...value,
__type: 'GeoPoint',
}),
ACL: value => {
const parseACL = {};
if (value.public) {
parseACL['*'] = {
read: value.public.read,
write: value.public.write,
};
}
if (value.users) {
value.users.forEach(rule => {
parseACL[rule.userId] = {
read: rule.read,
write: rule.write,
};
});
}
if (value.roles) {
value.roles.forEach(rule => {
parseACL[`role:${rule.roleName}`] = {
read: rule.read,
write: rule.write,
};
});
}
return parseACL;
},
relation: async (
targetClass,
field,

View File

@@ -56,7 +56,7 @@ const transformOutputTypeToGraphQL = (
case 'Bytes':
return defaultGraphQLTypes.BYTES;
case 'ACL':
return defaultGraphQLTypes.OBJECT;
return defaultGraphQLTypes.ACL;
default:
return undefined;
}

View File

@@ -198,7 +198,12 @@ const transformQueryInputToParse = (constraints, fields) => {
}
if (typeof fieldValue === 'object') {
transformQueryConstraintInputToParse(fieldValue, fields, fieldName, constraints);
transformQueryConstraintInputToParse(
fieldValue,
fields,
fieldName,
constraints
);
}
});
};