Skip to content

Commit

Permalink
chore(server): move workspace leave resolver (#2670)
Browse files Browse the repository at this point in the history
* chore(server): move workspace leave resolver

* workspacesCore fix
  • Loading branch information
fabis94 authored Aug 16, 2024
1 parent 6d6d37b commit 301da42
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type WorkspaceMutations {
update(input: WorkspaceUpdateInput!): Workspace! @hasScope(scope: "workspace:update")
updateRole(input: WorkspaceRoleUpdateInput!): Workspace!
@hasScope(scope: "workspace:update")
leave(id: ID!): Boolean!
invites: WorkspaceInviteMutations!
}

Expand Down Expand Up @@ -260,11 +261,3 @@ extend type AdminQueries {
input UserWorkspacesFilter {
search: String
}

type UserWorkspaceMutations {
leave(id: ID!): Boolean!
}

extend type ActiveUserMutations {
workspaceMutations: UserWorkspaceMutations
}
27 changes: 7 additions & 20 deletions packages/server/modules/core/graph/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export type ActiveUserMutations = {
finishOnboarding: Scalars['Boolean']['output'];
/** Edit a user's profile */
update: User;
workspaceMutations?: Maybe<UserWorkspaceMutations>;
};


Expand Down Expand Up @@ -3592,16 +3591,6 @@ export type UserUpdateInput = {
name?: InputMaybe<Scalars['String']['input']>;
};

export type UserWorkspaceMutations = {
__typename?: 'UserWorkspaceMutations';
leave: Scalars['Boolean']['output'];
};


export type UserWorkspaceMutationsLeaveArgs = {
id: Scalars['ID']['input'];
};

export type UserWorkspacesFilter = {
search?: InputMaybe<Scalars['String']['input']>;
};
Expand Down Expand Up @@ -3923,6 +3912,7 @@ export type WorkspaceMutations = {
create: Workspace;
delete: Scalars['Boolean']['output'];
invites: WorkspaceInviteMutations;
leave: Scalars['Boolean']['output'];
update: Workspace;
updateRole: Workspace;
};
Expand All @@ -3938,6 +3928,11 @@ export type WorkspaceMutationsDeleteArgs = {
};


export type WorkspaceMutationsLeaveArgs = {
id: Scalars['ID']['input'];
};


export type WorkspaceMutationsUpdateArgs = {
input: WorkspaceUpdateInput;
};
Expand Down Expand Up @@ -4277,7 +4272,6 @@ export type ResolversTypes = {
UserRoleInput: UserRoleInput;
UserSearchResultCollection: ResolverTypeWrapper<Omit<UserSearchResultCollection, 'items'> & { items: Array<ResolversTypes['LimitedUser']> }>;
UserUpdateInput: UserUpdateInput;
UserWorkspaceMutations: ResolverTypeWrapper<MutationsObjectGraphQLReturn>;
UserWorkspacesFilter: UserWorkspacesFilter;
Version: ResolverTypeWrapper<VersionGraphQLReturn>;
VersionCollection: ResolverTypeWrapper<Omit<VersionCollection, 'items'> & { items: Array<ResolversTypes['Version']> }>;
Expand Down Expand Up @@ -4504,7 +4498,6 @@ export type ResolversParentTypes = {
UserRoleInput: UserRoleInput;
UserSearchResultCollection: Omit<UserSearchResultCollection, 'items'> & { items: Array<ResolversParentTypes['LimitedUser']> };
UserUpdateInput: UserUpdateInput;
UserWorkspaceMutations: MutationsObjectGraphQLReturn;
UserWorkspacesFilter: UserWorkspacesFilter;
Version: VersionGraphQLReturn;
VersionCollection: Omit<VersionCollection, 'items'> & { items: Array<ResolversParentTypes['Version']> };
Expand Down Expand Up @@ -4577,7 +4570,6 @@ export type ActiveUserMutationsResolvers<ContextType = GraphQLContext, ParentTyp
emailMutations?: Resolver<ResolversTypes['UserEmailMutations'], ParentType, ContextType>;
finishOnboarding?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType>;
update?: Resolver<ResolversTypes['User'], ParentType, ContextType, RequireFields<ActiveUserMutationsUpdateArgs, 'user'>>;
workspaceMutations?: Resolver<Maybe<ResolversTypes['UserWorkspaceMutations']>, ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

Expand Down Expand Up @@ -5747,11 +5739,6 @@ export type UserSearchResultCollectionResolvers<ContextType = GraphQLContext, Pa
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type UserWorkspaceMutationsResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['UserWorkspaceMutations'] = ResolversParentTypes['UserWorkspaceMutations']> = {
leave?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<UserWorkspaceMutationsLeaveArgs, 'id'>>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type VersionResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['Version'] = ResolversParentTypes['Version']> = {
authorUser?: Resolver<Maybe<ResolversTypes['LimitedUser']>, ParentType, ContextType>;
automationsStatus?: Resolver<Maybe<ResolversTypes['TriggeredAutomationsStatus']>, ParentType, ContextType>;
Expand Down Expand Up @@ -5899,6 +5886,7 @@ export type WorkspaceMutationsResolvers<ContextType = GraphQLContext, ParentType
create?: Resolver<ResolversTypes['Workspace'], ParentType, ContextType, RequireFields<WorkspaceMutationsCreateArgs, 'input'>>;
delete?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<WorkspaceMutationsDeleteArgs, 'workspaceId'>>;
invites?: Resolver<ResolversTypes['WorkspaceInviteMutations'], ParentType, ContextType>;
leave?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<WorkspaceMutationsLeaveArgs, 'id'>>;
update?: Resolver<ResolversTypes['Workspace'], ParentType, ContextType, RequireFields<WorkspaceMutationsUpdateArgs, 'input'>>;
updateRole?: Resolver<ResolversTypes['Workspace'], ParentType, ContextType, RequireFields<WorkspaceMutationsUpdateRoleArgs, 'input'>>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
Expand Down Expand Up @@ -6018,7 +6006,6 @@ export type Resolvers<ContextType = GraphQLContext> = {
UserEmailMutations?: UserEmailMutationsResolvers<ContextType>;
UserProjectsUpdatedMessage?: UserProjectsUpdatedMessageResolvers<ContextType>;
UserSearchResultCollection?: UserSearchResultCollectionResolvers<ContextType>;
UserWorkspaceMutations?: UserWorkspaceMutationsResolvers<ContextType>;
Version?: VersionResolvers<ContextType>;
VersionCollection?: VersionCollectionResolvers<ContextType>;
VersionCreatedTrigger?: VersionCreatedTriggerResolvers<ContextType>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export type ActiveUserMutations = {
finishOnboarding: Scalars['Boolean']['output'];
/** Edit a user's profile */
update: User;
workspaceMutations?: Maybe<UserWorkspaceMutations>;
};


Expand Down Expand Up @@ -3581,16 +3580,6 @@ export type UserUpdateInput = {
name?: InputMaybe<Scalars['String']['input']>;
};

export type UserWorkspaceMutations = {
__typename?: 'UserWorkspaceMutations';
leave: Scalars['Boolean']['output'];
};


export type UserWorkspaceMutationsLeaveArgs = {
id: Scalars['ID']['input'];
};

export type UserWorkspacesFilter = {
search?: InputMaybe<Scalars['String']['input']>;
};
Expand Down Expand Up @@ -3912,6 +3901,7 @@ export type WorkspaceMutations = {
create: Workspace;
delete: Scalars['Boolean']['output'];
invites: WorkspaceInviteMutations;
leave: Scalars['Boolean']['output'];
update: Workspace;
updateRole: Workspace;
};
Expand All @@ -3927,6 +3917,11 @@ export type WorkspaceMutationsDeleteArgs = {
};


export type WorkspaceMutationsLeaveArgs = {
id: Scalars['ID']['input'];
};


export type WorkspaceMutationsUpdateArgs = {
input: WorkspaceUpdateInput;
};
Expand Down
41 changes: 18 additions & 23 deletions packages/server/modules/workspaces/graph/resolvers/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,24 @@ export = FF_WORKSPACES_MODULE_ENABLED

return await getWorkspaceFactory({ db })({ workspaceId })
},
leave: async (_parent, args, ctx) => {
const userId = ctx.userId!

const getWorkspaceRoles = getWorkspaceRolesFactory({ db })
const emitWorkspaceEvent = getEventBus().emit

const deleteWorkspaceRole = deleteWorkspaceRoleFactory({
deleteWorkspaceRole: repoDeleteWorkspaceRoleFactory({ db }),
getWorkspaceRoles,
emitWorkspaceEvent,
getStreams,
revokeStreamPermissions
})

await deleteWorkspaceRole({ workspaceId: args.id, userId })

return true
},
invites: () => ({})
},
WorkspaceInviteMutations: {
Expand Down Expand Up @@ -540,29 +558,6 @@ export = FF_WORKSPACES_MODULE_ENABLED
workspaceList: async () => {
throw new WorkspacesNotYetImplementedError()
}
},
ActiveUserMutations: {
workspaceMutations: () => ({})
},
UserWorkspaceMutations: {
leave: async (parent, args, ctx) => {
const userId = ctx.userId!

const getWorkspaceRoles = getWorkspaceRolesFactory({ db })
const emitWorkspaceEvent = getEventBus().emit

const deleteWorkspaceRole = deleteWorkspaceRoleFactory({
deleteWorkspaceRole: repoDeleteWorkspaceRoleFactory({ db }),
getWorkspaceRoles,
emitWorkspaceEvent,
getStreams,
revokeStreamPermissions
})

await deleteWorkspaceRole({ workspaceId: args.id, userId })

return true
}
}
} as Resolvers)
: {}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export = !FF_WORKSPACES_MODULE_ENABLED
updateRole: async () => {
throw new WorkspacesModuleDisabledError()
},
leave: async () => {
throw new WorkspacesModuleDisabledError()
},
invites: () => ({})
},
WorkspaceInviteMutations: {
Expand Down Expand Up @@ -71,11 +74,6 @@ export = !FF_WORKSPACES_MODULE_ENABLED
workspaceList: async () => {
throw new WorkspacesModuleDisabledError()
}
},
ActiveUserMutations: {
workspaceMutations: async () => {
throw new WorkspacesModuleDisabledError()
}
}
} as Resolvers)
: {}
Loading

0 comments on commit 301da42

Please sign in to comment.