EZQMS-663: Add permissions util (#5189)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev 2024-04-04 19:41:28 +04:00 committed by GitHub
parent dc580157c6
commit 4379549291
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1333,12 +1333,16 @@ async function getAttrEditor (key: KeyedAttribute, hierarchy: Hierarchy): Promis
type PermissionsBySpace = Record<Ref<Space>, Set<Ref<Permission>>> type PermissionsBySpace = Record<Ref<Space>, Set<Ref<Permission>>>
type AccountsByPermission = Record<Ref<Space>, Record<Ref<Permission>, Set<Ref<Account>>>> type AccountsByPermission = Record<Ref<Space>, Record<Ref<Permission>, Set<Ref<Account>>>>
interface PermissionsStore { export interface PermissionsStore {
ps: PermissionsBySpace ps: PermissionsBySpace
ap: AccountsByPermission ap: AccountsByPermission
whitelist: Set<Ref<Space>> whitelist: Set<Ref<Space>>
} }
export function checkMyPermission (_id: Ref<Permission>, space: Ref<TypedSpace>, store: PermissionsStore): boolean {
return (store.whitelist.has(space) || store.ps[space]?.has(_id)) ?? false
}
export const permissionsStore = writable<PermissionsStore>({ export const permissionsStore = writable<PermissionsStore>({
ps: {}, ps: {},
ap: {}, ap: {},