Files
speckle-server/packages/server/modules/gatekeeper/services/featureAuthorization.ts
T
Gergő Jedlicska f210d9b749 gergo/web 2109 project region based db connection selector (#3434)
* feat(projects): add project regions, default to null

* feat(multiregion): add projectRegion Db client lookup logic

* feat(multiregion): add project region repositories and caching

* feat(multiRegion): db initialization and get project db client

* feat(docker-compose): add second db for regions testing

* feat(multiRegion): initialize region with pubs and subs working

* fix(multiRegion): get region client even if it was registered in another pod

* feat(workspaces): create workspace resolver split

* feat: update server region metadata

* feat(projects): rewrite project creation

* feat(multiRegion): getRegionDb

* fix(workspaces): get projects now can retur null

* feat(multiRegion): make local multi region DB-s work

* feat: set d efault workspace region

* CR changes

* tests

* feat(multiRegion): bind region properly

* fe update

* test fixes

* feat(multiRegion): automatically create aiven extras plugin

* ci(postgres): use published postgres with aiven extras

* fix(multiRegion): roll back the aiven extras migration, there is a better way

* tests fix

* fix(billing): we do not need to add a seat, if the workspace is on a plan, but has no sub

---------

Co-authored-by: Kristaps Fabians Geikins <fabis94@live.com>
2024-11-06 17:29:08 +01:00

53 lines
1.8 KiB
TypeScript

import { GetWorkspacePlan } from '@/modules/gatekeeper/domain/billing'
import {
CanWorkspaceAccessFeature,
WorkspaceFeatureAccessFunction
} from '@/modules/gatekeeper/domain/operations'
import { workspacePlanFeatures } from '@/modules/gatekeeper/domain/workspacePricing'
import { throwUncoveredError } from '@speckle/shared'
export const canWorkspaceAccessFeatureFactory =
({
getWorkspacePlan
}: {
getWorkspacePlan: GetWorkspacePlan
}): CanWorkspaceAccessFeature =>
async ({ workspaceId, workspaceFeature }) => {
const workspacePlan = await getWorkspacePlan({ workspaceId })
if (!workspacePlan) return false
switch (workspacePlan.status) {
case 'valid':
case 'trial':
case 'paymentFailed':
case 'cancelationScheduled':
break
case 'expired':
case 'canceled':
return false
default:
throwUncoveredError(workspacePlan)
}
return workspacePlanFeatures[workspacePlan.name][workspaceFeature]
}
export const canWorkspaceUseOidcSsoFactory =
(deps: { getWorkspacePlan: GetWorkspacePlan }): WorkspaceFeatureAccessFunction =>
async ({ workspaceId }) =>
canWorkspaceAccessFeatureFactory(deps)({ workspaceId, workspaceFeature: 'oidcSso' })
export const canWorkspaceUseRegionsFactory =
(deps: { getWorkspacePlan: GetWorkspacePlan }): WorkspaceFeatureAccessFunction =>
async ({ workspaceId }) =>
canWorkspaceAccessFeatureFactory(deps)({
workspaceId,
workspaceFeature: 'workspaceDataRegionSpecificity'
})
export const canWorkspaceUseDomainBasedSecurityPolicies =
(deps: { getWorkspacePlan: GetWorkspacePlan }): WorkspaceFeatureAccessFunction =>
async ({ workspaceId }) =>
canWorkspaceAccessFeatureFactory(deps)({
workspaceId,
workspaceFeature: 'domainBasedSecurityPolicies'
})