Skip to content

Commit 5f70d38

Browse files
authored
Fix caldav issues (#16297)
1 parent e112eb4 commit 5f70d38

File tree

6 files changed

+54
-64
lines changed

6 files changed

+54
-64
lines changed

packages/twenty-front/src/pages/settings/accounts/SettingsAccountsConfiguration.tsx

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -99,31 +99,32 @@ export const SettingsAccountsConfiguration = () => {
9999
});
100100
};
101101

102-
switch (currentStep) {
103-
case SettingsAccountsConfigurationStep.Email:
104-
if (!isDefined(messageChannel)) {
105-
return null;
106-
}
107-
return (
108-
<SettingsAccountsConfigurationStepEmail
109-
messageChannel={messageChannel}
110-
hasNextStep={isDefined(calendarChannel)}
111-
isSubmitting={isSubmitting}
112-
onNext={handleNext}
113-
onAddAccount={handleAddAccount}
114-
/>
115-
);
116-
case SettingsAccountsConfigurationStep.Calendar:
117-
if (!isDefined(calendarChannel)) {
118-
return null;
119-
}
120-
return (
121-
<SettingsAccountsConfigurationStepCalendar
122-
calendarChannel={calendarChannel}
123-
messageChannel={messageChannel}
124-
isSubmitting={isSubmitting}
125-
onAddAccount={handleAddAccount}
126-
/>
127-
);
102+
const showEmailStep =
103+
currentStep === SettingsAccountsConfigurationStep.Email &&
104+
isDefined(messageChannel);
105+
106+
if (showEmailStep) {
107+
return (
108+
<SettingsAccountsConfigurationStepEmail
109+
messageChannel={messageChannel}
110+
hasNextStep={isDefined(calendarChannel)}
111+
isSubmitting={isSubmitting}
112+
onNext={handleNext}
113+
onAddAccount={handleAddAccount}
114+
/>
115+
);
128116
}
117+
118+
if (!isDefined(calendarChannel)) {
119+
return null;
120+
}
121+
122+
return (
123+
<SettingsAccountsConfigurationStepCalendar
124+
calendarChannel={calendarChannel}
125+
messageChannel={messageChannel}
126+
isSubmitting={isSubmitting}
127+
onAddAccount={handleAddAccount}
128+
/>
129+
);
129130
};

packages/twenty-server/src/engine/core-modules/imap-smtp-caldav-connection/services/imap-smtp-caldav-connection.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class ImapSmtpCaldavService {
139139
}
140140

141141
throw new UserInputError(`CALDAV connection failed: ${error.message}`, {
142-
userFriendlyMessage: msg`Invalid credentials. Please check your username and password.`,
142+
userFriendlyMessage: msg`Invalid CALDAV credentials. Please check your username and password.`,
143143
});
144144
}
145145

packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/caldav/lib/caldav.client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class CalDAVClient {
8484
if (!this.hasFileExtension(url)) return 'ics';
8585
const fileName = url.substring(url.lastIndexOf('/') + 1);
8686

87-
return fileName.substring(fileName.lastIndexOf('.') + 1);
87+
return fileName.substring(fileName.lastIndexOf('.') + 1).toLowerCase();
8888
}
8989

