794bd7c7e9
* feat(shared): rename user workspaces loader * feat(gatekeeper): intoduce the enterprise plan * chore(server): remove more "magic strings" * refactor(shared): extract user is workspace admin to an auth fragment * feat(shared): add can createWorkspacePolicy * feat(workspaces): WIP block workspace creation * feat(server): add can create workspace checks * feat(workspaces): enforce canCreateWorkspace policy on the workspace creation mutation * feat(shared): allow workspace admins and guests to create workspaces even if they are part of an exclusive workspace * test(shared): use test fake properly * fix(server): eligble workspace typing fixes * test(shared): fix more workspace fakes * fix(workspacesCore): add missing loader * fix(shared): use proper exhaustive switch cases, they stop bugs from happening * feat(shared): introduce workspacePlanHasAccessToFeature function with tests * chore(workspaces): fix more PR comments * fix(workspaces): naming * fix(workspaces): some more * feat(shared): generalize workspace feature access policy * feat(workspaces): allow toggling the isExclusive option for workspace update
61 lines
2.1 KiB
TypeScript
61 lines
2.1 KiB
TypeScript
import { Resolvers } from '@/modules/core/graph/generated/graphql'
|
|
import { Authz, WorkspacePlanFeatures } from '@speckle/shared'
|
|
|
|
export default {
|
|
Workspace: {
|
|
permissions: (parent) => ({
|
|
workspaceId: parent.id
|
|
})
|
|
},
|
|
WorkspacePermissionChecks: {
|
|
canCreateProject: async (parent, _args, ctx) => {
|
|
const canCreateProject = await ctx.authPolicies.workspace.canCreateProject({
|
|
workspaceId: parent.workspaceId,
|
|
userId: ctx.userId
|
|
})
|
|
return Authz.toGraphqlResult(canCreateProject)
|
|
},
|
|
canInvite: async (parent, _args, ctx) => {
|
|
const canInvite = await ctx.authPolicies.workspace.canInvite({
|
|
workspaceId: parent.workspaceId,
|
|
userId: ctx.userId
|
|
})
|
|
return Authz.toGraphqlResult(canInvite)
|
|
},
|
|
canMoveProjectToWorkspace: async (parent, args, ctx) => {
|
|
const canMoveProjectToWorkspace =
|
|
await ctx.authPolicies.project.canMoveToWorkspace({
|
|
userId: ctx.userId,
|
|
projectId: args.projectId ?? undefined,
|
|
workspaceId: parent.workspaceId
|
|
})
|
|
return Authz.toGraphqlResult(canMoveProjectToWorkspace)
|
|
},
|
|
canEditEmbedOptions: async (parent, _args, ctx) => {
|
|
const canEditEmbedOptions =
|
|
await ctx.authPolicies.workspace.canUseWorkspacePlanFeature({
|
|
userId: ctx.userId,
|
|
workspaceId: parent.workspaceId,
|
|
feature: WorkspacePlanFeatures.HideSpeckleBranding
|
|
})
|
|
return Authz.toGraphqlResult(canEditEmbedOptions)
|
|
},
|
|
canMakeWorkspaceExclusive: async (parent, _args, ctx) => {
|
|
const canEditEmbedOptions =
|
|
await ctx.authPolicies.workspace.canUseWorkspacePlanFeature({
|
|
userId: ctx.userId,
|
|
workspaceId: parent.workspaceId,
|
|
feature: WorkspacePlanFeatures.ExclusiveMembership
|
|
})
|
|
return Authz.toGraphqlResult(canEditEmbedOptions)
|
|
},
|
|
canReadMemberEmail: async (parent, _args, ctx) => {
|
|
const policyResult = await ctx.authPolicies.workspace.canReadMemberEmail({
|
|
userId: ctx.userId,
|
|
workspaceId: parent.workspaceId
|
|
})
|
|
return Authz.toGraphqlResult(policyResult)
|
|
}
|
|
}
|
|
} as Resolvers
|