Skip to content

Commit

Permalink
feat(workspaces): admin update workspace plan
Browse files Browse the repository at this point in the history
  • Loading branch information
gjedlicska committed Dec 11, 2024
1 parent b3317d0 commit b602bb6
Show file tree
Hide file tree
Showing 12 changed files with 263 additions and 9 deletions.
23 changes: 23 additions & 0 deletions packages/frontend-2/lib/common/generated/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ export type AdminInviteList = {
totalCount: Scalars['Int']['output'];
};

export type AdminMutations = {
__typename?: 'AdminMutations';
updateWorkspacePlan: Scalars['Boolean']['output'];
};


export type AdminMutationsUpdateWorkspacePlanArgs = {
input: AdminUpdateWorkspacePlanInput;
};

export type AdminQueries = {
__typename?: 'AdminQueries';
inviteList: AdminInviteList;
Expand Down Expand Up @@ -108,6 +118,12 @@ export type AdminQueriesWorkspaceListArgs = {
query?: InputMaybe<Scalars['String']['input']>;
};

export type AdminUpdateWorkspacePlanInput = {
plan: WorkspacePlans;
status: WorkspacePlanStatuses;
workspaceId: Scalars['ID']['input'];
};

export type AdminUserList = {
__typename?: 'AdminUserList';
cursor?: Maybe<Scalars['String']['output']>;
Expand Down Expand Up @@ -1240,6 +1256,7 @@ export type Mutation = {
_?: Maybe<Scalars['String']['output']>;
/** Various Active User oriented mutations */
activeUserMutations: ActiveUserMutations;
admin: AdminMutations;
adminDeleteUser: Scalars['Boolean']['output'];
/** Creates an personal api token. */
apiTokenCreate: Scalars['String']['output'];
Expand Down Expand Up @@ -6701,6 +6718,7 @@ export type AllObjectTypes = {
Activity: Activity,
ActivityCollection: ActivityCollection,
AdminInviteList: AdminInviteList,
AdminMutations: AdminMutations,
AdminQueries: AdminQueries,
AdminUserList: AdminUserList,
AdminUserListItem: AdminUserListItem,
Expand Down Expand Up @@ -6872,6 +6890,9 @@ export type AdminInviteListFieldArgs = {
items: {},
totalCount: {},
}
export type AdminMutationsFieldArgs = {
updateWorkspacePlan: AdminMutationsUpdateWorkspacePlanArgs,
}
export type AdminQueriesFieldArgs = {
inviteList: AdminQueriesInviteListArgs,
projectList: AdminQueriesProjectListArgs,
Expand Down Expand Up @@ -7262,6 +7283,7 @@ export type ModelsTreeItemCollectionFieldArgs = {
export type MutationFieldArgs = {
_: {},
activeUserMutations: {},
admin: {},
adminDeleteUser: MutationAdminDeleteUserArgs,
apiTokenCreate: MutationApiTokenCreateArgs,
apiTokenRevoke: MutationApiTokenRevokeArgs,
Expand Down Expand Up @@ -8071,6 +8093,7 @@ export type AllObjectFieldArgTypes = {
Activity: ActivityFieldArgs,
ActivityCollection: ActivityCollectionFieldArgs,
AdminInviteList: AdminInviteListFieldArgs,
AdminMutations: AdminMutationsFieldArgs,
AdminQueries: AdminQueriesFieldArgs,
AdminUserList: AdminUserListFieldArgs,
AdminUserListItem: AdminUserListItemFieldArgs,
Expand Down
14 changes: 14 additions & 0 deletions packages/server/assets/workspacesCore/typedefs/workspaces.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -565,3 +565,17 @@ extend type Subscription {
@hasServerRole(role: SERVER_GUEST)
@hasScope(scope: "workspace:read")
}

extend type Mutation {
admin: AdminMutations! @hasServerRole(role: SERVER_ADMIN)
}

input AdminUpdateWorkspacePlanInput {
workspaceId: ID!
plan: WorkspacePlans!
status: WorkspacePlanStatuses!
}

type AdminMutations {
updateWorkspacePlan(input: AdminUpdateWorkspacePlanInput!): Boolean!
}
1 change: 1 addition & 0 deletions packages/server/codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ generates:
VersionMutations: '@/modules/core/helpers/graphTypes#MutationsObjectGraphQLReturn'
CommentMutations: '@/modules/core/helpers/graphTypes#MutationsObjectGraphQLReturn'
AutomateMutations: '@/modules/core/helpers/graphTypes#MutationsObjectGraphQLReturn'
AdminMutations: '@/modules/core/helpers/graphTypes#MutationsObjectGraphQLReturn'
AdminQueries: '@/modules/core/helpers/graphTypes#GraphQLEmptyReturn'
ServerStatistics: '@/modules/core/helpers/graphTypes#GraphQLEmptyReturn'
ServerStats: '@/modules/core/helpers/graphTypes#GraphQLEmptyReturn'
Expand Down
28 changes: 28 additions & 0 deletions packages/server/modules/core/graph/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ export type AdminInviteList = {
totalCount: Scalars['Int']['output'];
};

export type AdminMutations = {
__typename?: 'AdminMutations';
updateWorkspacePlan: Scalars['Boolean']['output'];
};


export type AdminMutationsUpdateWorkspacePlanArgs = {
input: AdminUpdateWorkspacePlanInput;
};

export type AdminQueries = {
__typename?: 'AdminQueries';
inviteList: AdminInviteList;
Expand Down Expand Up @@ -125,6 +135,12 @@ export type AdminQueriesWorkspaceListArgs = {
query?: InputMaybe<Scalars['String']['input']>;
};

export type AdminUpdateWorkspacePlanInput = {
plan: WorkspacePlans;
status: WorkspacePlanStatuses;
workspaceId: Scalars['ID']['input'];
};

export type AdminUserList = {
__typename?: 'AdminUserList';
cursor?: Maybe<Scalars['String']['output']>;
Expand Down Expand Up @@ -1262,6 +1278,7 @@ export type Mutation = {
_?: Maybe<Scalars['String']['output']>;
/** Various Active User oriented mutations */
activeUserMutations: ActiveUserMutations;
admin: AdminMutations;
adminDeleteUser: Scalars['Boolean']['output'];
/** Creates an personal api token. */
apiTokenCreate: Scalars['String']['output'];
Expand Down Expand Up @@ -4664,7 +4681,9 @@ export type ResolversTypes = {
ActivityCollection: ResolverTypeWrapper<ActivityCollectionGraphQLReturn>;
AddDomainToWorkspaceInput: AddDomainToWorkspaceInput;
AdminInviteList: ResolverTypeWrapper<Omit<AdminInviteList, 'items'> & { items: Array<ResolversTypes['ServerInvite']> }>;
AdminMutations: ResolverTypeWrapper<MutationsObjectGraphQLReturn>;
AdminQueries: ResolverTypeWrapper<GraphQLEmptyReturn>;
AdminUpdateWorkspacePlanInput: AdminUpdateWorkspacePlanInput;
AdminUserList: ResolverTypeWrapper<AdminUserList>;
AdminUserListItem: ResolverTypeWrapper<AdminUserListItem>;
AdminUsersListCollection: ResolverTypeWrapper<Omit<AdminUsersListCollection, 'items'> & { items: Array<ResolversTypes['AdminUsersListItem']> }>;
Expand Down Expand Up @@ -4956,7 +4975,9 @@ export type ResolversParentTypes = {
ActivityCollection: ActivityCollectionGraphQLReturn;
AddDomainToWorkspaceInput: AddDomainToWorkspaceInput;
AdminInviteList: Omit<AdminInviteList, 'items'> & { items: Array<ResolversParentTypes['ServerInvite']> };
AdminMutations: MutationsObjectGraphQLReturn;
AdminQueries: GraphQLEmptyReturn;
AdminUpdateWorkspacePlanInput: AdminUpdateWorkspacePlanInput;
AdminUserList: AdminUserList;
AdminUserListItem: AdminUserListItem;
AdminUsersListCollection: Omit<AdminUsersListCollection, 'items'> & { items: Array<ResolversParentTypes['AdminUsersListItem']> };
Expand Down Expand Up @@ -5280,6 +5301,11 @@ export type AdminInviteListResolvers<ContextType = GraphQLContext, ParentType ex
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type AdminMutationsResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['AdminMutations'] = ResolversParentTypes['AdminMutations']> = {
updateWorkspacePlan?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<AdminMutationsUpdateWorkspacePlanArgs, 'input'>>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type AdminQueriesResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['AdminQueries'] = ResolversParentTypes['AdminQueries']> = {
inviteList?: Resolver<ResolversTypes['AdminInviteList'], ParentType, ContextType, RequireFields<AdminQueriesInviteListArgs, 'cursor' | 'limit' | 'query'>>;
projectList?: Resolver<ResolversTypes['ProjectCollection'], ParentType, ContextType, RequireFields<AdminQueriesProjectListArgs, 'cursor' | 'limit'>>;
Expand Down Expand Up @@ -5788,6 +5814,7 @@ export type ModelsTreeItemCollectionResolvers<ContextType = GraphQLContext, Pare
export type MutationResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['Mutation'] = ResolversParentTypes['Mutation']> = {
_?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
activeUserMutations?: Resolver<ResolversTypes['ActiveUserMutations'], ParentType, ContextType>;
admin?: Resolver<ResolversTypes['AdminMutations'], ParentType, ContextType>;
adminDeleteUser?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<MutationAdminDeleteUserArgs, 'userConfirmation'>>;
apiTokenCreate?: Resolver<ResolversTypes['String'], ParentType, ContextType, RequireFields<MutationApiTokenCreateArgs, 'token'>>;
apiTokenRevoke?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<MutationApiTokenRevokeArgs, 'token'>>;
Expand Down Expand Up @@ -6784,6 +6811,7 @@ export type Resolvers<ContextType = GraphQLContext> = {
Activity?: ActivityResolvers<ContextType>;
ActivityCollection?: ActivityCollectionResolvers<ContextType>;
AdminInviteList?: AdminInviteListResolvers<ContextType>;
AdminMutations?: AdminMutationsResolvers<ContextType>;
AdminQueries?: AdminQueriesResolvers<ContextType>;
AdminUserList?: AdminUserListResolvers<ContextType>;
AdminUserListItem?: AdminUserListItemResolvers<ContextType>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ export type AdminInviteList = {
totalCount: Scalars['Int']['output'];
};

export type AdminMutations = {
__typename?: 'AdminMutations';
updateWorkspacePlan: Scalars['Boolean']['output'];
};


export type AdminMutationsUpdateWorkspacePlanArgs = {
input: AdminUpdateWorkspacePlanInput;
};

export type AdminQueries = {
__typename?: 'AdminQueries';
inviteList: AdminInviteList;
Expand Down Expand Up @@ -106,6 +116,12 @@ export type AdminQueriesWorkspaceListArgs = {
query?: InputMaybe<Scalars['String']['input']>;
};

export type AdminUpdateWorkspacePlanInput = {
plan: WorkspacePlans;
status: WorkspacePlanStatuses;
workspaceId: Scalars['ID']['input'];
};

export type AdminUserList = {
__typename?: 'AdminUserList';
cursor?: Maybe<Scalars['String']['output']>;
Expand Down Expand Up @@ -1243,6 +1259,7 @@ export type Mutation = {
_?: Maybe<Scalars['String']['output']>;
/** Various Active User oriented mutations */
activeUserMutations: ActiveUserMutations;
admin: AdminMutations;
adminDeleteUser: Scalars['Boolean']['output'];
/** Creates an personal api token. */
apiTokenCreate: Scalars['String']['output'];
Expand Down
4 changes: 4 additions & 0 deletions packages/server/modules/gatekeeper/domain/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export type UpsertPaidWorkspacePlan = (args: {
workspacePlan: PaidWorkspacePlan
}) => Promise<void>

export type UpsertUnpaidWorkspacePlan = (args: {
workspacePlan: UnpaidWorkspacePlan
}) => Promise<void>

export type UpsertWorkspacePlan = (args: {
workspacePlan: WorkspacePlan
}) => Promise<void>
Expand Down
6 changes: 6 additions & 0 deletions packages/server/modules/gatekeeper/errors/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export class WorkspacePlanMismatchError extends BaseError {
static statusCode = 500
}

export class InvalidWorkspacePlanStatus extends BaseError {
static defaultMessage = 'Workspace plan cannot be in the specified status'
static code = 'INVALID_WORKSPACE_PLAN_STATUS'
static statusCode = 400
}

export class WorkspaceCheckoutSessionInProgressError extends BaseError {
static defaultMessage = 'Workspace already has a checkout session in progress'
static code = 'WORKSPACE_CHECKOUT_SESSION_IN_PROGRESS_ERROR'
Expand Down
9 changes: 8 additions & 1 deletion packages/server/modules/gatekeeper/repositories/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
GetWorkspaceSubscription,
GetWorkspaceSubscriptionBySubscriptionId,
GetWorkspaceSubscriptions,
UpsertTrialWorkspacePlan
UpsertTrialWorkspacePlan,
UpsertUnpaidWorkspacePlan
} from '@/modules/gatekeeper/domain/billing'
import { Knex } from 'knex'

Expand Down Expand Up @@ -61,6 +62,12 @@ export const upsertTrialWorkspacePlanFactory = ({
db: Knex
}): UpsertTrialWorkspacePlan => upsertWorkspacePlanFactory({ db })

export const upsertUnpaidWorkspacePlanFactory = ({
db
}: {
db: Knex
}): UpsertUnpaidWorkspacePlan => upsertWorkspacePlanFactory({ db })

export const saveCheckoutSessionFactory =
({ db }: { db: Knex }): SaveCheckoutSession =>
async ({ checkoutSession }) => {
Expand Down
12 changes: 12 additions & 0 deletions packages/server/modules/workspaces/domain/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ export type GetWorkspaceWithDomains = (args: {

export type DeleteWorkspace = (args: DeleteWorkspaceArgs) => Promise<void>

type CountWorkspacesArgs = {
filter?: {
search?: string
}
}
export type QueryWorkspacesArgs = CountWorkspacesArgs & {
limit: number
cursor?: string
}
export type QueryWorkspaces = (args: QueryWorkspacesArgs) => Promise<Workspace[]>
export type CountWorkspaces = (args: CountWorkspacesArgs) => Promise<number>

/** Workspace Roles */

export type GetWorkspaceCollaboratorsArgs = {
Expand Down
Loading

0 comments on commit b602bb6

Please sign in to comment.