GraphQL: ACL (#5957)
* Spec Fix Spec * Add ACL Type + Input * Improvements * Fix
This commit is contained in:
committed by
Antonio Davi Macedo Coelho de Castro
parent
9cf3b52bef
commit
2290145e82
@@ -53,7 +53,7 @@ const transformInputTypeToGraphQL = (
|
||||
case 'Bytes':
|
||||
return defaultGraphQLTypes.BYTES;
|
||||
case 'ACL':
|
||||
return defaultGraphQLTypes.OBJECT;
|
||||
return defaultGraphQLTypes.ACL_INPUT;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -56,7 +56,7 @@ const transformOutputTypeToGraphQL = (
|
||||
case 'Bytes':
|
||||
return defaultGraphQLTypes.BYTES;
|
||||
case 'ACL':
|
||||
return defaultGraphQLTypes.OBJECT;
|
||||
return defaultGraphQLTypes.ACL;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -198,7 +198,12 @@ const transformQueryInputToParse = (constraints, fields) => {
|
||||
}
|
||||
|
||||
if (typeof fieldValue === 'object') {
|
||||
transformQueryConstraintInputToParse(fieldValue, fields, fieldName, constraints);
|
||||
transformQueryConstraintInputToParse(
|
||||
fieldValue,
|
||||
fields,
|
||||
fieldName,
|
||||
constraints
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user