From 37512a712de48ed9a611f0cec3c3fce2820118e2 Mon Sep 17 00:00:00 2001 From: Ronald Langeveld Date: Thu, 31 Aug 2023 16:16:45 +0700 Subject: [PATCH] Added email settings links to point to Admin X (#17883) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs https://github.com/TryGhost/Product/issues/3349 - added conditions to change the url links to point admin X in staff emails where the user have admin X enabled in Labs. --- ### 🤖 Generated by Copilot at e532a0d This pull request enables the staff service to support the new admin settings UI feature flag. It modifies the `StaffServiceEmails` and `StaffService` modules to use the `labs` dependency and generate the staff URL accordingly. It also updates the email templates that include the staff URL. --- ghost/staff-service/lib/StaffService.js | 3 +- ghost/staff-service/lib/StaffServiceEmails.js | 48 ++++++++++++++++--- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/ghost/staff-service/lib/StaffService.js b/ghost/staff-service/lib/StaffService.js index 6c90f58f79..c4becf8369 100644 --- a/ghost/staff-service/lib/StaffService.js +++ b/ghost/staff-service/lib/StaffService.js @@ -22,7 +22,8 @@ class StaffService { mailer, settingsHelpers, settingsCache, - urlUtils + urlUtils, + labs }); } diff --git a/ghost/staff-service/lib/StaffServiceEmails.js b/ghost/staff-service/lib/StaffServiceEmails.js index bb2d463ff3..75f1657d0b 100644 --- a/ghost/staff-service/lib/StaffServiceEmails.js +++ b/ghost/staff-service/lib/StaffServiceEmails.js @@ -4,13 +4,14 @@ const moment = require('moment'); const glob = require('glob'); class StaffServiceEmails { - constructor({logging, models, mailer, settingsHelpers, settingsCache, urlUtils}) { + constructor({logging, models, mailer, settingsHelpers, settingsCache, urlUtils, labs}) { this.logging = logging; this.models = models; this.mailer = mailer; this.settingsHelpers = settingsHelpers; this.settingsCache = settingsCache; this.urlUtils = urlUtils; + this.labs = labs; this.Handlebars = require('handlebars'); this.registerPartials(); @@ -33,6 +34,12 @@ class StaffServiceEmails { attributionTitle = 'Homepage'; } + let staffUrl = this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings/staff/${user.slug}`); + + if (this.labs.isSet('adminXSettings')) { + staffUrl = this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings-x/users/show/${user.slug}`); + } + const templateData = { memberData, attributionTitle, @@ -44,7 +51,7 @@ class StaffServiceEmails { accentColor: this.settingsCache.get('accent_color'), fromEmail: this.fromEmailAddress, toEmail: to, - staffUrl: this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings/staff/${user.slug}`) + staffUrl: staffUrl }; const {html, text} = await this.renderEmailTemplate('new-free-signup', templateData); @@ -87,6 +94,12 @@ class StaffServiceEmails { attributionTitle = 'Homepage'; } + let staffUrl = this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings/staff/${user.slug}`); + + if (this.labs.isSet('adminXSettings')) { + staffUrl = this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings-x/users/show/${user.slug}`); + } + const templateData = { memberData, attributionTitle, @@ -101,7 +114,7 @@ class StaffServiceEmails { accentColor: this.settingsCache.get('accent_color'), fromEmail: this.fromEmailAddress, toEmail: to, - staffUrl: this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings/staff/${user.slug}`) + staffUrl: staffUrl }; const {html, text} = await this.renderEmailTemplate('new-paid-started', templateData); @@ -138,6 +151,12 @@ class StaffServiceEmails { cancellationReason: subscription.cancellationReason || '' }; + let staffUrl = this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings/staff/${user.slug}`); + + if (this.labs.isSet('adminXSettings')) { + staffUrl = this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings-x/users/show/${user.slug}`); + } + const templateData = { memberData, tierData, @@ -148,7 +167,7 @@ class StaffServiceEmails { accentColor: this.settingsCache.get('accent_color'), fromEmail: this.fromEmailAddress, toEmail: to, - staffUrl: this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings/staff/${user.slug}`) + staffUrl: staffUrl }; const {html, text} = await this.renderEmailTemplate('new-paid-cancellation', templateData); @@ -168,6 +187,12 @@ class StaffServiceEmails { * @param {string} recipient.slug */ async getSharedData(recipient) { + let staffUrl = this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings/staff/${recipient.slug}`); + + if (this.labs.isSet('adminXSettings')) { + staffUrl = this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings-x/users/show/${recipient.slug}`); + } + return { siteTitle: this.settingsCache.get('title'), siteUrl: this.urlUtils.getSiteUrl(), @@ -175,7 +200,7 @@ class StaffServiceEmails { accentColor: this.settingsCache.get('accent_color'), fromEmail: this.fromEmailAddress, toEmail: recipient.email, - staffUrl: this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings/staff/${recipient.slug}`) + staffUrl: staffUrl }; } @@ -210,6 +235,10 @@ class StaffServiceEmails { for (const user of users) { const to = user.email; + let staffUrl = this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings/staff/${user.slug}`); + if (this.labs.isSet('adminXSettings')) { + staffUrl = this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings-x/users/show/${user.slug}`); + } const templateData = { siteTitle: this.settingsCache.get('title'), siteUrl: this.urlUtils.getSiteUrl(), @@ -219,7 +248,7 @@ class StaffServiceEmails { partial: `milestones/${milestone.value}`, toEmail: to, adminUrl: this.urlUtils.urlFor('admin', true), - staffUrl: this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings/staff/${user.slug}`) + staffUrl: staffUrl }; const {html, text} = await this.renderEmailTemplate('new-milestone-received', templateData); @@ -263,6 +292,11 @@ class StaffServiceEmails { for (const user of users) { const to = user.email; + let staffUrl = this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings/staff/${user.slug}`); + if (this.labs.isSet('adminXSettings')) { + staffUrl = this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings-x/users/show/${user.slug}`); + } + const templateData = { siteTitle: this.settingsCache.get('title'), siteUrl: this.urlUtils.getSiteUrl(), @@ -270,7 +304,7 @@ class StaffServiceEmails { fromEmail: this.fromEmailAddress, toEmail: to, adminUrl: this.urlUtils.urlFor('admin', true), - staffUrl: this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings/staff/${user.slug}`), + staffUrl: staffUrl, donation: { name: donationPaymentEvent.name ?? donationPaymentEvent.email, email: donationPaymentEvent.email,