use fallback permissions correctly
This commit is contained in:
@@ -58,18 +58,31 @@ export class UmbDocumentUserPermissionCondition
|
||||
if (!this.#entityType) return;
|
||||
if (this.#unique === undefined) return;
|
||||
|
||||
let verbs: Array<string> = this.#fallbackPermissions;
|
||||
const hasDocumentPermissions = this.#documentPermissions.length > 0;
|
||||
|
||||
if (this.#documentPermissions) {
|
||||
// if there is no permissions for any documents we use the fallback permissions
|
||||
if (!hasDocumentPermissions) {
|
||||
this.#check(this.#fallbackPermissions);
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasDocumentPermissions) {
|
||||
const permissionsForCurrentDocument = this.#documentPermissions.find(
|
||||
(permission) => permission.document.id === this.#unique,
|
||||
);
|
||||
const currentDocumentVerbs = permissionsForCurrentDocument ? permissionsForCurrentDocument.verbs : [];
|
||||
verbs = verbs.concat(currentDocumentVerbs);
|
||||
}
|
||||
|
||||
const uniqueVerbs = [...new Set(verbs)];
|
||||
this.permitted = this.config.allOf.every((verb) => uniqueVerbs.includes(verb));
|
||||
// no permissions for the current document - use the fallback permissions
|
||||
if (!permissionsForCurrentDocument) {
|
||||
this.#check(this.#fallbackPermissions);
|
||||
return;
|
||||
}
|
||||
|
||||
this.#check(permissionsForCurrentDocument.verbs);
|
||||
}
|
||||
}
|
||||
|
||||
#check(verbs: Array<string>) {
|
||||
this.permitted = this.config.allOf.every((verb) => verbs.includes(verb));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user