Skip to content

Commit

Permalink
gergo/web 2428 academia should be free business (#3842)
Browse files Browse the repository at this point in the history
* feat(server): workspace shoul equal unpaid business

* feat(server): add free workspace plans

* feat(gatekeeper): rename plans to invoiced

* chore(gatekeeper): regen gql

* feat(gatekeeper): calculate workspace plan payment method

* fix(fe2): add missing workspace plans
  • Loading branch information
gjedlicska authored Jan 16, 2025
1 parent 6a54113 commit 7b295ba
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ const canUpgradeToPlan = computed(() => {
[WorkspacePlans.Plus]: [WorkspacePlans.Business],
[WorkspacePlans.Business]: [],
[WorkspacePlans.Academia]: [],
[WorkspacePlans.Unlimited]: []
[WorkspacePlans.Unlimited]: [],
[WorkspacePlans.StarterInvoiced]: [],
[WorkspacePlans.PlusInvoiced]: [],
[WorkspacePlans.BusinessInvoiced]: []
}
return allowedUpgrades[props.currentPlan.name].includes(props.plan.name)
Expand Down
3 changes: 3 additions & 0 deletions packages/frontend-2/lib/common/generated/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4481,8 +4481,11 @@ export enum WorkspacePlanStatuses {
export enum WorkspacePlans {
Academia = 'academia',
Business = 'business',
BusinessInvoiced = 'businessInvoiced',
Plus = 'plus',
PlusInvoiced = 'plusInvoiced',
Starter = 'starter',
StarterInvoiced = 'starterInvoiced',
Unlimited = 'unlimited'
}

Expand Down
7 changes: 7 additions & 0 deletions packages/server/assets/gatekeeper/typedefs/gatekeeper.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,17 @@ enum WorkspacePlanStatuses {
expired
}

enum WorkspacePaymentMethod {
unpaid
invoice
billing
}

type WorkspacePlan {
name: WorkspacePlans!
status: WorkspacePlanStatuses!
createdAt: DateTime!
paymentMethod: WorkspacePaymentMethod!
}

type WorkspaceSubscriptionSeats {
Expand Down
9 changes: 9 additions & 0 deletions packages/server/modules/core/graph/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4534,10 +4534,17 @@ export type WorkspaceMutationsUpdateRoleArgs = {
input: WorkspaceRoleUpdateInput;
};

export enum WorkspacePaymentMethod {
Billing = 'billing',
Invoice = 'invoice',
Unpaid = 'unpaid'
}

export type WorkspacePlan = {
__typename?: 'WorkspacePlan';
createdAt: Scalars['DateTime']['output'];
name: WorkspacePlans;
paymentMethod: WorkspacePaymentMethod;
status: WorkspacePlanStatuses;
};

Expand Down Expand Up @@ -5062,6 +5069,7 @@ export type ResolversTypes = {
WorkspaceJoinRequestMutations: ResolverTypeWrapper<WorkspaceJoinRequestMutationsGraphQLReturn>;
WorkspaceJoinRequestStatus: WorkspaceJoinRequestStatus;
WorkspaceMutations: ResolverTypeWrapper<WorkspaceMutationsGraphQLReturn>;
WorkspacePaymentMethod: WorkspacePaymentMethod;
WorkspacePlan: ResolverTypeWrapper<WorkspacePlan>;
WorkspacePlanStatuses: WorkspacePlanStatuses;
WorkspacePlans: WorkspacePlans;
Expand Down Expand Up @@ -6906,6 +6914,7 @@ export type WorkspaceMutationsResolvers<ContextType = GraphQLContext, ParentType
export type WorkspacePlanResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['WorkspacePlan'] = ResolversParentTypes['WorkspacePlan']> = {
createdAt?: Resolver<ResolversTypes['DateTime'], ParentType, ContextType>;
name?: Resolver<ResolversTypes['WorkspacePlans'], ParentType, ContextType>;
paymentMethod?: Resolver<ResolversTypes['WorkspacePaymentMethod'], ParentType, ContextType>;
status?: Resolver<ResolversTypes['WorkspacePlanStatuses'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4515,10 +4515,17 @@ export type WorkspaceMutationsUpdateRoleArgs = {
input: WorkspaceRoleUpdateInput;
};

export enum WorkspacePaymentMethod {
Billing = 'billing',
Invoice = 'invoice',
Unpaid = 'unpaid'
}

export type WorkspacePlan = {
__typename?: 'WorkspacePlan';
createdAt: Scalars['DateTime']['output'];
name: WorkspacePlans;
paymentMethod: WorkspacePaymentMethod;
status: WorkspacePlanStatuses;
};

Expand Down
28 changes: 26 additions & 2 deletions packages/server/modules/gatekeeper/graph/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getFeatureFlags, getFrontendOrigin } from '@/modules/shared/helpers/env
import { Resolvers } from '@/modules/core/graph/generated/graphql'
import { pricingTable } from '@/modules/gatekeeper/domain/workspacePricing'
import { authorizeResolver } from '@/modules/shared'
import { Roles } from '@speckle/shared'
import { Roles, throwUncoveredError } from '@speckle/shared'
import {
countWorkspaceRoleWithOptionalProjectRoleFactory,
getWorkspaceFactory
Expand Down Expand Up @@ -33,6 +33,7 @@ import { canWorkspaceAccessFeatureFactory } from '@/modules/gatekeeper/services/
import { upgradeWorkspaceSubscriptionFactory } from '@/modules/gatekeeper/services/subscriptions'
import { isWorkspaceReadOnlyFactory } from '@/modules/gatekeeper/services/readOnly'
import { calculateSubscriptionSeats } from '@/modules/gatekeeper/domain/billing'
import { WorkspacePaymentMethod } from '@/test/graphql/generated/graphql'

const { FF_GATEKEEPER_MODULE_ENABLED } = getFeatureFlags()

Expand All @@ -47,7 +48,30 @@ export = FF_GATEKEEPER_MODULE_ENABLED
},
Workspace: {
plan: async (parent) => {
return await getWorkspacePlanFactory({ db })({ workspaceId: parent.id })
const workspacePlan = await getWorkspacePlanFactory({ db })({
workspaceId: parent.id
})
if (!workspacePlan) return null
let paymentMethod: WorkspacePaymentMethod
switch (workspacePlan.name) {
case 'starter':
case 'plus':
case 'business':
paymentMethod = WorkspacePaymentMethod.Billing
break
case 'unlimited':
case 'academia':
paymentMethod = WorkspacePaymentMethod.Unpaid
break
case 'starterInvoiced':
case 'plusInvoiced':
case 'businessInvoiced':
paymentMethod = WorkspacePaymentMethod.Invoice
break
default:
throwUncoveredError(workspacePlan)
}
return { ...workspacePlan, paymentMethod }
},
subscription: async (parent) => {
const workspaceId = parent.id
Expand Down
7 changes: 7 additions & 0 deletions packages/server/test/graphql/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4516,10 +4516,17 @@ export type WorkspaceMutationsUpdateRoleArgs = {
input: WorkspaceRoleUpdateInput;
};

export enum WorkspacePaymentMethod {
Billing = 'billing',
Invoice = 'invoice',
Unpaid = 'unpaid'
}

export type WorkspacePlan = {
__typename?: 'WorkspacePlan';
createdAt: Scalars['DateTime']['output'];
name: WorkspacePlans;
paymentMethod: WorkspacePaymentMethod;
status: WorkspacePlanStatuses;
};

Expand Down

0 comments on commit 7b295ba

Please sign in to comment.