Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(workspaces): list workspace join requests for admin #3811

Merged
merged 13 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/server/assets/workspacesCore/typedefs/workspaces.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,17 @@ type Workspace {
Info about the workspace creation state
"""
creationState: WorkspaceCreationState
"""
Get all join requests for all the workspaces the user is an admin of
"""
adminWorkspacesJoinRequests(
filter: AdminWorkspaceJoinRequestFilter
cursor: String
limit: Int! = 25
): WorkspaceJoinRequestCollection!
@hasServerRole(role: SERVER_USER)
@hasScope(scope: "workspace:read")
@hasWorkspaceRole(role: ADMIN)
}

type WorkspaceCreationState {
Expand Down Expand Up @@ -450,6 +461,29 @@ type WorkspaceCollection {
items: [Workspace!]!
}

type WorkspaceJoinRequestCollection {
totalCount: Int!
cursor: String
items: [WorkspaceJoinRequest!]!
}

type WorkspaceJoinRequest {
workspace: Workspace!
user: LimitedUser!
status: WorkspaceJoinRequestStatus!
createdAt: DateTime!
}

enum WorkspaceJoinRequestStatus {
pending
accepted
denied
}

input AdminWorkspaceJoinRequestFilter {
status: WorkspaceJoinRequestStatus
}

extend type User {
"""
Get discoverable workspaces with verified domains that match the active user's
Expand Down
1 change: 1 addition & 0 deletions packages/server/codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ generates:
WorkspaceBillingMutations: '@/modules/gatekeeper/helpers/graphTypes#WorkspaceBillingMutationsGraphQLReturn'
PendingWorkspaceCollaborator: '@/modules/workspacesCore/helpers/graphTypes#PendingWorkspaceCollaboratorGraphQLReturn'
WorkspaceCollaborator: '@/modules/workspacesCore/helpers/graphTypes#WorkspaceCollaboratorGraphQLReturn'
WorkspaceJoinRequest: '@/modules/workspacesCore/helpers/graphTypes#WorkspaceJoinRequestGraphQLReturn'
Webhook: '@/modules/webhooks/helpers/graphTypes#WebhookGraphQLReturn'
SmartTextEditorValue: '@/modules/core/services/richTextEditorService#SmartTextEditorValueGraphQLReturn'
BlobMetadata: '@/modules/blobstorage/domain/types#BlobStorageItem'
Expand Down
61 changes: 60 additions & 1 deletion 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, WorkspaceSsoGraphQLReturn, WorkspaceMutationsGraphQLReturn, WorkspaceInviteMutationsGraphQLReturn, WorkspaceProjectMutationsGraphQLReturn, PendingWorkspaceCollaboratorGraphQLReturn, WorkspaceCollaboratorGraphQLReturn, ProjectRoleGraphQLReturn } from '@/modules/workspacesCore/helpers/graphTypes';
import { WorkspaceGraphQLReturn, WorkspaceSsoGraphQLReturn, WorkspaceMutationsGraphQLReturn, WorkspaceInviteMutationsGraphQLReturn, WorkspaceProjectMutationsGraphQLReturn, PendingWorkspaceCollaboratorGraphQLReturn, WorkspaceCollaboratorGraphQLReturn, WorkspaceJoinRequestGraphQLReturn, 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 @@ -176,6 +176,10 @@ export type AdminUsersListItem = {
registeredUser?: Maybe<User>;
};

export type AdminWorkspaceJoinRequestFilter = {
status?: InputMaybe<WorkspaceJoinRequestStatus>;
};

export type ApiToken = {
__typename?: 'ApiToken';
createdAt: Scalars['DateTime']['output'];
Expand Down Expand Up @@ -4168,6 +4172,8 @@ export type WebhookUpdateInput = {

export type Workspace = {
__typename?: 'Workspace';
/** Get all join requests for all the workspaces the user is an admin of */
adminWorkspacesJoinRequests: WorkspaceJoinRequestCollection;
automateFunctions: AutomateFunctionCollection;
createdAt: Scalars['DateTime']['output'];
/** Info about the workspace creation state */
Expand Down Expand Up @@ -4211,6 +4217,13 @@ export type Workspace = {
};


export type WorkspaceAdminWorkspacesJoinRequestsArgs = {
cursor?: InputMaybe<Scalars['String']['input']>;
filter?: InputMaybe<AdminWorkspaceJoinRequestFilter>;
limit?: Scalars['Int']['input'];
};


export type WorkspaceAutomateFunctionsArgs = {
cursor?: InputMaybe<Scalars['String']['input']>;
filter?: InputMaybe<AutomateFunctionsFilter>;
Expand Down Expand Up @@ -4396,6 +4409,27 @@ export type WorkspaceInviteUseInput = {
token: Scalars['String']['input'];
};

export type WorkspaceJoinRequest = {
__typename?: 'WorkspaceJoinRequest';
createdAt: Scalars['DateTime']['output'];
status: WorkspaceJoinRequestStatus;
user: LimitedUser;
workspace: Workspace;
};

export type WorkspaceJoinRequestCollection = {
__typename?: 'WorkspaceJoinRequestCollection';
cursor?: Maybe<Scalars['String']['output']>;
items: Array<WorkspaceJoinRequest>;
totalCount: Scalars['Int']['output'];
};

export enum WorkspaceJoinRequestStatus {
Accepted = 'accepted',
Denied = 'denied',
Pending = 'pending'
}

export type WorkspaceMutations = {
__typename?: 'WorkspaceMutations';
addDomain: Workspace;
Expand Down Expand Up @@ -4742,6 +4776,7 @@ export type ResolversTypes = {
AdminUserListItem: ResolverTypeWrapper<AdminUserListItem>;
AdminUsersListCollection: ResolverTypeWrapper<Omit<AdminUsersListCollection, 'items'> & { items: Array<ResolversTypes['AdminUsersListItem']> }>;
AdminUsersListItem: ResolverTypeWrapper<Omit<AdminUsersListItem, 'invitedUser' | 'registeredUser'> & { invitedUser?: Maybe<ResolversTypes['ServerInvite']>, registeredUser?: Maybe<ResolversTypes['User']> }>;
AdminWorkspaceJoinRequestFilter: AdminWorkspaceJoinRequestFilter;
ApiToken: ResolverTypeWrapper<ApiToken>;
ApiTokenCreateInput: ApiTokenCreateInput;
AppAuthor: ResolverTypeWrapper<AppAuthor>;
Expand Down Expand Up @@ -5002,6 +5037,9 @@ export type ResolversTypes = {
WorkspaceInviteMutations: ResolverTypeWrapper<WorkspaceInviteMutationsGraphQLReturn>;
WorkspaceInviteResendInput: WorkspaceInviteResendInput;
WorkspaceInviteUseInput: WorkspaceInviteUseInput;
WorkspaceJoinRequest: ResolverTypeWrapper<WorkspaceJoinRequestGraphQLReturn>;
WorkspaceJoinRequestCollection: ResolverTypeWrapper<Omit<WorkspaceJoinRequestCollection, 'items'> & { items: Array<ResolversTypes['WorkspaceJoinRequest']> }>;
WorkspaceJoinRequestStatus: WorkspaceJoinRequestStatus;
WorkspaceMutations: ResolverTypeWrapper<WorkspaceMutationsGraphQLReturn>;
WorkspacePlan: ResolverTypeWrapper<WorkspacePlan>;
WorkspacePlanStatuses: WorkspacePlanStatuses;
Expand Down Expand Up @@ -5040,6 +5078,7 @@ export type ResolversParentTypes = {
AdminUserListItem: AdminUserListItem;
AdminUsersListCollection: Omit<AdminUsersListCollection, 'items'> & { items: Array<ResolversParentTypes['AdminUsersListItem']> };
AdminUsersListItem: Omit<AdminUsersListItem, 'invitedUser' | 'registeredUser'> & { invitedUser?: Maybe<ResolversParentTypes['ServerInvite']>, registeredUser?: Maybe<ResolversParentTypes['User']> };
AdminWorkspaceJoinRequestFilter: AdminWorkspaceJoinRequestFilter;
ApiToken: ApiToken;
ApiTokenCreateInput: ApiTokenCreateInput;
AppAuthor: AppAuthor;
Expand Down Expand Up @@ -5275,6 +5314,8 @@ export type ResolversParentTypes = {
WorkspaceInviteMutations: WorkspaceInviteMutationsGraphQLReturn;
WorkspaceInviteResendInput: WorkspaceInviteResendInput;
WorkspaceInviteUseInput: WorkspaceInviteUseInput;
WorkspaceJoinRequest: WorkspaceJoinRequestGraphQLReturn;
WorkspaceJoinRequestCollection: Omit<WorkspaceJoinRequestCollection, 'items'> & { items: Array<ResolversParentTypes['WorkspaceJoinRequest']> };
WorkspaceMutations: WorkspaceMutationsGraphQLReturn;
WorkspacePlan: WorkspacePlan;
WorkspaceProjectCreateInput: WorkspaceProjectCreateInput;
Expand Down Expand Up @@ -6719,6 +6760,7 @@ export type WebhookEventCollectionResolvers<ContextType = GraphQLContext, Parent
};

export type WorkspaceResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['Workspace'] = ResolversParentTypes['Workspace']> = {
adminWorkspacesJoinRequests?: Resolver<ResolversTypes['WorkspaceJoinRequestCollection'], ParentType, ContextType, RequireFields<WorkspaceAdminWorkspacesJoinRequestsArgs, 'limit'>>;
automateFunctions?: Resolver<ResolversTypes['AutomateFunctionCollection'], ParentType, ContextType, RequireFields<WorkspaceAutomateFunctionsArgs, 'limit'>>;
createdAt?: Resolver<ResolversTypes['DateTime'], ParentType, ContextType>;
creationState?: Resolver<Maybe<ResolversTypes['WorkspaceCreationState']>, ParentType, ContextType>;
Expand Down Expand Up @@ -6797,6 +6839,21 @@ export type WorkspaceInviteMutationsResolvers<ContextType = GraphQLContext, Pare
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type WorkspaceJoinRequestResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['WorkspaceJoinRequest'] = ResolversParentTypes['WorkspaceJoinRequest']> = {
createdAt?: Resolver<ResolversTypes['DateTime'], ParentType, ContextType>;
status?: Resolver<ResolversTypes['WorkspaceJoinRequestStatus'], ParentType, ContextType>;
user?: Resolver<ResolversTypes['LimitedUser'], ParentType, ContextType>;
workspace?: Resolver<ResolversTypes['Workspace'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type WorkspaceJoinRequestCollectionResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['WorkspaceJoinRequestCollection'] = ResolversParentTypes['WorkspaceJoinRequestCollection']> = {
cursor?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
items?: Resolver<Array<ResolversTypes['WorkspaceJoinRequest']>, ParentType, ContextType>;
totalCount?: Resolver<ResolversTypes['Int'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type WorkspaceMutationsResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['WorkspaceMutations'] = ResolversParentTypes['WorkspaceMutations']> = {
addDomain?: Resolver<ResolversTypes['Workspace'], ParentType, ContextType, RequireFields<WorkspaceMutationsAddDomainArgs, 'input'>>;
billing?: Resolver<ResolversTypes['WorkspaceBillingMutations'], ParentType, ContextType>;
Expand Down Expand Up @@ -7026,6 +7083,8 @@ export type Resolvers<ContextType = GraphQLContext> = {
WorkspaceCreationState?: WorkspaceCreationStateResolvers<ContextType>;
WorkspaceDomain?: WorkspaceDomainResolvers<ContextType>;
WorkspaceInviteMutations?: WorkspaceInviteMutationsResolvers<ContextType>;
WorkspaceJoinRequest?: WorkspaceJoinRequestResolvers<ContextType>;
WorkspaceJoinRequestCollection?: WorkspaceJoinRequestCollectionResolvers<ContextType>;
WorkspaceMutations?: WorkspaceMutationsResolvers<ContextType>;
WorkspacePlan?: WorkspacePlanResolvers<ContextType>;
WorkspaceProjectMutations?: WorkspaceProjectMutationsResolvers<ContextType>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ export type AdminUsersListItem = {
registeredUser?: Maybe<User>;
};

export type AdminWorkspaceJoinRequestFilter = {
status?: InputMaybe<WorkspaceJoinRequestStatus>;
};

export type ApiToken = {
__typename?: 'ApiToken';
createdAt: Scalars['DateTime']['output'];
Expand Down Expand Up @@ -4149,6 +4153,8 @@ export type WebhookUpdateInput = {

export type Workspace = {
__typename?: 'Workspace';
/** Get all join requests for all the workspaces the user is an admin of */
adminWorkspacesJoinRequests: WorkspaceJoinRequestCollection;
automateFunctions: AutomateFunctionCollection;
createdAt: Scalars['DateTime']['output'];
/** Info about the workspace creation state */
Expand Down Expand Up @@ -4192,6 +4198,13 @@ export type Workspace = {
};


export type WorkspaceAdminWorkspacesJoinRequestsArgs = {
cursor?: InputMaybe<Scalars['String']['input']>;
filter?: InputMaybe<AdminWorkspaceJoinRequestFilter>;
limit?: Scalars['Int']['input'];
};


export type WorkspaceAutomateFunctionsArgs = {
cursor?: InputMaybe<Scalars['String']['input']>;
filter?: InputMaybe<AutomateFunctionsFilter>;
Expand Down Expand Up @@ -4377,6 +4390,27 @@ export type WorkspaceInviteUseInput = {
token: Scalars['String']['input'];
};

export type WorkspaceJoinRequest = {
__typename?: 'WorkspaceJoinRequest';
createdAt: Scalars['DateTime']['output'];
status: WorkspaceJoinRequestStatus;
user: LimitedUser;
workspace: Workspace;
};

export type WorkspaceJoinRequestCollection = {
__typename?: 'WorkspaceJoinRequestCollection';
cursor?: Maybe<Scalars['String']['output']>;
items: Array<WorkspaceJoinRequest>;
totalCount: Scalars['Int']['output'];
};

export enum WorkspaceJoinRequestStatus {
Accepted = 'accepted',
Denied = 'denied',
Pending = 'pending'
}

export type WorkspaceMutations = {
__typename?: 'WorkspaceMutations';
addDomain: Workspace;
Expand Down
2 changes: 1 addition & 1 deletion packages/server/modules/shared/services/paginatedItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getPaginatedItemsFactory =
getTotalCount
}: {
getItems: (args: TArgs) => Promise<T[]>
getTotalCount: (args: TArgs) => Promise<number>
getTotalCount: (args: Omit<TArgs, 'cursor' | 'limit'>) => Promise<number>
}) =>
async (args: TArgs): Promise<Collection<T>> => {
const maybeDecodedCursor = args.cursor ? decodeIsoDateCursor(args.cursor) : null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { db } from '@/db/knex'
import { Resolvers } from '@/modules/core/graph/generated/graphql'
import { getPaginatedItemsFactory } from '@/modules/shared/services/paginatedItems'
import {
countAdminWorkspaceJoinRequestsFactory,
getAdminWorkspaceJoinRequestsFactory
} from '@/modules/workspaces/repositories/workspaceJoinRequests'
import { WorkspaceJoinRequestStatus } from '@/modules/workspacesCore/domain/types'
import { WorkspaceJoinRequestGraphQLReturn } from '@/modules/workspacesCore/helpers/graphTypes'

export default {
Workspace: {
adminWorkspacesJoinRequests: async (parent, args, ctx) => {
const { filter, cursor, limit } = args

return await getPaginatedItemsFactory<
{
limit: number
cursor?: string
filter: {
workspaceId: string
userId: string
status?: WorkspaceJoinRequestStatus | null
}
},
WorkspaceJoinRequestGraphQLReturn
>({
getItems: getAdminWorkspaceJoinRequestsFactory({ db }),
getTotalCount: countAdminWorkspaceJoinRequestsFactory({ db })
})({
filter: {
workspaceId: parent.id,
status: filter?.status ?? undefined,
userId: ctx.userId! // This is the worskpace admin, not the request userId
},
cursor: cursor ?? undefined,
limit
})
}
},
WorkspaceJoinRequest: {
user: async (parent, _args, ctx) => {
return await ctx.loaders.users.getUser.load(parent.userId)
},
workspace: async (parent, _args, ctx) => {
return await ctx.loaders.workspaces!.getWorkspace.load(parent.workspaceId)
}
}
} as Resolvers
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import {
CreateWorkspaceJoinRequest,
UpdateWorkspaceJoinRequestStatus
} from '@/modules/workspaces/domain/operations'
import { WorkspaceJoinRequest } from '@/modules/workspacesCore/domain/types'
import { WorkspaceJoinRequests } from '@/modules/workspacesCore/helpers/db'
import {
WorkspaceJoinRequest,
WorkspaceJoinRequestStatus
} from '@/modules/workspacesCore/domain/types'
import {
WorkspaceAcl,
WorkspaceJoinRequests
} from '@/modules/workspacesCore/helpers/db'
import { Roles } from '@speckle/shared'
import { Knex } from 'knex'

const tables = {
Expand All @@ -27,3 +34,56 @@ export const updateWorkspaceJoinRequestStatusFactory =
.onConflict(['workspaceId', 'userId'])
.merge(['status'])
}

type WorkspaceJoinRequestFilter = {
workspaceId: string
status?: WorkspaceJoinRequestStatus | null
userId: string
}

const adminWorkspaceJoinRequestsBaseQueryFactory =
(db: Knex) => (filter: WorkspaceJoinRequestFilter) => {
const query = tables
.workspaceJoinRequests(db)
.innerJoin(
WorkspaceAcl.name,
WorkspaceAcl.col.workspaceId,
WorkspaceJoinRequests.col.workspaceId
)
.where(WorkspaceAcl.col.role, Roles.Workspace.Admin)
.where(WorkspaceAcl.col.userId, filter.userId)
.where(WorkspaceJoinRequests.col.workspaceId, filter.workspaceId)
if (filter.status) query.andWhere(WorkspaceJoinRequests.col.status, filter.status)
return query
}

export const getAdminWorkspaceJoinRequestsFactory =
({ db }: { db: Knex }) =>
async ({
filter,
cursor,
limit
}: {
filter: WorkspaceJoinRequestFilter
cursor?: string
limit: number
}) => {
const query = adminWorkspaceJoinRequestsBaseQueryFactory(db)(filter)

if (cursor) {
query.andWhere(WorkspaceJoinRequests.col.createdAt, '<', cursor)
}
return await query
.select<WorkspaceJoinRequest[]>(WorkspaceJoinRequests.cols)
.orderBy(WorkspaceJoinRequests.col.createdAt, 'desc')
.limit(limit)
}

export const countAdminWorkspaceJoinRequestsFactory =
({ db }: { db: Knex }) =>
async ({ filter }: { filter: WorkspaceJoinRequestFilter }) => {
const query = adminWorkspaceJoinRequestsBaseQueryFactory(db)(filter)

const [res] = await query.count()
return parseInt(res.count.toString())
}
Loading