5629 update blocklist for messaging v2 (#5756)

Closes #5629 

- Add subdomain support in blocklist (if @example.com is blocked, every
subdomain will be blocked)
This commit is contained in:
bosiraphael
2024-06-13 07:53:28 +02:00
committed by GitHub
parent 374237a988
commit f825bea071
11 changed files with 165 additions and 113 deletions

View File

@ -67,9 +67,9 @@ export class MessageChannelMessageAssociationRepository {
);
}
public async deleteByMessageParticipantHandleAndMessageChannelIdsAndRoles(
public async deleteByMessageParticipantHandleAndMessageChannelIdAndRoles(
messageParticipantHandle: string,
messageChannelIds: string[],
messageChannelId: string,
rolesToDelete: ('from' | 'to' | 'cc' | 'bcc')[],
workspaceId: string,
transactionManager?: EntityManager,
@ -79,21 +79,35 @@ export class MessageChannelMessageAssociationRepository {
const isHandleDomain = messageParticipantHandle.startsWith('@');
const messageChannel =
await this.workspaceDataSourceService.executeRawQuery(
`SELECT * FROM ${dataSourceSchema}."messageChannel"
WHERE "id" = $1`,
[messageChannelId],
workspaceId,
transactionManager,
);
const messageChannelHandle = messageChannel[0].handle;
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" ${
isHandleDomain ? 'ILIKE' : '='
} $1 AND "messageParticipant"."role" = ANY($2) AND "messageChannelMessageAssociation"."messageChannelId" = ANY($3)`,
WHERE "messageParticipant"."handle" != $1
AND "messageParticipant"."handle" ${isHandleDomain ? '~*' : '='} $2
AND "messageParticipant"."role" = ANY($3)
AND "messageChannelMessageAssociation"."messageChannelId" = $4`,
[
messageChannelHandle,
isHandleDomain
? `%${messageParticipantHandle}`
? // eslint-disable-next-line no-useless-escape
`.+@(.+\.)?${messageParticipantHandle.slice(1)}`
: messageParticipantHandle,
rolesToDelete,
messageChannelIds,
messageChannelId,
],
workspaceId,
transactionManager,