feat: Add default ACL (#8701)

This commit is contained in:
Daniel
2025-03-25 01:15:27 +11:00
committed by GitHub
parent b9917dd734
commit 12b5d781dc
10 changed files with 245 additions and 5 deletions

View File

@@ -255,6 +255,7 @@ function validateProtectedFieldsKey(key, userIdRegExp) {
}
const CLPValidKeys = Object.freeze([
'ACL',
'find',
'count',
'get',
@@ -364,13 +365,34 @@ function validateCLP(perms: ClassLevelPermissions, fields: SchemaFields, userIdR
continue;
}
// or [entity]: boolean
const permit = operation[entity];
if (permit !== true) {
if (operationKey === 'ACL') {
if (Object.prototype.toString.call(permit) !== '[object Object]') {
throw new Parse.Error(
Parse.Error.INVALID_JSON,
`'${permit}' is not a valid value for class level permissions acl`
);
}
const invalidKeys = Object.keys(permit).filter(key => !['read', 'write'].includes(key));
const invalidValues = Object.values(permit).filter(key => typeof key !== 'boolean');
if (invalidKeys.length) {
throw new Parse.Error(
Parse.Error.INVALID_JSON,
`'${invalidKeys.join(',')}' is not a valid key for class level permissions acl`
);
}
if (invalidValues.length) {
throw new Parse.Error(
Parse.Error.INVALID_JSON,
`'${invalidValues.join(',')}' is not a valid value for class level permissions acl`
);
}
} else if (permit !== true) {
throw new Parse.Error(
Parse.Error.INVALID_JSON,
`'${permit}' is not a valid value for class level permissions ${operationKey}:${entity}:${permit}`
`'${permit}' is not a valid value for class level permissions acl ${operationKey}:${entity}`
);
}
}

View File

@@ -19,6 +19,11 @@ export type Schema = {
};
export type ClassLevelPermissions = {
ACL?: {
[string]: {
[string]: boolean,
},
},
find?: { [string]: boolean },
count?: { [string]: boolean },
get?: { [string]: boolean },