Skip to content

Conversation

@neo773
Copy link
Member

@neo773 neo773 commented Dec 3, 2025

No description provided.

Comment on lines +119 to +129
return null;
}

return (
<SettingsAccountsConfigurationStepCalendar
calendarChannel={calendarChannel}
messageChannel={messageChannel}
isSubmitting={isSubmitting}
onAddAccount={handleAddAccount}
/>
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: SettingsAccountsConfiguration renders SettingsAccountsConfigurationStepCalendar when currentStep is Email for CALDAV-only accounts due to missing messageChannel check.
Severity: HIGH | Confidence: High

🔍 Detailed Analysis

When currentStep is SettingsAccountsConfigurationStep.Email for an account that only has CALDAV configured (i.e., messageChannel is undefined and calendarChannel is defined), the component incorrectly renders SettingsAccountsConfigurationStepCalendar. This occurs because the showEmailStep condition currentStep === SettingsAccountsConfigurationStep.Email && isDefined(messageChannel) evaluates to false, and the subsequent check !isDefined(calendarChannel) also evaluates to false, causing the SettingsAccountsConfigurationStepCalendar component to be rendered by default. This leads to a confusing user experience where the Calendar configuration UI is shown instead of the expected Email configuration UI.

💡 Suggested Fix

Reintroduce an explicit check for isDefined(messageChannel) when currentStep is SettingsAccountsConfigurationStep.Email to ensure the correct step is rendered or null is returned if messageChannel is not present.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location:
packages/twenty-front/src/pages/settings/accounts/SettingsAccountsConfiguration.tsx#L102-L129

Potential issue: When `currentStep` is `SettingsAccountsConfigurationStep.Email` for an
account that only has CALDAV configured (i.e., `messageChannel` is `undefined` and
`calendarChannel` is `defined`), the component incorrectly renders
`SettingsAccountsConfigurationStepCalendar`. This occurs because the `showEmailStep`
condition `currentStep === SettingsAccountsConfigurationStep.Email &&
isDefined(messageChannel)` evaluates to `false`, and the subsequent check
`!isDefined(calendarChannel)` also evaluates to `false`, causing the
`SettingsAccountsConfigurationStepCalendar` component to be rendered by default. This
leads to a confusing user experience where the Calendar configuration UI is shown
instead of the expected Email configuration UI.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 5265647

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 3, 2025

Greptile Overview

Greptile Summary

This PR fixes several CalDAV-related issues:

  • Critical bug fix: Fixed calendar-account-authentication.service.ts:36 where the code incorrectly checked connectionParameters.SMTP instead of connectionParameters.CALDAV when validating calendar authentication. This would have prevented CalDAV authentication from working properly.

  • Message channel logic improvement: Refactored setupMessageChannels to only create a message channel when IMAP is actually present, rather than creating it and then discarding it. This improves code clarity and prevents unnecessary database operations.

  • File extension handling: Added .toLowerCase() to file extension extraction in caldav.client.ts:87 to ensure case-insensitive matching against allowed extensions (ics, eml).

  • Error message clarity: Updated CalDAV connection error message to explicitly mention "CALDAV" instead of generic "Invalid credentials" for better user experience.

  • Frontend refactor: Replaced switch statement with if-else logic in SettingsAccountsConfiguration.tsx. However, this introduces a subtle behavioral change where any step other than Email will attempt to render the Calendar step (see inline comment).

Confidence Score: 4/5

  • Safe to merge with one logic concern to verify in the frontend code
  • The PR addresses critical bugs (SMTP vs CALDAV check) and improves code quality. Most changes are straightforward improvements. The score is 4 instead of 5 due to the frontend refactor that changes implicit behavior around unhandled step values.
  • Pay close attention to SettingsAccountsConfiguration.tsx - verify that currentStep can only be Email or Calendar enum values

Important Files Changed

File Analysis

Filename Score Overview
packages/twenty-front/src/pages/settings/accounts/SettingsAccountsConfiguration.tsx 4/5 Refactored switch statement to if-else for cleaner logic flow, but the Calendar step logic may have changed behavior
packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-account-authentication.service.ts 5/5 Fixed critical bug where SMTP was checked instead of CALDAV for calendar authentication
packages/twenty-server/src/modules/connected-account/services/imap-smtp-caldav-apis.service.ts 5/5 Improved logic clarity by only creating message channel when IMAP is present

Sequence Diagram

sequenceDiagram
    participant User
    participant Frontend
    participant AccountAPI
    participant CalendarService
    participant CalDAVDriver

    User->>Frontend: Configure CalDAV account
    Frontend->>AccountAPI: Process account with parameters
    AccountAPI->>AccountAPI: Check CALDAV in connection params
    alt CALDAV exists
        AccountAPI->>AccountAPI: Create calendar channel
    end
    alt IMAP exists
        AccountAPI->>AccountAPI: Create message channel
    end
    AccountAPI-->>Frontend: Return account ID

    User->>Frontend: Start calendar sync
    Frontend->>CalendarService: Validate connection
    CalendarService->>CalendarService: Check CALDAV field (bug fix)
    alt CALDAV present
        CalendarService->>CalendarService: Verify credentials
    end
    CalendarService-->>Frontend: Connection validated

    Frontend->>CalDAVDriver: Fetch calendar events
    CalDAVDriver->>CalDAVDriver: List available calendars
    CalDAVDriver->>CalDAVDriver: Normalize file extensions to lowercase
    CalDAVDriver->>CalDAVDriver: Filter valid formats
    CalDAVDriver-->>Frontend: Return calendar events
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +102 to +129
const showEmailStep =
currentStep === SettingsAccountsConfigurationStep.Email &&
isDefined(messageChannel);

if (showEmailStep) {
return (
<SettingsAccountsConfigurationStepEmail
messageChannel={messageChannel}
hasNextStep={isDefined(calendarChannel)}
isSubmitting={isSubmitting}
onNext={handleNext}
onAddAccount={handleAddAccount}
/>
);
}

if (!isDefined(calendarChannel)) {
return null;
}

return (
<SettingsAccountsConfigurationStepCalendar
calendarChannel={calendarChannel}
messageChannel={messageChannel}
isSubmitting={isSubmitting}
onAddAccount={handleAddAccount}
/>
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Potential logic change: the new code will always check currentStep for the email step but will render the calendar step for ANY other step value (not just SettingsAccountsConfigurationStep.Calendar). The old switch statement would implicitly return undefined for unknown step values.

If currentStep can only be Email or Calendar, this is fine. Otherwise, you may want to add an explicit check:

Suggested change
const showEmailStep =
currentStep === SettingsAccountsConfigurationStep.Email &&
isDefined(messageChannel);
if (showEmailStep) {
return (
<SettingsAccountsConfigurationStepEmail
messageChannel={messageChannel}
hasNextStep={isDefined(calendarChannel)}
isSubmitting={isSubmitting}
onNext={handleNext}
onAddAccount={handleAddAccount}
/>
);
}
if (!isDefined(calendarChannel)) {
return null;
}
return (
<SettingsAccountsConfigurationStepCalendar
calendarChannel={calendarChannel}
messageChannel={messageChannel}
isSubmitting={isSubmitting}
onAddAccount={handleAddAccount}
/>
);
if (showEmailStep) {
return (
<SettingsAccountsConfigurationStepEmail
messageChannel={messageChannel}
hasNextStep={isDefined(calendarChannel)}
isSubmitting={isSubmitting}
onNext={handleNext}
onAddAccount={handleAddAccount}
/>
);
}
if (currentStep !== SettingsAccountsConfigurationStep.Calendar || !isDefined(calendarChannel)) {
return null;
}
return (
<SettingsAccountsConfigurationStepCalendar
calendarChannel={calendarChannel}
messageChannel={messageChannel}
isSubmitting={isSubmitting}
onAddAccount={handleAddAccount}
/>
);
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/twenty-front/src/pages/settings/accounts/SettingsAccountsConfiguration.tsx
Line: 102:129

Comment:
**logic:** Potential logic change: the new code will always check `currentStep` for the email step but will render the calendar step for ANY other step value (not just `SettingsAccountsConfigurationStep.Calendar`). The old switch statement would implicitly return `undefined` for unknown step values.

If `currentStep` can only be `Email` or `Calendar`, this is fine. Otherwise, you may want to add an explicit check:

```suggestion
  if (showEmailStep) {
    return (
      <SettingsAccountsConfigurationStepEmail
        messageChannel={messageChannel}
        hasNextStep={isDefined(calendarChannel)}
        isSubmitting={isSubmitting}
        onNext={handleNext}
        onAddAccount={handleAddAccount}
      />
    );
  }

  if (currentStep !== SettingsAccountsConfigurationStep.Calendar || !isDefined(calendarChannel)) {
    return null;
  }

  return (
    <SettingsAccountsConfigurationStepCalendar
      calendarChannel={calendarChannel}
      messageChannel={messageChannel}
      isSubmitting={isSubmitting}
      onAddAccount={handleAddAccount}
    />
  );
```

How can I resolve this? If you propose a fix, please make it concise.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:2076

This environment will automatically shut down when the PR is closed or after 5 hours.

@charlesBochet charlesBochet merged commit 5f70d38 into main Dec 4, 2025
67 of 68 checks passed
@charlesBochet charlesBochet deleted the fix-caldav-issues branch December 4, 2025 13:34
@twenty-eng-sync
Copy link

Hey @charlesBochet! After you've done the QA of your Pull Request, you can mark it as done here. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants