Files
speckle-server/packages/server/modules/workspaces/domain/logic.ts
T
Gergő Jedlicska 4a2d85d68c feat(server): web 3485 prevent accounts from creating new workspaces (#4913)
* 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
2025-06-18 08:58:26 +01:00

57 lines
1.7 KiB
TypeScript

import { UserEmail } from '@/modules/core/domain/userEmails/types'
import { WorkspaceDomainsInvalidState } from '@/modules/workspaces/errors/workspace'
import {
LimitedWorkspace,
Workspace,
WorkspaceDomain
} from '@/modules/workspacesCore/domain/types'
import { Roles, WorkspaceRoles } from '@speckle/shared'
export const userEmailsCompliantWithWorkspaceDomains = ({
userEmails,
workspaceDomains
}: {
userEmails: UserEmail[]
workspaceDomains: WorkspaceDomain[]
}): boolean =>
anyEmailCompliantWithWorkspaceDomains({
emails: userEmails.filter((e) => e.verified).map((e) => e.email),
workspaceDomains
})
export const anyEmailCompliantWithWorkspaceDomains = ({
emails,
workspaceDomains
}: {
emails: string[]
workspaceDomains: WorkspaceDomain[]
}): boolean => {
const validWorkspaceDomains = workspaceDomains.filter((domain) => domain.verified)
// we must have min 1 domain to validate compliance
if (!validWorkspaceDomains.length) throw new WorkspaceDomainsInvalidState()
for (const email of emails) {
if (validWorkspaceDomains.some((domain) => email.endsWith(domain.domain)))
return true
}
return false
}
export const isWorkspaceRole = (role: string): role is WorkspaceRoles => {
const validRoles: string[] = Object.values(Roles.Workspace)
return validRoles.includes(role)
}
export const toLimitedWorkspace = (workspace: Workspace): LimitedWorkspace => {
return {
id: workspace.id,
slug: workspace.slug,
name: workspace.name,
description: workspace.description,
logo: workspace.logo,
discoverabilityAutoJoinEnabled: workspace.discoverabilityAutoJoinEnabled,
isExclusive: workspace.isExclusive
}
}