feat: message folders control (#14144)

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
This commit is contained in:
neo773
2025-08-30 21:09:10 +05:30
committed by GitHub
parent a0884cede9
commit 8ab71fef1f
49 changed files with 1786 additions and 301 deletions
@@ -17,7 +17,6 @@ import { AuthSsoService } from 'src/engine/core-modules/auth/services/auth-sso.s
import { CreateCalendarChannelService } from 'src/engine/core-modules/auth/services/create-calendar-channel.service';
import { CreateConnectedAccountService } from 'src/engine/core-modules/auth/services/create-connected-account.service';
import { CreateMessageChannelService } from 'src/engine/core-modules/auth/services/create-message-channel.service';
import { CreateMessageFolderService } from 'src/engine/core-modules/auth/services/create-message-folder.service';
import { GoogleAPIScopesService } from 'src/engine/core-modules/auth/services/google-apis-scopes';
import { GoogleAPIsService } from 'src/engine/core-modules/auth/services/google-apis.service';
import { MicrosoftAPIsService } from 'src/engine/core-modules/auth/services/microsoft-apis.service';
@@ -59,6 +58,7 @@ import { UserRoleModule } from 'src/engine/metadata-modules/user-role/user-role.
import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module';
import { WorkspaceManagerModule } from 'src/engine/workspace-manager/workspace-manager.module';
import { ConnectedAccountModule } from 'src/modules/connected-account/connected-account.module';
import { MessagingFolderSyncManagerModule } from 'src/modules/messaging/message-folder-manager/messaging-folder-sync-manager.module';
import { TwoFactorAuthenticationMethod } from '../two-factor-authentication/entities/two-factor-authentication-method.entity';
import { TwoFactorAuthenticationModule } from '../two-factor-authentication/two-factor-authentication.module';
@@ -96,6 +96,7 @@ import { JwtAuthStrategy } from './strategies/jwt.auth.strategy';
OnboardingModule,
WorkspaceDataSourceModule,
ConnectedAccountModule,
MessagingFolderSyncManagerModule,
WorkspaceSSOModule,
FeatureFlagModule,
WorkspaceInvitationModule,
@@ -136,17 +137,11 @@ import { JwtAuthStrategy } from './strategies/jwt.auth.strategy';
ResetMessageFolderService,
CreateMessageChannelService,
CreateCalendarChannelService,
CreateMessageFolderService,
CreateConnectedAccountService,
UpdateConnectedAccountOnReconnectService,
TransientTokenService,
AuthSsoService,
],
exports: [
AccessTokenService,
LoginTokenService,
RefreshTokenService,
CreateMessageFolderService,
],
exports: [AccessTokenService, LoginTokenService, RefreshTokenService],
})
export class AuthModule {}
@@ -1,53 +0,0 @@
import { Injectable } from '@nestjs/common';
import { v4 } from 'uuid';
import { type WorkspaceEntityManager } from 'src/engine/twenty-orm/entity-manager/workspace-entity-manager';
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
import { type MessageFolderWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-folder.workspace-entity';
import { MessageFolderName } from 'src/modules/messaging/message-import-manager/drivers/microsoft/types/folders';
export type CreateMessageFoldersInput = {
workspaceId: string;
messageChannelId: string;
manager: WorkspaceEntityManager;
};
@Injectable()
export class CreateMessageFolderService {
constructor(
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
) {}
async createMessageFolders(input: CreateMessageFoldersInput): Promise<void> {
const { workspaceId, messageChannelId, manager } = input;
const messageFolderRepository =
await this.twentyORMGlobalManager.getRepositoryForWorkspace<MessageFolderWorkspaceEntity>(
workspaceId,
'messageFolder',
);
await messageFolderRepository.save(
{
id: v4(),
messageChannelId,
name: MessageFolderName.INBOX,
syncCursor: '',
},
{},
manager,
);
await messageFolderRepository.save(
{
id: v4(),
messageChannelId,
name: MessageFolderName.SENT_ITEMS,
syncCursor: '',
},
{},
manager,
);
}
}
@@ -6,7 +6,6 @@ import { ConnectedAccountProvider } from 'twenty-shared/types';
import { CreateCalendarChannelService } from 'src/engine/core-modules/auth/services/create-calendar-channel.service';
import { CreateConnectedAccountService } from 'src/engine/core-modules/auth/services/create-connected-account.service';
import { CreateMessageChannelService } from 'src/engine/core-modules/auth/services/create-message-channel.service';
import { CreateMessageFolderService } from 'src/engine/core-modules/auth/services/create-message-folder.service';
import { MicrosoftAPIsService } from 'src/engine/core-modules/auth/services/microsoft-apis.service';
import { ResetCalendarChannelService } from 'src/engine/core-modules/auth/services/reset-calendar-channel.service';
import { ResetMessageChannelService } from 'src/engine/core-modules/auth/services/reset-message-channel.service';
@@ -141,12 +140,6 @@ describe('MicrosoftAPIsService', () => {
.mockResolvedValue('message-channel-id'),
},
},
{
provide: CreateMessageFolderService,
useValue: {
createMessageFolders: jest.fn(),
},
},
{
provide: CreateCalendarChannelService,
useValue: {
@@ -6,7 +6,6 @@ import { v4 } from 'uuid';
import { CreateCalendarChannelService } from 'src/engine/core-modules/auth/services/create-calendar-channel.service';
import { CreateConnectedAccountService } from 'src/engine/core-modules/auth/services/create-connected-account.service';
import { CreateMessageChannelService } from 'src/engine/core-modules/auth/services/create-message-channel.service';
import { CreateMessageFolderService } from 'src/engine/core-modules/auth/services/create-message-folder.service';
import { ResetCalendarChannelService } from 'src/engine/core-modules/auth/services/reset-calendar-channel.service';
import { ResetMessageChannelService } from 'src/engine/core-modules/auth/services/reset-message-channel.service';
import { ResetMessageFolderService } from 'src/engine/core-modules/auth/services/reset-message-folder.service';
@@ -52,7 +51,6 @@ export class MicrosoftAPIsService {
private readonly resetCalendarChannelService: ResetCalendarChannelService,
private readonly createMessageChannelService: CreateMessageChannelService,
private readonly createCalendarChannelService: CreateCalendarChannelService,
private readonly createMessageFolderService: CreateMessageFolderService,
private readonly createConnectedAccountService: CreateConnectedAccountService,
private readonly updateConnectedAccountOnReconnectService: UpdateConnectedAccountOnReconnectService,
private readonly twentyConfigService: TwentyConfigService,
@@ -122,18 +120,11 @@ export class MicrosoftAPIsService {
manager,
});
const newMessageChannelId =
await this.createMessageChannelService.createMessageChannel({
workspaceId,
connectedAccountId: newOrExistingConnectedAccountId,
handle,
messageVisibility,
manager,
});
await this.createMessageFolderService.createMessageFolders({
await this.createMessageChannelService.createMessageChannel({
workspaceId,
messageChannelId: newMessageChannelId,
connectedAccountId: newOrExistingConnectedAccountId,
handle,
messageVisibility,
manager,
});
@@ -30,6 +30,15 @@ export const PUBLIC_FEATURE_FLAGS: PublicFeatureFlag[] = [
imagePath: 'https://twenty.com/images/lab/is-workflow-branch-enabled.png',
},
},
{
key: FeatureFlagKey.IS_MESSAGE_FOLDER_CONTROL_ENABLED,
metadata: {
label: 'Message Folder Control',
description: 'Control which folders are synced',
imagePath:
'https://twenty.com/images/lab/is-message-folder-control-enabled.png',
},
},
...(process.env.CLOUDFLARE_API_KEY
? [
// {
@@ -14,4 +14,5 @@ export enum FeatureFlagKey {
IS_WORKSPACE_MIGRATION_V2_ENABLED = 'IS_WORKSPACE_MIGRATION_V2_ENABLED',
IS_API_KEY_ROLES_ENABLED = 'IS_API_KEY_ROLES_ENABLED',
IS_PAGE_LAYOUT_ENABLED = 'IS_PAGE_LAYOUT_ENABLED',
IS_MESSAGE_FOLDER_CONTROL_ENABLED = 'IS_MESSAGE_FOLDER_CONTROL_ENABLED',
}