fix workspace-member deletion with existing attachments/documents (#5232)
## Context We have a non-nullable constraint on authorId in attachments and documents, until we have soft-deletion we need to handle deletion of workspace-members and their attachments/documents. This PR introduces pre-hooks to deleteOne/deleteMany This is called when a user deletes a workspace-member from the members page Next: needs to be done on user level as well. This is called when users try to delete their own accounts. I've seen other issues such as re-creating a user with a previously used email failing.
This commit is contained in:
@ -6,6 +6,8 @@ import { CalendarEventFindOnePreQueryHook } from 'src/modules/calendar/query-hoo
|
||||
import { BlocklistCreateManyPreQueryHook } from 'src/modules/connected-account/query-hooks/blocklist/blocklist-create-many.pre-query.hook';
|
||||
import { BlocklistUpdateManyPreQueryHook } from 'src/modules/connected-account/query-hooks/blocklist/blocklist-update-many.pre-query.hook';
|
||||
import { BlocklistUpdateOnePreQueryHook } from 'src/modules/connected-account/query-hooks/blocklist/blocklist-update-one.pre-query.hook';
|
||||
import { WorkspaceMemberDeleteOnePreQueryHook } from 'src/modules/workspace-member/query-hooks/workspace-member-delete-one.pre-query.hook';
|
||||
import { WorkspaceMemberDeleteManyPreQueryHook } from 'src/modules/workspace-member/query-hooks/workspace-member-delete-many.pre-query.hook';
|
||||
|
||||
// TODO: move to a decorator
|
||||
export const workspacePreQueryHooks: WorkspaceQueryHook = {
|
||||
@ -22,4 +24,8 @@ export const workspacePreQueryHooks: WorkspaceQueryHook = {
|
||||
updateMany: [BlocklistUpdateManyPreQueryHook.name],
|
||||
updateOne: [BlocklistUpdateOnePreQueryHook.name],
|
||||
},
|
||||
workspaceMember: {
|
||||
deleteOne: [WorkspaceMemberDeleteOnePreQueryHook.name],
|
||||
deleteMany: [WorkspaceMemberDeleteManyPreQueryHook.name],
|
||||
},
|
||||
};
|
||||
|
||||
@ -4,12 +4,14 @@ import { MessagingQueryHookModule } from 'src/modules/messaging/query-hooks/mess
|
||||
import { WorkspacePreQueryHookService } from 'src/engine/api/graphql/workspace-query-runner/workspace-pre-query-hook/workspace-pre-query-hook.service';
|
||||
import { CalendarQueryHookModule } from 'src/modules/calendar/query-hooks/calendar-query-hook.module';
|
||||
import { ConnectedAccountQueryHookModule } from 'src/modules/connected-account/query-hooks/connected-account-query-hook.module';
|
||||
import { WorkspaceMemberQueryHookModule } from 'src/modules/workspace-member/query-hooks/workspace-member-query-hook.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MessagingQueryHookModule,
|
||||
CalendarQueryHookModule,
|
||||
ConnectedAccountQueryHookModule,
|
||||
WorkspaceMemberQueryHookModule,
|
||||
],
|
||||
providers: [WorkspacePreQueryHookService],
|
||||
exports: [WorkspacePreQueryHookService],
|
||||
|
||||
@ -436,6 +436,14 @@ export class WorkspaceQueryRunnerService {
|
||||
atMost: maximumRecordAffected,
|
||||
});
|
||||
|
||||
await this.workspacePreQueryHookService.executePreHooks(
|
||||
userId,
|
||||
workspaceId,
|
||||
objectMetadataItem.nameSingular,
|
||||
'deleteMany',
|
||||
args,
|
||||
);
|
||||
|
||||
const result = await this.execute(query, workspaceId);
|
||||
|
||||
const parsedResults = (
|
||||
@ -495,6 +503,14 @@ export class WorkspaceQueryRunnerService {
|
||||
);
|
||||
// TODO END
|
||||
|
||||
await this.workspacePreQueryHookService.executePreHooks(
|
||||
userId,
|
||||
workspaceId,
|
||||
objectMetadataItem.nameSingular,
|
||||
'deleteOne',
|
||||
args,
|
||||
);
|
||||
|
||||
const result = await this.execute(query, workspaceId);
|
||||
|
||||
const parsedResults = (
|
||||
|
||||
Reference in New Issue
Block a user