Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZQMS-663: More info in permissions store, fix tree element actions #5090

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
})

async function onMenuClick (ev: MouseEvent): Promise<void> {
// 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
})
Expand Down
23 changes: 23 additions & 0 deletions plugins/view-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1332,20 +1332,24 @@ async function getAttrEditor (key: KeyedAttribute, hierarchy: Hierarchy): Promis
}

type PermissionsBySpace = Record<Ref<Space>, Set<Ref<Permission>>>
type AccountsByPermission = Record<Ref<Space>, Record<Ref<Permission>, Set<Ref<Account>>>>
interface PermissionsStore {
ps: PermissionsBySpace
ap: AccountsByPermission
whitelist: Set<Ref<Space>>
}

export const permissionsStore = writable<PermissionsStore>({
ps: {},
ap: {},
whitelist: new Set()
})
const permissionsQuery = createQuery(true)

permissionsQuery.query(core.class.Space, {}, (res) => {
const whitelistedSpaces = new Set<Ref<Space>>()
const permissionsBySpace: PermissionsBySpace = {}
const accountsByPermission: AccountsByPermission = {}
const client = getClient()
const hierarchy = client.getHierarchy()
const me = getCurrentAccount()
Expand All @@ -1364,13 +1368,32 @@ 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<Ref<Account>> = (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)
}
}

permissionsStore.set({
ps: permissionsBySpace,
ap: accountsByPermission,
whitelist: whitelistedSpaces
})
})