Skip to content

Commit

Permalink
gergo/workspacesMultiRegion (#3477)
Browse files Browse the repository at this point in the history
* feat(webhook-service): learn to speak multi region

* feat(fileimport-service): talk multi region to me

* feat(fileuploads, blobs): multi region

* feat(workspaces): update delet workspace with billing and regions

* fix typo

* feat(workspaces): remove old billing resolvers

* test(workspaces): fix tests

* fix(workspaces): remove unused schema
  • Loading branch information
gjedlicska authored Nov 19, 2024
1 parent 381c4e2 commit e30b8c8
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 586 deletions.
58 changes: 0 additions & 58 deletions packages/server/assets/workspacesCore/typedefs/workspaces.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -226,60 +226,6 @@ input PendingWorkspaceCollaboratorsFilter {
search: String
}

type WorkspaceVersionsCount {
"""
Total number of versions of all projects in the workspace
"""
current: Int!
"""
Maximum number of version of all projects in the workspace with no additional cost
"""
max: Int!
}

enum Currency {
GBP
USD
EUR
}

type WorkspaceCostItem {
count: Int!
name: String!
cost: Float!
label: String!
}

type WorkspaceCostDiscount {
name: String!
amount: Float!
}

type WorkspaceCost {
"""
Estimated cost of the workspace with no discount applied
"""
subTotal: Float!
"""
Currency of the price
"""
currency: Currency!
items: [WorkspaceCostItem!]!
"""
Discount applied to the total
"""
discount: WorkspaceCostDiscount
"""
Total cost with discount applied
"""
total: Float!
}

type WorkspaceBilling {
versionsCount: WorkspaceVersionsCount!
cost: WorkspaceCost!
}

type Workspace {
id: ID!
name: String!
Expand Down Expand Up @@ -324,10 +270,6 @@ type Workspace {
filter: WorkspaceProjectsFilter
): ProjectCollection!
"""
Billing data for Workspaces beta
"""
billing: WorkspaceBilling @hasWorkspaceRole(role: MEMBER)
"""
Information about the workspace's SSO configuration and the current user's SSO session, if present
"""
sso: WorkspaceSso
Expand Down
1 change: 0 additions & 1 deletion packages/server/codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ generates:
ProjectAutomationsUpdatedMessage: '@/modules/automate/helpers/graphTypes#ProjectAutomationsUpdatedMessageGraphQLReturn'
UserAutomateInfo: '@/modules/automate/helpers/graphTypes#UserAutomateInfoGraphQLReturn'
Workspace: '@/modules/workspacesCore/helpers/graphTypes#WorkspaceGraphQLReturn'
WorkspaceBilling: '@/modules/workspacesCore/helpers/graphTypes#WorkspaceBillingGraphQLReturn'
WorkspaceSso: '@/modules/workspacesCore/helpers/graphTypes#WorkspaceSsoGraphQLReturn'
WorkspaceMutations: '@/modules/workspacesCore/helpers/graphTypes#WorkspaceMutationsGraphQLReturn'
WorkspaceInviteMutations: '@/modules/workspacesCore/helpers/graphTypes#WorkspaceInviteMutationsGraphQLReturn'
Expand Down
20 changes: 1 addition & 19 deletions packages/server/modules/core/graph/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CommentReplyAuthorCollectionGraphQLReturn, CommentGraphQLReturn } from
import { PendingStreamCollaboratorGraphQLReturn } from '@/modules/serverinvites/helpers/graphTypes';
import { FileUploadGraphQLReturn } from '@/modules/fileuploads/helpers/types';
import { AutomateFunctionGraphQLReturn, AutomateFunctionReleaseGraphQLReturn, AutomationGraphQLReturn, AutomationRevisionGraphQLReturn, AutomationRevisionFunctionGraphQLReturn, AutomateRunGraphQLReturn, AutomationRunTriggerGraphQLReturn, AutomationRevisionTriggerDefinitionGraphQLReturn, AutomateFunctionRunGraphQLReturn, TriggeredAutomationsStatusGraphQLReturn, ProjectAutomationMutationsGraphQLReturn, ProjectTriggeredAutomationsStatusUpdatedMessageGraphQLReturn, ProjectAutomationsUpdatedMessageGraphQLReturn, UserAutomateInfoGraphQLReturn } from '@/modules/automate/helpers/graphTypes';
import { WorkspaceGraphQLReturn, WorkspaceBillingGraphQLReturn, WorkspaceSsoGraphQLReturn, WorkspaceMutationsGraphQLReturn, WorkspaceInviteMutationsGraphQLReturn, WorkspaceProjectMutationsGraphQLReturn, PendingWorkspaceCollaboratorGraphQLReturn, WorkspaceCollaboratorGraphQLReturn, ProjectRoleGraphQLReturn } from '@/modules/workspacesCore/helpers/graphTypes';
import { WorkspaceGraphQLReturn, WorkspaceSsoGraphQLReturn, WorkspaceMutationsGraphQLReturn, WorkspaceInviteMutationsGraphQLReturn, WorkspaceProjectMutationsGraphQLReturn, PendingWorkspaceCollaboratorGraphQLReturn, WorkspaceCollaboratorGraphQLReturn, ProjectRoleGraphQLReturn } from '@/modules/workspacesCore/helpers/graphTypes';
import { WorkspaceBillingMutationsGraphQLReturn } from '@/modules/gatekeeper/helpers/graphTypes';
import { WebhookGraphQLReturn } from '@/modules/webhooks/helpers/graphTypes';
import { SmartTextEditorValueGraphQLReturn } from '@/modules/core/services/richTextEditorService';
Expand Down Expand Up @@ -4029,8 +4029,6 @@ export type Workspace = {
__typename?: 'Workspace';
/** Regions available to the workspace for project data residency */
availableRegions: Array<ServerRegionItem>;
/** Billing data for Workspaces beta */
billing?: Maybe<WorkspaceBilling>;
createdAt: Scalars['DateTime']['output'];
customerPortalUrl?: Maybe<Scalars['String']['output']>;
/** Selected fallback when `logo` not set */
Expand Down Expand Up @@ -4092,12 +4090,6 @@ export type WorkspaceTeamArgs = {
limit?: Scalars['Int']['input'];
};

export type WorkspaceBilling = {
__typename?: 'WorkspaceBilling';
cost: WorkspaceCost;
versionsCount: WorkspaceVersionsCount;
};

export type WorkspaceBillingMutations = {
__typename?: 'WorkspaceBillingMutations';
cancelCheckoutSession: Scalars['Boolean']['output'];
Expand Down Expand Up @@ -4792,7 +4784,6 @@ export type ResolversTypes = {
WebhookEventCollection: ResolverTypeWrapper<WebhookEventCollection>;
WebhookUpdateInput: WebhookUpdateInput;
Workspace: ResolverTypeWrapper<WorkspaceGraphQLReturn>;
WorkspaceBilling: ResolverTypeWrapper<WorkspaceBillingGraphQLReturn>;
WorkspaceBillingMutations: ResolverTypeWrapper<WorkspaceBillingMutationsGraphQLReturn>;
WorkspaceCollaborator: ResolverTypeWrapper<WorkspaceCollaboratorGraphQLReturn>;
WorkspaceCollaboratorCollection: ResolverTypeWrapper<Omit<WorkspaceCollaboratorCollection, 'items'> & { items: Array<ResolversTypes['WorkspaceCollaborator']> }>;
Expand Down Expand Up @@ -5053,7 +5044,6 @@ export type ResolversParentTypes = {
WebhookEventCollection: WebhookEventCollection;
WebhookUpdateInput: WebhookUpdateInput;
Workspace: WorkspaceGraphQLReturn;
WorkspaceBilling: WorkspaceBillingGraphQLReturn;
WorkspaceBillingMutations: WorkspaceBillingMutationsGraphQLReturn;
WorkspaceCollaborator: WorkspaceCollaboratorGraphQLReturn;
WorkspaceCollaboratorCollection: Omit<WorkspaceCollaboratorCollection, 'items'> & { items: Array<ResolversParentTypes['WorkspaceCollaborator']> };
Expand Down Expand Up @@ -6467,7 +6457,6 @@ export type WebhookEventCollectionResolvers<ContextType = GraphQLContext, Parent

export type WorkspaceResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['Workspace'] = ResolversParentTypes['Workspace']> = {
availableRegions?: Resolver<Array<ResolversTypes['ServerRegionItem']>, ParentType, ContextType>;
billing?: Resolver<Maybe<ResolversTypes['WorkspaceBilling']>, ParentType, ContextType>;
createdAt?: Resolver<ResolversTypes['DateTime'], ParentType, ContextType>;
customerPortalUrl?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
defaultLogoIndex?: Resolver<ResolversTypes['Int'], ParentType, ContextType>;
Expand All @@ -6493,12 +6482,6 @@ export type WorkspaceResolvers<ContextType = GraphQLContext, ParentType extends
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type WorkspaceBillingResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['WorkspaceBilling'] = ResolversParentTypes['WorkspaceBilling']> = {
cost?: Resolver<ResolversTypes['WorkspaceCost'], ParentType, ContextType>;
versionsCount?: Resolver<ResolversTypes['WorkspaceVersionsCount'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type WorkspaceBillingMutationsResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['WorkspaceBillingMutations'] = ResolversParentTypes['WorkspaceBillingMutations']> = {
cancelCheckoutSession?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<WorkspaceBillingMutationsCancelCheckoutSessionArgs, 'input'>>;
createCheckoutSession?: Resolver<ResolversTypes['CheckoutSession'], ParentType, ContextType, RequireFields<WorkspaceBillingMutationsCreateCheckoutSessionArgs, 'input'>>;
Expand Down Expand Up @@ -6763,7 +6746,6 @@ export type Resolvers<ContextType = GraphQLContext> = {
WebhookEvent?: WebhookEventResolvers<ContextType>;
WebhookEventCollection?: WebhookEventCollectionResolvers<ContextType>;
Workspace?: WorkspaceResolvers<ContextType>;
WorkspaceBilling?: WorkspaceBillingResolvers<ContextType>;
WorkspaceBillingMutations?: WorkspaceBillingMutationsResolvers<ContextType>;
WorkspaceCollaborator?: WorkspaceCollaboratorResolvers<ContextType>;
WorkspaceCollaboratorCollection?: WorkspaceCollaboratorCollectionResolvers<ContextType>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4010,8 +4010,6 @@ export type Workspace = {
__typename?: 'Workspace';
/** Regions available to the workspace for project data residency */
availableRegions: Array<ServerRegionItem>;
/** Billing data for Workspaces beta */
billing?: Maybe<WorkspaceBilling>;
createdAt: Scalars['DateTime']['output'];
customerPortalUrl?: Maybe<Scalars['String']['output']>;
/** Selected fallback when `logo` not set */
Expand Down Expand Up @@ -4073,12 +4071,6 @@ export type WorkspaceTeamArgs = {
limit?: Scalars['Int']['input'];
};

export type WorkspaceBilling = {
__typename?: 'WorkspaceBilling';
cost: WorkspaceCost;
versionsCount: WorkspaceVersionsCount;
};

export type WorkspaceBillingMutations = {
__typename?: 'WorkspaceBillingMutations';
cancelCheckoutSession: Scalars['Boolean']['output'];
Expand Down
1 change: 0 additions & 1 deletion packages/server/modules/gatekeeper/domain/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
export const WORKSPACE_MAX_PROJECTS_VERSIONS = 500
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
deleteInviteFactory as deleteInviteFromDbFactory,
queryAllUserResourceInvitesFactory,
queryAllResourceInvitesFactory,
markInviteUpdatedfactory,
markInviteUpdatedFactory,
deleteServerOnlyInvitesFactory,
updateAllInviteTargetsFactory
} from '@/modules/serverinvites/repositories/serverInvites'
Expand Down Expand Up @@ -384,7 +384,7 @@ export = {
}),
findUserByTarget: findUserByTargetFactory({ db }),
findInvite: findInviteFactory({ db }),
markInviteUpdated: markInviteUpdatedfactory({ db }),
markInviteUpdated: markInviteUpdatedFactory({ db }),
getUser,
getServerInfo
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ export const findInviteByTokenFactory =
return (await q) || null
}

export const markInviteUpdatedfactory =
export const markInviteUpdatedFactory =
({ db }: { db: Knex }): MarkInviteUpdated =>
async ({ inviteId }) => {
const cols = ServerInvites.with({ withoutTablePrefix: true }).col
Expand Down
4 changes: 0 additions & 4 deletions packages/server/modules/workspaces/domain/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,6 @@ export type EmitWorkspaceEvent = <TEvent extends WorkspaceEvents>(args: {
payload: EventBusPayloads[TEvent]
}) => Promise<void>

export type CountProjectsVersionsByWorkspaceId = (args: {
workspaceId: string
}) => Promise<number>

export type CountWorkspaceRoleWithOptionalProjectRole = (args: {
workspaceId: string
workspaceRole: WorkspaceRoles
Expand Down
6 changes: 6 additions & 0 deletions packages/server/modules/workspaces/errors/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,9 @@ export class WorkspaceDomainsInvalidState extends BaseError {
static code = 'WORKSPACE_NO_VERIFIED_DOMAINS'
static statusCode = 500
}

export class WorkspacePaidPlanActiveError extends BaseError {
static defaultMessage = 'Workspace has an active paid plan, cancel it first'
static code = 'WORKSPACE_PAID_PLAN_ACTIVE'
static statusCode = 400
}
Loading

0 comments on commit e30b8c8

Please sign in to comment.