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

@ -124,14 +124,13 @@ export class GoogleCalendarSyncService {
const blocklist = await this.getBlocklist(workspaceMemberId, workspaceId);
let filteredEvents = filterOutBlocklistedEvents(events, blocklist).filter(
(event) => event.status !== 'cancelled',
);
let filteredEvents = filterOutBlocklistedEvents(
calendarChannel.handle,
events,
blocklist,
).filter((event) => event.status !== 'cancelled');
if (emailOrDomainToReimport) {
// We still need to filter the events to only keep the ones that have the email or domain we want to reimport
// because the q parameter in the list method also filters the events that have the email or domain in their summary, description ...
// The q parameter allows us to narrow down the events
filteredEvents = filteredEvents.filter(
(event) =>
event.attendees?.some(

View File

@ -3,6 +3,7 @@ import { calendar_v3 as calendarV3 } from 'googleapis';
import { isEmailBlocklisted } from 'src/modules/calendar-messaging-participant/utils/is-email-blocklisted.util';
export const filterOutBlocklistedEvents = (
calendarChannelHandle: string,
events: calendarV3.Schema$Event[],
blocklist: string[],
) => {
@ -12,7 +13,8 @@ export const filterOutBlocklistedEvents = (
}
return event.attendees.every(
(attendee) => !isEmailBlocklisted(attendee.email, blocklist),
(attendee) =>
!isEmailBlocklisted(calendarChannelHandle, attendee.email, blocklist),
);
});
};