9090
private isValidFormat(url: string): boolean {

packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-account-authentication.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class CalendarAccountAuthenticationService {
3333
}: ValidateAndRefreshConnectedAccountAuthenticationParams): Promise<ConnectedAccountTokens> {
3434
if (
3535
connectedAccount.provider === ConnectedAccountProvider.IMAP_SMTP_CALDAV &&
36-
isDefined(connectedAccount.connectionParameters?.SMTP)
36+
isDefined(connectedAccount.connectionParameters?.CALDAV)
3737
) {
3838
await this.validateCalDavCredentialsForConnectedAccount({
3939
connectedAccount,

packages/twenty-server/src/modules/connected-account/services/imap-smtp-caldav-apis.service.spec.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ describe('ImapSmtpCalDavAPIService', () => {
261261
expect(mockCalendarQueueService.add).not.toHaveBeenCalled();
262262
});
263263

264-
it('should create both channels when only CALDAV is configured but disable message sync', async () => {
264+
it('should only create calendar channel when only CALDAV is configured', async () => {
265265
const caldavOnlyInput = {
266266
...baseInput,
267267
connectionParameters: {
@@ -282,7 +282,6 @@ describe('ImapSmtpCalDavAPIService', () => {
282282
const expectedCalendarChannel = {
283283
id: 'mocked-uuid',
284284
connectedAccountId: 'mocked-uuid',
285-
286285
handle: '[email protected]',
287286
};
288287

@@ -292,21 +291,7 @@ describe('ImapSmtpCalDavAPIService', () => {
292291

293292
await service.processAccount(caldavOnlyInput);
294293

295-
expect(mockMessageChannelRepository.save).toHaveBeenCalledWith(
296-
{
297-
id: 'mocked-uuid',
298-
connectedAccountId: 'mocked-uuid',
299-
type: MessageChannelType.EMAIL,
300-
handle: '[email protected]',
301-
isSyncEnabled: false,
302-
syncStatus: MessageChannelSyncStatus.NOT_SYNCED,
303-
syncStage: MessageChannelSyncStage.PENDING_CONFIGURATION,
304-
pendingGroupEmailsAction: MessageChannelPendingGroupEmailsAction.NONE,
305-
syncCursor: '',
306-
syncStageStartedAt: null,
307-
},
308-
{},
309-
);
294+
expect(mockMessageChannelRepository.save).not.toHaveBeenCalled();
310295
expect(mockCalendarChannelRepository.save).toHaveBeenCalled();
311296

312297
expect(mockMessageQueueService.add).not.toHaveBeenCalled();

packages/twenty-server/src/modules/connected-account/services/imap-smtp-caldav-apis.service.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,29 @@ export class ImapSmtpCalDavAPIService {
138138
accountId: string,
139139
messageChannelRepository: WorkspaceRepository<MessageChannelWorkspaceEntity>,
140140
): Promise<MessageChannelWorkspaceEntity | null> {
141-
const shouldEnableSync = Boolean(input.connectionParameters.IMAP);
142-
143-
const newMessageChannel = await messageChannelRepository.save(
144-
{
145-
id: v4(),
146-
connectedAccountId: accountId,
147-
type: MessageChannelType.EMAIL,
148-
handle: input.handle,
149-
isSyncEnabled: shouldEnableSync,
150-
syncStatus: MessageChannelSyncStatus.NOT_SYNCED,
151-
syncStage: MessageChannelSyncStage.PENDING_CONFIGURATION,
152-
pendingGroupEmailsAction: MessageChannelPendingGroupEmailsAction.NONE,
153-
syncCursor: '',
154-
syncStageStartedAt: null,
155-
},
156-
{},
157-
);
141+
const shouldCreateMessageChannel = Boolean(input.connectionParameters.IMAP);
142+
143+
if (shouldCreateMessageChannel) {
144+
const newMessageChannel = await messageChannelRepository.save(
145+
{
146+
id: v4(),
147+
connectedAccountId: accountId,
148+
type: MessageChannelType.EMAIL,
149+
handle: input.handle,
150+
isSyncEnabled: true,
151+
syncStatus: MessageChannelSyncStatus.NOT_SYNCED,
152+
syncStage: MessageChannelSyncStage.PENDING_CONFIGURATION,
153+
pendingGroupEmailsAction: MessageChannelPendingGroupEmailsAction.NONE,
154+
syncCursor: '',
155+
syncStageStartedAt: null,
156+
},
157+
{},
158+
);
158159

159-
return shouldEnableSync ? newMessageChannel : null;
160+
return newMessageChannel;
161+
}
162+
163+
return null;
160164
}
161165

162166
private async setupCalendarChannels(

0 commit comments

Comments
 (0)