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,