From 90ba9a25c52181a3c2f71b5c0ea560c040d75c2f Mon Sep 17 00:00:00 2001 From: Alexey Zinoviev Date: Thu, 28 Mar 2024 21:37:29 +0400 Subject: [PATCH] ezqms-663: add more info to permissions store, fix tree element actions Signed-off-by: Alexey Zinoviev --- .../components/navigator/TreeElement.svelte | 2 ++ plugins/view-resources/src/utils.ts | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/plugins/view-resources/src/components/navigator/TreeElement.svelte b/plugins/view-resources/src/components/navigator/TreeElement.svelte index 06dadc99ce2..c577b613ab2 100644 --- a/plugins/view-resources/src/components/navigator/TreeElement.svelte +++ b/plugins/view-resources/src/components/navigator/TreeElement.svelte @@ -58,6 +58,8 @@ }) async function onMenuClick (ev: MouseEvent): Promise { + // Read actual popup actions on open as visibility might have been changed + popupMenuActions = await actions().then((res) => res.filter((action) => action.inline !== true)) showPopup(Menu, { actions: popupMenuActions, ctx: _id }, ev.target as HTMLElement, () => { hovered = false }) diff --git a/plugins/view-resources/src/utils.ts b/plugins/view-resources/src/utils.ts index 1629405bf01..ab812cbdf10 100644 --- a/plugins/view-resources/src/utils.ts +++ b/plugins/view-resources/src/utils.ts @@ -1332,13 +1332,16 @@ async function getAttrEditor (key: KeyedAttribute, hierarchy: Hierarchy): Promis } type PermissionsBySpace = Record, Set>> +type AccountsByPermission = Record, Record, Set>>> interface PermissionsStore { ps: PermissionsBySpace + ap: AccountsByPermission whitelist: Set> } export const permissionsStore = writable({ ps: {}, + ap: {}, whitelist: new Set() }) const permissionsQuery = createQuery(true) @@ -1346,6 +1349,7 @@ const permissionsQuery = createQuery(true) permissionsQuery.query(core.class.Space, {}, (res) => { const whitelistedSpaces = new Set>() const permissionsBySpace: PermissionsBySpace = {} + const accountsByPermission: AccountsByPermission = {} const client = getClient() const hierarchy = client.getHierarchy() const me = getCurrentAccount() @@ -1364,6 +1368,24 @@ permissionsQuery.query(core.class.Space, {}, (res) => { const roles = client.getModel().findAllSync(core.class.Role, { attachedTo: type._id }) const myRoles = roles.filter((r) => ((asMixin as any)[r._id] ?? []).includes(me._id)) permissionsBySpace[s._id] = new Set(myRoles.flatMap((r) => r.permissions)) + + accountsByPermission[s._id] = {} + + for (const role of roles) { + const assignment: Array> = (asMixin as any)[role._id] ?? [] + + if (assignment.length === 0) { + continue + } + + for (const permissionId of role.permissions) { + if (accountsByPermission[s._id][permissionId] === undefined) { + accountsByPermission[s._id][permissionId] = new Set() + } + + assignment.forEach((acc) => accountsByPermission[s._id][permissionId].add(acc)) + } + } } else { whitelistedSpaces.add(s._id) } @@ -1371,6 +1393,7 @@ permissionsQuery.query(core.class.Space, {}, (res) => { permissionsStore.set({ ps: permissionsBySpace, + ap: accountsByPermission, whitelist: whitelistedSpaces }) })