Skip to content

Updated welcome email renderer to use custom design settings#27094

Draft
cmraible wants to merge 3 commits intomainfrom
chris-ny-1197-use-design-settings-from-the-database-when-rendering-welcome
Draft

Updated welcome email renderer to use custom design settings#27094
cmraible wants to merge 3 commits intomainfrom
chris-ny-1197-use-design-settings-from-the-database-when-rendering-welcome

Conversation

@cmraible
Copy link
Copy Markdown
Collaborator

@cmraible cmraible commented Apr 3, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 3, 2026

Walkthrough

This pull request introduces feature-flagged email design customization for member welcome emails. The renderer service now accepts optional designSettings and conditionally applies design customizations when the welcomeEmailsDesignCustomization labs flag is enabled. The email template wrapper was updated to optionally render footer content and a "Powered by Ghost" badge. The member welcome email service now loads email design settings from the database and passes them to the renderer. Template helpers and parameters were added to support conditional rendering of header, badge, and footer elements. Comprehensive unit and integration tests verify the feature behavior both when enabled and disabled.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Updated welcome email renderer to use custom design settings' directly and clearly describes the main change in the PR: integrating custom design settings (from the database) into the welcome email renderer.
Description check ✅ Passed The PR description directly references a Linear issue (NY-1197) about using design settings from the database when rendering welcome emails, which aligns with the changeset that implements this feature across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chris-ny-1197-use-design-settings-from-the-database-when-rendering-welcome

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.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 3, 2026

@cmraible
Copy link
Copy Markdown
Collaborator Author

cmraible commented Apr 3, 2026

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 3, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ghost/core/core/server/services/member-welcome-emails/member-welcome-email-renderer.js (1)

219-243: ⚠️ Potential issue | 🟠 Major

Resolve wrapper-level URLs before passing them into the template.

linkReplacer.replace() only normalizes URLs inside the Lexical body. header_image and footer_content are injected afterwards, so any relative /content/images/... or #/portal/... URLs stored in email_design_settings will go out as broken relative URLs in the final email.

🔧 Suggested fix
         const managePreferencesUrl = new URL('#/portal/account/newsletters', siteSettings.url).href;
         const year = new Date().getFullYear();
-        const headerImage = useDesignCustomization ? (designSettings.header_image || null) : null;
+        const headerImage = useDesignCustomization && designSettings.header_image
+            ? new URL(designSettings.header_image, siteSettings.url).href
+            : null;
+        const footerContent = useDesignCustomization && designSettings.footer_content
+            ? await linkReplacer.replace(designSettings.footer_content, (url) => url, {base: siteSettings.url})
+            : null;
         const showHeaderTitle = useDesignCustomization ? designSettings.show_header_title !== false : false;
         const showBadge = useDesignCustomization ? designSettings.show_badge !== false : false;

         const html = this.#wrapperTemplate({
             content: contentWithAbsoluteLinks,
             emailTitle: subjectWithReplacements,
             subject: subjectWithReplacements,
-            footerContent: useDesignCustomization ? designSettings.footer_content : null,
+            footerContent,
             hasHeaderContent: Boolean(headerImage || showHeaderTitle),
             headerImage,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@ghost/core/core/server/services/member-welcome-emails/member-welcome-email-renderer.js`
around lines 219 - 243, The wrapper-level assets (header_image and
footer_content) are not being URL-normalized before passing into
this.#wrapperTemplate, so relative URLs stored in designSettings will remain
broken; update the code to resolve those before templating by converting
headerImage to an absolute URL (e.g., if headerImage is a string use new
URL(headerImage, siteSettings.url).href or equivalent) and run
linkReplacer.replace on designSettings.footer_content (and any other wrapper
HTML like managePreferencesUrl if it can be relative) so footer_content and
headerImage are passed into this.#wrapperTemplate as absolute/normalized URLs
instead of raw relative values.
🧹 Nitpick comments (1)
ghost/core/test/integration/services/member-welcome-emails.test.js (1)

441-467: Restore the shared design-settings row inside this test.

This suite seeds default-automated-email once in before. Mutating it inline makes the test order-dependent if more cases are added below later, and it leaves dirty state behind if an assertion throws before suite teardown.

♻️ Suggested cleanup
         const memberWelcomeEmailService = require('../../../core/server/services/member-welcome-emails/service');
         memberWelcomeEmailService.init();

         await memberWelcomeEmailService.api.loadMemberWelcomeEmails();

+        const originalDesignSettings = await db.knex('email_design_settings')
+            .where('id', defaultEmailDesignSettingId)
+            .first('footer_content', 'show_badge');
+
+        try {
             await db.knex('email_design_settings')
                 .where('id', defaultEmailDesignSettingId)
                 .update({
                     footer_content: '<p>Fresh footer content</p>',
                     show_badge: false
                 });

             await memberWelcomeEmailService.api.send({
                 member: {
                     email: 'fresh-design@example.com',
                     name: 'Fresh Design',
                     uuid: '77777777-7777-4777-8777-777777777777'
                 },
                 memberStatus: 'free'
             });

             sinon.assert.calledOnce(mailService.GhostMailer.prototype.send);
             const sendCall = mailService.GhostMailer.prototype.send.firstCall;
             assert.ok(sendCall.args[0].html.includes('Fresh footer content</p>'));
             assert.equal(sendCall.args[0].html.includes('https://ghost.org/?via=pbg-newsletter'), false);
+        } finally {
+            await db.knex('email_design_settings')
+                .where('id', defaultEmailDesignSettingId)
+                .update(originalDesignSettings);
+        }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ghost/core/test/integration/services/member-welcome-emails.test.js` around
lines 441 - 467, This test mutates the shared email_design_settings row
(identified by defaultEmailDesignSettingId) and leaves global state dirty;
before updating via db.knex(...).update(...) in the test, read and store the
original row (e.g., const original = await
db.knex('email_design_settings').where('id',
defaultEmailDesignSettingId').first()) and then after the assertion restore it
(or use a try/finally around the update/send/assert block) by writing the
original values back with db.knex(...).where('id',
defaultEmailDesignSettingId').update(original) so the shared design-settings row
is always restored even if an assertion throws. Ensure the code references the
same defaultEmailDesignSettingId and the memberWelcomeEmailService.api.send call
remains unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In
`@ghost/core/core/server/services/member-welcome-emails/member-welcome-email-renderer.js`:
- Around line 219-243: The wrapper-level assets (header_image and
footer_content) are not being URL-normalized before passing into
this.#wrapperTemplate, so relative URLs stored in designSettings will remain
broken; update the code to resolve those before templating by converting
headerImage to an absolute URL (e.g., if headerImage is a string use new
URL(headerImage, siteSettings.url).href or equivalent) and run
linkReplacer.replace on designSettings.footer_content (and any other wrapper
HTML like managePreferencesUrl if it can be relative) so footer_content and
headerImage are passed into this.#wrapperTemplate as absolute/normalized URLs
instead of raw relative values.

---

Nitpick comments:
In `@ghost/core/test/integration/services/member-welcome-emails.test.js`:
- Around line 441-467: This test mutates the shared email_design_settings row
(identified by defaultEmailDesignSettingId) and leaves global state dirty;
before updating via db.knex(...).update(...) in the test, read and store the
original row (e.g., const original = await
db.knex('email_design_settings').where('id',
defaultEmailDesignSettingId').first()) and then after the assertion restore it
(or use a try/finally around the update/send/assert block) by writing the
original values back with db.knex(...).where('id',
defaultEmailDesignSettingId').update(original) so the shared design-settings row
is always restored even if an assertion throws. Ensure the code references the
same defaultEmailDesignSettingId and the memberWelcomeEmailService.api.send call
remains unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5cb03195-69b1-4cba-9a68-4ead4d315990

📥 Commits

Reviewing files that changed from the base of the PR and between d8137f1 and e5e38ab.

⛔ Files ignored due to path filters (1)
  • ghost/core/test/integration/services/__snapshots__/member-welcome-emails-snapshot.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (7)
  • ghost/core/core/server/services/member-welcome-emails/email-templates/wrapper.hbs
  • ghost/core/core/server/services/member-welcome-emails/member-welcome-email-renderer.js
  • ghost/core/core/server/services/member-welcome-emails/service.js
  • ghost/core/test/integration/services/member-welcome-emails-snapshot.test.js
  • ghost/core/test/integration/services/member-welcome-emails.test.js
  • ghost/core/test/unit/server/services/member-welcome-emails/member-welcome-email-renderer.test.js
  • ghost/core/test/unit/server/services/member-welcome-emails/service.test.js

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.

1 participant