mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-26 05:24:04 +03:00
Remove Gate decorator IS_BLOCKLIST_ENABLED from BlocklistObjectMetadata (#4250)
* Remove Gate decorator from BlocklistObjectMetadata * check if blocklist is enabled * wip * done
This commit is contained in:
parent
b762be3f93
commit
72ae6e44b3
@ -1,4 +1,7 @@
|
||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { FetchMessagesByBatchesService } from 'src/workspace/messaging/services/fetch-messages-by-batches.service';
|
||||
import { GmailClientProvider } from 'src/workspace/messaging/services/providers/gmail/gmail-client.provider';
|
||||
@ -15,6 +18,10 @@ import { createQueriesFromMessageIds } from 'src/workspace/messaging/utils/creat
|
||||
import { gmailSearchFilterExcludeEmails } from 'src/workspace/messaging/utils/gmail-search-filter';
|
||||
import { BlocklistService } from 'src/workspace/messaging/repositories/blocklist/blocklist.service';
|
||||
import { SaveMessagesAndCreateContactsService } from 'src/workspace/messaging/services/save-messages-and-create-contacts.service';
|
||||
import {
|
||||
FeatureFlagEntity,
|
||||
FeatureFlagKeys,
|
||||
} from 'src/core/feature-flag/feature-flag.entity';
|
||||
|
||||
@Injectable()
|
||||
export class GmailFullSyncService {
|
||||
@ -30,6 +37,8 @@ export class GmailFullSyncService {
|
||||
private readonly messageChannelMessageAssociationService: MessageChannelMessageAssociationService,
|
||||
private readonly blocklistService: BlocklistService,
|
||||
private readonly saveMessagesAndCreateContactsService: SaveMessagesAndCreateContactsService,
|
||||
@InjectRepository(FeatureFlagEntity, 'core')
|
||||
private readonly featureFlagRepository: Repository<FeatureFlagEntity>,
|
||||
) {}
|
||||
|
||||
public async fetchConnectedAccountThreads(
|
||||
@ -63,10 +72,22 @@ export class GmailFullSyncService {
|
||||
const gmailClient =
|
||||
await this.gmailClientProvider.getGmailClient(refreshToken);
|
||||
|
||||
const blocklist = await this.blocklistService.getByWorkspaceMemberId(
|
||||
workspaceMemberId,
|
||||
workspaceId,
|
||||
);
|
||||
const isBlocklistEnabledFeatureFlag =
|
||||
await this.featureFlagRepository.findOneBy({
|
||||
workspaceId,
|
||||
key: FeatureFlagKeys.IsBlocklistEnabled,
|
||||
value: true,
|
||||
});
|
||||
|
||||
const isBlocklistEnabled =
|
||||
isBlocklistEnabledFeatureFlag && isBlocklistEnabledFeatureFlag.value;
|
||||
|
||||
const blocklist = isBlocklistEnabled
|
||||
? await this.blocklistService.getByWorkspaceMemberId(
|
||||
workspaceMemberId,
|
||||
workspaceId,
|
||||
)
|
||||
: [];
|
||||
|
||||
const blocklistedEmails = blocklist.map((blocklist) => blocklist.handle);
|
||||
let startTime = Date.now();
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { gmail_v1 } from 'googleapis';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { FetchMessagesByBatchesService } from 'src/workspace/messaging/services/fetch-messages-by-batches.service';
|
||||
import { GmailClientProvider } from 'src/workspace/messaging/services/providers/gmail/gmail-client.provider';
|
||||
@ -18,6 +20,10 @@ import { GmailMessage } from 'src/workspace/messaging/types/gmail-message';
|
||||
import { isPersonEmail } from 'src/workspace/messaging/utils/is-person-email.util';
|
||||
import { BlocklistService } from 'src/workspace/messaging/repositories/blocklist/blocklist.service';
|
||||
import { SaveMessagesAndCreateContactsService } from 'src/workspace/messaging/services/save-messages-and-create-contacts.service';
|
||||
import {
|
||||
FeatureFlagEntity,
|
||||
FeatureFlagKeys,
|
||||
} from 'src/core/feature-flag/feature-flag.entity';
|
||||
|
||||
@Injectable()
|
||||
export class GmailPartialSyncService {
|
||||
@ -33,6 +39,8 @@ export class GmailPartialSyncService {
|
||||
private readonly messageService: MessageService,
|
||||
private readonly blocklistService: BlocklistService,
|
||||
private readonly saveMessagesAndCreateContactsService: SaveMessagesAndCreateContactsService,
|
||||
@InjectRepository(FeatureFlagEntity, 'core')
|
||||
private readonly featureFlagRepository: Repository<FeatureFlagEntity>,
|
||||
) {}
|
||||
|
||||
public async fetchConnectedAccountThreads(
|
||||
@ -140,10 +148,22 @@ export class GmailPartialSyncService {
|
||||
connectedAccountId,
|
||||
);
|
||||
|
||||
const blocklist = await this.blocklistService.getByWorkspaceMemberId(
|
||||
connectedAccount.accountOwnerId,
|
||||
workspaceId,
|
||||
);
|
||||
const isBlocklistEnabledFeatureFlag =
|
||||
await this.featureFlagRepository.findOneBy({
|
||||
workspaceId,
|
||||
key: FeatureFlagKeys.IsBlocklistEnabled,
|
||||
value: true,
|
||||
});
|
||||
|
||||
const isBlocklistEnabled =
|
||||
isBlocklistEnabledFeatureFlag && isBlocklistEnabledFeatureFlag.value;
|
||||
|
||||
const blocklist = isBlocklistEnabled
|
||||
? await this.blocklistService.getByWorkspaceMemberId(
|
||||
connectedAccount.accountOwnerId,
|
||||
workspaceId,
|
||||
)
|
||||
: [];
|
||||
|
||||
const blocklistedEmails = blocklist.map((blocklist) => blocklist.handle);
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
|
||||
import { FieldMetadata } from 'src/workspace/workspace-sync-metadata/decorators/field-metadata.decorator';
|
||||
import { Gate } from 'src/workspace/workspace-sync-metadata/decorators/gate.decorator';
|
||||
import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-system.decorator';
|
||||
import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator';
|
||||
import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata';
|
||||
@ -13,9 +12,6 @@ import { WorkspaceMemberObjectMetadata } from 'src/workspace/workspace-sync-meta
|
||||
description: 'Blocklist',
|
||||
icon: 'IconForbid2',
|
||||
})
|
||||
@Gate({
|
||||
featureFlag: 'IS_BLOCKLIST_ENABLED',
|
||||
})
|
||||
@IsSystem()
|
||||
export class BlocklistObjectMetadata extends BaseObjectMetadata {
|
||||
@FieldMetadata({
|
||||
|
Loading…
Reference in New Issue
Block a user