Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@BilalG1
Copy link
Contributor

@BilalG1 BilalG1 commented Nov 20, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Fixed email template retention: custom templates are now only preserved when using dedicated email servers, not shared configurations.
  • Tests

    • Added end-to-end test coverage for email template behavior across different server configurations.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Nov 20, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
stack-backend Ready Ready Preview Comment Nov 20, 2025 6:09pm
stack-dashboard Ready Ready Preview Comment Nov 20, 2025 6:09pm
stack-demo Ready Ready Preview Comment Nov 20, 2025 6:09pm
stack-docs Ready Ready Preview Comment Nov 20, 2025 6:09pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 20, 2025

Walkthrough

Changes add type safety to email configuration and enforce that custom email templates are only preserved when using dedicated (non-shared) SMTP servers. The conditional template handling is validated through a new E2E test and implemented in the config sanitization schema.

Changes

Cohort / File(s) Summary
Type refinement for email configuration
apps/dashboard/.../projects/[projectId]/emails/page-client.tsx
Added type assertion using satisfies CompleteConfig['emails']['server'] to the emails.server object in EditEmailServerDialog update config.
E2E test validation
apps/e2e/tests/backend/endpoints/api/v1/internal/config.test.ts
Added DEFAULT_EMAIL_THEME_ID import and new test case "only keeps custom email templates when using a dedicated email server" that verifies templates are preserved with dedicated servers and removed with shared servers.
Conditional template merging logic
packages/stack-shared/src/config/schema.ts
Modified sanitizeOrganizationConfig to conditionally merge prepared.emails.templates only when config.emails.server.isShared is false; templates are omitted for shared server configurations.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Email Config Update
    participant Schema as sanitizeOrganizationConfig
    participant Templates as Email Templates Store
    
    Client->>Schema: updateConfig with emails.server
    
    alt isShared = false (Dedicated Server)
        Schema->>Templates: Merge & preserve prepared.emails.templates
        Templates->>Templates: Custom templates retained
    else isShared = true (Shared Server)
        Schema->>Templates: Omit prepared.emails.templates
        Templates->>Templates: Custom templates removed
    end
    
    Schema->>Client: Sanitized config returned
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • areas requiring extra attention:
    • The conditional logic in sanitizeOrganizationConfig (schema.ts) that determines when to include/exclude templates—verify this aligns with the intended multi-tenancy behavior
    • E2E test assertions to ensure the dedicated→shared→dedicated flow correctly validates template persistence

Possibly related PRs

Poem

🐰 With types refined and templates tamed,
Our shared and dedicated servers now framed.
Type safety hops and config flows true,
Only custom templates where they're due! ✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description contains only a boilerplate HTML comment with a link to CONTRIBUTING.md guidelines and provides no actual description of changes, objectives, or implementation details. Add a meaningful description explaining the problem being fixed, the solution implemented, and how the changes address the issue with email template reset behavior.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Email templates reset fix' is concise and specific, clearly indicating the main change involves fixing email template reset behavior, which aligns with the core functionality changes in the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch email-templates-reset-fix

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 20, 2025

Greptile Overview

Greptile Summary

This PR fixes the email templates reset issue by ensuring custom email templates are only included when using a dedicated email server (isShared = false). The fix prevents custom templates from persisting when switching to a shared email server and ensures they are properly restored when switching back to a dedicated server.

Key Changes

  • Modified sanitizeOrganizationConfig in schema.ts:755 to conditionally spread custom templates based on isShared flag
  • Added type annotation satisfies CompleteConfig['emails']['server'] to dashboard email configuration for type safety
  • Added comprehensive E2E test verifying the correct behavior when toggling between shared and dedicated servers

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is minimal, well-tested, and directly addresses the issue described in the PR title. The logic is sound: custom templates should only be available with dedicated servers. The change is protected by comprehensive E2E tests that verify correct behavior when switching between shared and dedicated servers, ensuring templates are properly excluded/restored
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/stack-shared/src/config/schema.ts 5/5 Conditionally excludes custom email templates when using shared email server to prevent template persistence issues
apps/dashboard/src/app/(main)/(protected)/projects/[projectId]/emails/page-client.tsx 5/5 Added type annotation to ensure email server config matches schema types correctly
apps/e2e/tests/backend/endpoints/api/v1/internal/config.test.ts 5/5 Added comprehensive test verifying custom templates are removed with shared server and restored with dedicated server

Sequence Diagram

