Files
speckle-server/packages/server/modules/workspaces/authz.ts
T
Gergő Jedlicska 968d2f2520 auth/lib (#4242)
* wip

* wip

* feat(authz): wip policy shape

* wip

* fix(authz): canReadProject with latest pattern

* wip

* feat(shared): simplify authz checks and policies

* feat(shared): port role weights into shared

* test(shared): some more tests for authz

* test(shared): more query project tests

* typo!

* feat(shared): ff loading refinements

* feat(shared): example authorization policy integration

* authz loaders init

* chore(authz): naming etc

* wip

* fix(authz): authz error objects

Co-authored-by: Kristaps Fabians Geikins <fabis94@users.noreply.github.com>
Co-authored-by: Gergő Jedlicska <gjedlicska@users.noreply.github.com>

* fix(authz): use correct role weights

* chore(authz): use codes from errors in tests

* chore(authz): wow

* chore(authz): fix more tests, add more tests

* chore(authz): fix some tests, add some tests (again)

* fix(authz): fix tests again

* fix(server): you need to await !!!! otherwise it crashes the server.

---------

Co-authored-by: Charles Driesler <chuck@speckle.systems>
Co-authored-by: Kristaps Fabians Geikins <fabis94@users.noreply.github.com>
Co-authored-by: Gergő Jedlicska <gjedlicska@users.noreply.github.com>
2025-03-21 16:37:36 +01:00

37 lines
1.0 KiB
TypeScript

import { db } from '@/db/knex'
import { defineLoaders } from '@/modules/loaders'
import {
getUserSsoSessionFactory,
getWorkspaceSsoProviderRecordFactory
} from '@/modules/workspaces/repositories/sso'
import {
getWorkspaceFactory,
getWorkspaceRoleForUserFactory
} from '@/modules/workspaces/repositories/workspaces'
export const defineModuleLoaders = () => {
defineLoaders({
getWorkspace: getWorkspaceFactory({ db }),
getWorkspaceRole: async ({ userId, workspaceId }) => {
const role = await getWorkspaceRoleForUserFactory({ db })({
userId,
workspaceId
})
return role?.role ?? null
},
getWorkspaceSsoSession: async ({ userId, workspaceId }) => {
const ssoSession = await getUserSsoSessionFactory({ db })({
userId,
workspaceId
})
return ssoSession ?? null
},
getWorkspaceSsoProvider: async ({ workspaceId }) => {
const ssoProvider = await getWorkspaceSsoProviderRecordFactory({ db })({
workspaceId
})
return ssoProvider ?? null
}
})
}