uberf-7764: improve space permissions query (#6236)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev 2024-08-03 10:10:44 +04:00 committed by GitHub
parent 7c1a1619e8
commit c675f45491
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1495,9 +1495,21 @@ export const permissionsStore = writable<PermissionsStore>({
ap: {}, ap: {},
whitelist: new Set() whitelist: new Set()
}) })
const permissionsQuery = createQuery(true)
permissionsQuery.query(core.class.Space, {}, (res) => { const spaceTypesQuery = createQuery(true)
const permissionsQuery = createQuery(true)
type TargetClassesProjection = Record<Ref<Class<Space>>, number>
spaceTypesQuery.query(core.class.SpaceType, {}, (types) => {
const targetClasses = types.reduce<TargetClassesProjection>((acc, st) => {
acc[st.targetClass] = 1
return acc
}, {})
permissionsQuery.query(
core.class.Space,
{},
(res) => {
const whitelistedSpaces = new Set<Ref<Space>>() const whitelistedSpaces = new Set<Ref<Space>>()
const permissionsBySpace: PermissionsBySpace = {} const permissionsBySpace: PermissionsBySpace = {}
const accountsByPermission: AccountsByPermission = {} const accountsByPermission: AccountsByPermission = {}
@ -1548,6 +1560,15 @@ permissionsQuery.query(core.class.Space, {}, (res) => {
ap: accountsByPermission, ap: accountsByPermission,
whitelist: whitelistedSpaces whitelist: whitelistedSpaces
}) })
},
{
projection: {
_id: 1,
type: 1,
...targetClasses
} as any
}
)
}) })
export function getCollaborationUser (): CollaborationUser { export function getCollaborationUser (): CollaborationUser {