sequenceDiagram
    participant User
    participant Dashboard
    participant API
    participant Schema
    participant Database

    User->>Dashboard: Update email server config
    Dashboard->>API: PATCH /api/v1/internal/config/override
    Note over Dashboard,API: Sets isShared = true/false
    API->>Database: Store config override
    Database-->>API: Config saved
    
    User->>Dashboard: Request config
    Dashboard->>API: GET /api/v1/internal/config
    API->>Database: Fetch config
    Database-->>API: Raw config
    API->>Schema: sanitizeOrganizationConfig(config)
    
    alt isShared = true
        Schema->>Schema: Exclude custom templates<br/>(use only DEFAULT_EMAIL_TEMPLATES)
    else isShared = false
        Schema->>Schema: Include custom templates<br/>(merge with DEFAULT_EMAIL_TEMPLATES)
    end
    
    Schema-->>API: Sanitized config
    API-->>Dashboard: Config with/without templates
    Dashboard-->>User: Display config
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.

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/stack-shared/src/config/schema.ts (1)

755-755: Consider using prepared.emails.server.isShared for consistency.

The conditional logic correctly filters out custom templates when using a shared server. However, since line 748 already prepares the sanitized config and the rest of the function uses prepared for similar checks, it would be more consistent to reference prepared.emails.server.isShared instead of config.emails.server.isShared.

While functionally equivalent (since isShared isn't transformed by sanitization), using prepared throughout maintains a consistent pattern.

   const templates: typeof prepared.emails.templates = {
     ...DEFAULT_EMAIL_TEMPLATES,
-    ...(config.emails.server.isShared ? {} : prepared.emails.templates),
+    ...(prepared.emails.server.isShared ? {} : prepared.emails.templates),
   };
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 772d984 and bcf6fe0.

📒 Files selected for processing (3)
  • apps/dashboard/src/app/(main)/(protected)/projects/[projectId]/emails/page-client.tsx (1 hunks)
  • apps/e2e/tests/backend/endpoints/api/v1/internal/config.test.ts (2 hunks)
  • packages/stack-shared/src/config/schema.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
apps/e2e/tests/backend/endpoints/api/v1/internal/config.test.ts (3)
apps/e2e/tests/helpers.ts (1)
  • it (12-12)
packages/stack-shared/src/helpers/emails.ts (1)
  • DEFAULT_EMAIL_THEME_ID (107-107)
apps/e2e/tests/backend/backend-helpers.ts (1)
  • niceBackendFetch (109-173)
apps/dashboard/src/app/(main)/(protected)/projects/[projectId]/emails/page-client.tsx (1)
packages/stack-shared/src/config/schema.ts (1)
  • CompleteConfig (1074-1074)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Vercel Agent Review
  • GitHub Check: all-good
  • GitHub Check: lint_and_build (latest)
  • GitHub Check: build (22.x)
  • GitHub Check: docker
  • GitHub Check: restart-dev-and-test
  • GitHub Check: build (22.x)
  • GitHub Check: setup-tests
  • GitHub Check: restart-dev-and-test-with-custom-base-port
  • GitHub Check: build (22.x)
  • GitHub Check: check_prisma_migrations (22.x)
🔇 Additional comments (3)
apps/dashboard/src/app/(main)/(protected)/projects/[projectId]/emails/page-client.tsx (1)

158-158: LGTM! Type safety improvement.

The satisfies assertion ensures the email server configuration object conforms to CompleteConfig['emails']['server'] at compile time, helping catch any structural mismatches early.

apps/e2e/tests/backend/endpoints/api/v1/internal/config.test.ts (2)

1-1: LGTM! Necessary import for the new test.

The DEFAULT_EMAIL_THEME_ID constant is correctly imported and used in the test to ensure the custom template references a valid theme.


536-633: LGTM! Comprehensive test coverage for template filtering behavior.

This end-to-end test thoroughly validates the new behavior:

  1. Dedicated server scenario (lines 575-601): Confirms custom templates are preserved when using a dedicated SMTP server
  2. Shared server scenario (lines 603-618): Verifies custom templates are filtered out from the rendered config when switching to shared
  3. Round-trip scenario (lines 620-632): Ensures templates reappear when switching back to dedicated, confirming they're stored in the database but conditionally rendered

The test design with helper functions (configureServer, upsertTemplate) promotes clarity and maintainability.

@BilalG1 BilalG1 merged commit 95781b9 into dev Nov 20, 2025
24 checks passed
@BilalG1 BilalG1 deleted the email-templates-reset-fix branch November 20, 2025 18:31
@coderabbitai coderabbitai bot mentioned this pull request Jan 3, 2026
@coderabbitai coderabbitai bot mentioned this pull request Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants