6255 move services from messaging common module into the correct module and refactor them (#6409)

Closes #6255 

- Move files from `messaging/common` into the correct module
- Remove common module between calendar and messaging
`calendar-messaging-participant-manager`
- Update and fix massaging and calendar participant matching
- Create `MatchParticipantModule`

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
bosiraphael
2024-07-27 12:29:02 +02:00
committed by GitHub
parent 3060eb4e1e
commit d0db3b765f
42 changed files with 398 additions and 540 deletions

View File

@ -0,0 +1,69 @@
import { isEmailBlocklisted } from 'src/modules/blocklist/utils/is-email-blocklisted.util';
describe('isEmailBlocklisted', () => {
it('should return true if email is blocklisted', () => {
const channelHandle = 'abc@example.com';
const email = 'hello@twenty.com';
const blocklist = ['hello@twenty.com', 'hey@twenty.com'];
const result = isEmailBlocklisted(channelHandle, email, blocklist);
expect(result).toBe(true);
});
it('should return false if email is not blocklisted', () => {
const channelHandle = 'abc@example.com';
const email = 'hello@twenty.com';
const blocklist = ['hey@example.com'];
const result = isEmailBlocklisted(channelHandle, email, blocklist);
expect(result).toBe(false);
});
it('should return false if email is null', () => {
const channelHandle = 'abc@twenty.com';
const email = null;
const blocklist = ['@example.com'];
const result = isEmailBlocklisted(channelHandle, email, blocklist);
expect(result).toBe(false);
});
it('should return true for subdomains', () => {
const channelHandle = 'abc@example.com';
const email = 'hello@twenty.twenty.com';
const blocklist = ['@twenty.com'];
const result = isEmailBlocklisted(channelHandle, email, blocklist);
expect(result).toBe(true);
});
it('should return false for domains which end with blocklisted domain but are not subdomains', () => {
const channelHandle = 'abc@example.com';
const email = 'hello@twentytwenty.com';
const blocklist = ['@twenty.com'];
const result = isEmailBlocklisted(channelHandle, email, blocklist);
expect(result).toBe(false);
});
it('should return false if email is undefined', () => {
const channelHandle = 'abc@example.com';
const email = undefined;
const blocklist = ['@twenty.com'];
const result = isEmailBlocklisted(channelHandle, email, blocklist);
expect(result).toBe(false);
});
it('should return true if email ends with blocklisted domain', () => {
const channelHandle = 'abc@example.com';
const email = 'hello@twenty.com';
const blocklist = ['@twenty.com'];
const result = isEmailBlocklisted(channelHandle, email, blocklist);
expect(result).toBe(true);
});
it('should return false if email is same as channel handle', () => {
const channelHandle = 'hello@twenty.com';
const email = 'hello@twenty.com';
const blocklist = ['@twenty.com'];
const result = isEmailBlocklisted(channelHandle, email, blocklist);
expect(result).toBe(false);
});
});

View File

@ -0,0 +1,21 @@
// TODO: Move inside blocklist module
export const isEmailBlocklisted = (
channelHandle: string,
email: string | null | undefined,
blocklist: string[],
): boolean => {
if (!email || email === channelHandle) {
return false;
}
return blocklist.some((item) => {
if (item.startsWith('@')) {
const domain = email.split('@')[1];
return domain === item.slice(1) || domain.endsWith(`.${item.slice(1)}`);
}
return email === item;
});
};