From 5f70d388ef97ed6a8164cd36050ab4d1408105e4 Mon Sep 17 00:00:00 2001 From: neo773 <62795688+neo773@users.noreply.github.com> Date: Thu, 4 Dec 2025 19:04:20 +0530 Subject: [PATCH] Fix caldav issues (#16297) --- .../SettingsAccountsConfiguration.tsx | 53 ++++++++++--------- .../imap-smtp-caldav-connection.service.ts | 2 +- .../drivers/caldav/lib/caldav.client.ts | 2 +- ...calendar-account-authentication.service.ts | 2 +- .../imap-smtp-caldav-apis.service.spec.ts | 19 +------ .../services/imap-smtp-caldav-apis.service.ts | 38 +++++++------ 6 files changed, 53 insertions(+), 63 deletions(-) diff --git a/packages/twenty-front/src/pages/settings/accounts/SettingsAccountsConfiguration.tsx b/packages/twenty-front/src/pages/settings/accounts/SettingsAccountsConfiguration.tsx index e2fc73c918..e6126b8702 100644 --- a/packages/twenty-front/src/pages/settings/accounts/SettingsAccountsConfiguration.tsx +++ b/packages/twenty-front/src/pages/settings/accounts/SettingsAccountsConfiguration.tsx @@ -99,31 +99,32 @@ export const SettingsAccountsConfiguration = () => { }); }; - switch (currentStep) { - case SettingsAccountsConfigurationStep.Email: - if (!isDefined(messageChannel)) { - return null; - } - return ( - - ); - case SettingsAccountsConfigurationStep.Calendar: - if (!isDefined(calendarChannel)) { - return null; - } - return ( - - ); + const showEmailStep = + currentStep === SettingsAccountsConfigurationStep.Email && + isDefined(messageChannel); + + if (showEmailStep) { + return ( + + ); } + + if (!isDefined(calendarChannel)) { + return null; + } + + return ( + + ); }; diff --git a/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/services/imap-smtp-caldav-connection.service.ts b/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/services/imap-smtp-caldav-connection.service.ts index 05f11b46d0..a71b9d68a8 100644 --- a/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/services/imap-smtp-caldav-connection.service.ts +++ b/packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/services/imap-smtp-caldav-connection.service.ts @@ -139,7 +139,7 @@ export class ImapSmtpCaldavService { } throw new UserInputError(`CALDAV connection failed: ${error.message}`, { - userFriendlyMessage: msg`Invalid credentials. Please check your username and password.`, + userFriendlyMessage: msg`Invalid CALDAV credentials. Please check your username and password.`, }); } diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/caldav/lib/caldav.client.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/caldav/lib/caldav.client.ts index 882bf065e6..6299f85743 100644 --- a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/caldav/lib/caldav.client.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/caldav/lib/caldav.client.ts @@ -84,7 +84,7 @@ export class CalDAVClient { if (!this.hasFileExtension(url)) return 'ics'; const fileName = url.substring(url.lastIndexOf('/') + 1); - return fileName.substring(fileName.lastIndexOf('.') + 1); + return fileName.substring(fileName.lastIndexOf('.') + 1).toLowerCase(); } private isValidFormat(url: string): boolean { diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-account-authentication.service.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-account-authentication.service.ts index 6b058f07d5..b941469f77 100644 --- a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-account-authentication.service.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-account-authentication.service.ts @@ -33,7 +33,7 @@ export class CalendarAccountAuthenticationService { }: ValidateAndRefreshConnectedAccountAuthenticationParams): Promise { if ( connectedAccount.provider === ConnectedAccountProvider.IMAP_SMTP_CALDAV && - isDefined(connectedAccount.connectionParameters?.SMTP) + isDefined(connectedAccount.connectionParameters?.CALDAV) ) { await this.validateCalDavCredentialsForConnectedAccount({ connectedAccount, diff --git a/packages/twenty-server/src/modules/connected-account/services/imap-smtp-caldav-apis.service.spec.ts b/packages/twenty-server/src/modules/connected-account/services/imap-smtp-caldav-apis.service.spec.ts index 15ee83933f..f4cdc51241 100644 --- a/packages/twenty-server/src/modules/connected-account/services/imap-smtp-caldav-apis.service.spec.ts +++ b/packages/twenty-server/src/modules/connected-account/services/imap-smtp-caldav-apis.service.spec.ts @@ -261,7 +261,7 @@ describe('ImapSmtpCalDavAPIService', () => { expect(mockCalendarQueueService.add).not.toHaveBeenCalled(); }); - it('should create both channels when only CALDAV is configured but disable message sync', async () => { + it('should only create calendar channel when only CALDAV is configured', async () => { const caldavOnlyInput = { ...baseInput, connectionParameters: { @@ -282,7 +282,6 @@ describe('ImapSmtpCalDavAPIService', () => { const expectedCalendarChannel = { id: 'mocked-uuid', connectedAccountId: 'mocked-uuid', - handle: 'test@example.com', }; @@ -292,21 +291,7 @@ describe('ImapSmtpCalDavAPIService', () => { await service.processAccount(caldavOnlyInput); - expect(mockMessageChannelRepository.save).toHaveBeenCalledWith( - { - id: 'mocked-uuid', - connectedAccountId: 'mocked-uuid', - type: MessageChannelType.EMAIL, - handle: 'test@example.com', - isSyncEnabled: false, - syncStatus: MessageChannelSyncStatus.NOT_SYNCED, - syncStage: MessageChannelSyncStage.PENDING_CONFIGURATION, - pendingGroupEmailsAction: MessageChannelPendingGroupEmailsAction.NONE, - syncCursor: '', - syncStageStartedAt: null, - }, - {}, - ); + expect(mockMessageChannelRepository.save).not.toHaveBeenCalled(); expect(mockCalendarChannelRepository.save).toHaveBeenCalled(); expect(mockMessageQueueService.add).not.toHaveBeenCalled(); diff --git a/packages/twenty-server/src/modules/connected-account/services/imap-smtp-caldav-apis.service.ts b/packages/twenty-server/src/modules/connected-account/services/imap-smtp-caldav-apis.service.ts index 74640cf84d..b726bf96b6 100644 --- a/packages/twenty-server/src/modules/connected-account/services/imap-smtp-caldav-apis.service.ts +++ b/packages/twenty-server/src/modules/connected-account/services/imap-smtp-caldav-apis.service.ts @@ -138,25 +138,29 @@ export class ImapSmtpCalDavAPIService { accountId: string, messageChannelRepository: WorkspaceRepository, ): Promise { - const shouldEnableSync = Boolean(input.connectionParameters.IMAP); + const shouldCreateMessageChannel = Boolean(input.connectionParameters.IMAP); - const newMessageChannel = await messageChannelRepository.save( - { - id: v4(), - connectedAccountId: accountId, - type: MessageChannelType.EMAIL, - handle: input.handle, - isSyncEnabled: shouldEnableSync, - syncStatus: MessageChannelSyncStatus.NOT_SYNCED, - syncStage: MessageChannelSyncStage.PENDING_CONFIGURATION, - pendingGroupEmailsAction: MessageChannelPendingGroupEmailsAction.NONE, - syncCursor: '', - syncStageStartedAt: null, - }, - {}, - ); + if (shouldCreateMessageChannel) { + const newMessageChannel = await messageChannelRepository.save( + { + id: v4(), + connectedAccountId: accountId, + type: MessageChannelType.EMAIL, + handle: input.handle, + isSyncEnabled: true, + syncStatus: MessageChannelSyncStatus.NOT_SYNCED, + syncStage: MessageChannelSyncStage.PENDING_CONFIGURATION, + pendingGroupEmailsAction: MessageChannelPendingGroupEmailsAction.NONE, + syncCursor: '', + syncStageStartedAt: null, + }, + {}, + ); - return shouldEnableSync ? newMessageChannel : null; + return newMessageChannel; + } + + return null; } private async setupCalendarChannels(