820a1e2ebf
* 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
31 lines
1.0 KiB
TypeScript
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
|
|
})
|
|
}
|