Files
speckle-server/packages/shared/src/authz/checks/serverRole.ts
T
Kristaps Fabians Geikins 820a1e2ebf feat(server): workspace roles taken into account in project queries (#4319)
* Workspace.projects fixed

* Query.project tested & fixed

* personalOnly flag added

* withProjectRoleOnly flag

* authorizeResolver implicit workspace roles

* minor cleanup

* reorg + support for throwing auth errors

* global error mapping

* undo special borkage

* CR fixes

* more CR fixes

* shared tests fix

* minor adjustment

* tests fix

* see if removing cached roles fixes it?

* more fixes

* clean up debugging garbage
2025-04-07 12:52:07 +03:00

31 lines
1.0 KiB
TypeScript

import { Roles, ServerRoles } from '../../core/constants.js'
import { UserContext } from '../domain/context.js'
import { Loaders } from '../domain/loaders.js'
import { isMinimumServerRole } from '../domain/logic/roles.js'
import { AuthPolicyCheck } from '../domain/policies.js'
export const hasMinimumServerRole: AuthPolicyCheck<
'getServerRole',
UserContext & { role: ServerRoles }
> =
(loaders) =>
async ({ userId, role: requiredServerRole }) => {
const userServerRole = await loaders.getServerRole({ userId })
if (!userServerRole) return false
return isMinimumServerRole(userServerRole, requiredServerRole)
}
export const canUseAdminOverride: AuthPolicyCheck<
typeof Loaders.getAdminOverrideEnabled | 'getServerRole',
UserContext
> =
(loaders) =>
async ({ userId }) => {
const adminOverrideEnabled = await loaders.getAdminOverrideEnabled()
if (!adminOverrideEnabled) return false
return await hasMinimumServerRole(loaders)({
userId,
role: Roles.Server.Admin
})
}