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

@@ -367,6 +367,25 @@ RestWrite.prototype.setRequiredFieldsIfNeeded = function () {
}
};
// add default ACL
if (
schema?.classLevelPermissions?.ACL &&
!this.data.ACL &&
JSON.stringify(schema.classLevelPermissions.ACL) !==
JSON.stringify({ '*': { read: true, write: true } })
) {
const acl = deepcopy(schema.classLevelPermissions.ACL);
if (acl.currentUser) {
if (this.auth.user?.id) {
acl[this.auth.user?.id] = deepcopy(acl.currentUser);
}
delete acl.currentUser;
}
this.data.ACL = acl;
this.storage.fieldsChangedByTrigger = this.storage.fieldsChangedByTrigger || [];
this.storage.fieldsChangedByTrigger.push('ACL');
}
// Add default fields
if (!this.query) {
// allow customizing createdAt and updatedAt when using maintenance key