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

5187 delete all emails and events from a blocklisted domain name #5190

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,25 @@ export class CalendarChannelEventAssociationRepository {
const dataSourceSchema =
this.workspaceDataSourceService.getSchemaName(workspaceId);

const isHandleDomain = calendarEventParticipantHandle.startsWith('@');

await this.workspaceDataSourceService.executeRawQuery(
`DELETE FROM ${dataSourceSchema}."calendarChannelEventAssociation"
WHERE "id" IN (
SELECT "calendarChannelEventAssociation"."id"
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,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
Loading