0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Added email settings links to point to Admin X (#17883)

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.

---

<!-- Leave the line below if you'd like GitHub Copilot to generate a
summary from your commit -->
<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at e532a0d</samp>

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.
This commit is contained in:
Ronald Langeveld 2023-08-31 16:16:45 +07:00 committed by GitHub
parent eab974687f
commit 37512a712d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 8 deletions

View file

@ -22,7 +22,8 @@ class StaffService {
mailer,
settingsHelpers,
settingsCache,
urlUtils
urlUtils,
labs
});
}

View file

@ -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,