From 5e143f1f49cd731de00b4e28248d5e4625fdd952 Mon Sep 17 00:00:00 2001 From: bosiraphael <71827178+bosiraphael@users.noreply.github.com> Date: Fri, 26 Apr 2024 18:24:02 +0200 Subject: [PATCH] 5187 delete all emails and events from a blocklisted domain name (#5190) Closes #5187 --- ...alendar-channel-event-association.repository.ts | 13 +++++++++++-- ...ssage-channel-message-association.repository.ts | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/twenty-server/src/modules/calendar/repositories/calendar-channel-event-association.repository.ts b/packages/twenty-server/src/modules/calendar/repositories/calendar-channel-event-association.repository.ts index 3e85d4de4d..8944e7910e 100644 --- a/packages/twenty-server/src/modules/calendar/repositories/calendar-channel-event-association.repository.ts +++ b/packages/twenty-server/src/modules/calendar/repositories/calendar-channel-event-association.repository.ts @@ -179,6 +179,8 @@ export class CalendarChannelEventAssociationRepository { const dataSourceSchema = this.workspaceDataSourceService.getSchemaName(workspaceId); + const isHandleDomain = calendarEventParticipantHandle.startsWith('@'); + await this.workspaceDataSourceService.executeRawQuery( `DELETE FROM ${dataSourceSchema}."calendarChannelEventAssociation" WHERE "id" IN ( @@ -186,9 +188,16 @@ export class CalendarChannelEventAssociationRepository { FROM ${dataSourceSchema}."calendarChannelEventAssociation" "calendarChannelEventAssociation" JOIN ${dataSourceSchema}."calendarEvent" "calendarEvent" ON "calendarChannelEventAssociation"."calendarEventId" = "calendarEvent"."id" JOIN ${dataSourceSchema}."calendarEventParticipant" "calendarEventParticipant" ON "calendarEvent"."id" = "calendarEventParticipant"."calendarEventId" - WHERE "calendarEventParticipant"."handle" = $1 AND "calendarChannelEventAssociation"."calendarChannelId" = ANY($2) + WHERE "calendarEventParticipant"."handle" ${ + isHandleDomain ? 'ILIKE' : '=' + } $1 AND "calendarChannelEventAssociation"."calendarChannelId" = ANY($2) )`, - [calendarEventParticipantHandle, calendarChannelIds], + [ + isHandleDomain + ? `%${calendarEventParticipantHandle}` + : calendarEventParticipantHandle, + calendarChannelIds, + ], workspaceId, transactionManager, ); diff --git a/packages/twenty-server/src/modules/messaging/repositories/message-channel-message-association.repository.ts b/packages/twenty-server/src/modules/messaging/repositories/message-channel-message-association.repository.ts index c99e88224e..08e8d490c4 100644 --- a/packages/twenty-server/src/modules/messaging/repositories/message-channel-message-association.repository.ts +++ b/packages/twenty-server/src/modules/messaging/repositories/message-channel-message-association.repository.ts @@ -77,14 +77,24 @@ export class MessageChannelMessageAssociationRepository { const dataSourceSchema = this.workspaceDataSourceService.getSchemaName(workspaceId); + const isHandleDomain = messageParticipantHandle.startsWith('@'); + const messageChannelMessageAssociationIdsToDelete = await this.workspaceDataSourceService.executeRawQuery( `SELECT "messageChannelMessageAssociation".id FROM ${dataSourceSchema}."messageChannelMessageAssociation" "messageChannelMessageAssociation" JOIN ${dataSourceSchema}."message" ON "messageChannelMessageAssociation"."messageId" = ${dataSourceSchema}."message"."id" JOIN ${dataSourceSchema}."messageParticipant" "messageParticipant" ON ${dataSourceSchema}."message"."id" = "messageParticipant"."messageId" - WHERE "messageParticipant"."handle" = $1 AND "messageParticipant"."role"= ANY($2) AND "messageChannelMessageAssociation"."messageChannelId" = ANY($3)`, - [messageParticipantHandle, rolesToDelete, messageChannelIds], + WHERE "messageParticipant"."handle" ${ + isHandleDomain ? 'ILIKE' : '=' + } $1 AND "messageParticipant"."role" = ANY($2) AND "messageChannelMessageAssociation"."messageChannelId" = ANY($3)`, + [ + isHandleDomain + ? `%${messageParticipantHandle}` + : messageParticipantHandle, + rolesToDelete, + messageChannelIds, + ], workspaceId, transactionManager, );