mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-12 19:30:52 +00:00
ezqms-663: add more info to permissions store, fix tree element actions (#5090)
Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
parent
ff26de4919
commit
a7914674d7
@ -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
|
||||
})
|
||||
|
@ -1332,13 +1332,16 @@ 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)
|
||||
@ -1346,6 +1349,7 @@ 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()
|
||||
@ -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<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)
|
||||
}
|
||||
@ -1371,6 +1393,7 @@ permissionsQuery.query(core.class.Space, {}, (res) => {
|
||||
|
||||
permissionsStore.set({
|
||||
ps: permissionsBySpace,
|
||||
ap: accountsByPermission,
|
||||
whitelist: whitelistedSpaces
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user