0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Added use of email templates for version mismatch notifications

refs https://github.com/TryGhost/Toolbox/issues/292

- This change allows to reuse existing pattern present in Ghost on the version mismatch service layer, where we define the contents of the sent email through email templates instead of plain text.
- Apart form templates, there's now failed request URL present in the data passed to the email template along with site title and site url
This commit is contained in:
Naz 2022-05-05 18:23:13 +08:00
parent 38b9cf2472
commit 648530009d
4 changed files with 27 additions and 16 deletions

View file

@ -1,12 +1,13 @@
const routeMatch = require('path-match')();
const APIVersionCompatibilityService = require('@tryghost/api-version-compatibility-service'); const APIVersionCompatibilityService = require('@tryghost/api-version-compatibility-service');
const VersionNotificationsDataService = require('@tryghost/version-notifications-data-service'); const VersionNotificationsDataService = require('@tryghost/version-notifications-data-service');
const versionMismatchHandler = require('@tryghost/mw-api-version-mismatch'); const versionMismatchHandler = require('@tryghost/mw-api-version-mismatch');
const ghostVersion = require('@tryghost/version'); const ghostVersion = require('@tryghost/version');
const {GhostMailer} = require('../mail'); const {GhostMailer} = require('../mail');
const settingsService = require('../../services/settings'); const settingsService = require('../../services/settings');
const urlUtils = require('../../../shared/url-utils');
const models = require('../../models'); const models = require('../../models');
const routeMatch = require('path-match')(); const urlUtils = require('../../../shared/url-utils');
const settingsCache = require('../../../shared/settings-cache');
let serviceInstance; let serviceInstance;
@ -24,7 +25,9 @@ const init = () => {
}, },
fetchEmailsToNotify: versionNotificationsDataService.getNotificationEmails.bind(versionNotificationsDataService), fetchEmailsToNotify: versionNotificationsDataService.getNotificationEmails.bind(versionNotificationsDataService),
fetchHandled: versionNotificationsDataService.fetchNotification.bind(versionNotificationsDataService), fetchHandled: versionNotificationsDataService.fetchNotification.bind(versionNotificationsDataService),
saveHandled: versionNotificationsDataService.saveNotification.bind(versionNotificationsDataService) saveHandled: versionNotificationsDataService.saveNotification.bind(versionNotificationsDataService),
getSiteUrl: () => urlUtils.urlFor('home', true),
getSiteTitle: () => settingsCache.get('title')
}); });
}; };

View file

@ -6,8 +6,7 @@ const sentry = require('../../../../../shared/sentry');
const shared = require('../../../shared'); const shared = require('../../../shared');
const routes = require('./routes'); const routes = require('./routes');
const errorHandler = require('@tryghost/mw-error-handler'); const errorHandler = require('@tryghost/mw-error-handler');
const versionMissmatchHandler = require('@tryghost/mw-api-version-mismatch'); const apiVersionCompatibility = require('../../../../services/api-version-compatibility');
const {APIVersionCompatibilityServiceInstance} = require('../../../../services/api-version-compatibility');
module.exports = function setupApiApp() { module.exports = function setupApiApp() {
debug('Content API canary setup start'); debug('Content API canary setup start');
@ -29,7 +28,7 @@ module.exports = function setupApiApp() {
// API error handling // API error handling
apiApp.use(errorHandler.resourceNotFound); apiApp.use(errorHandler.resourceNotFound);
apiApp.use(versionMissmatchHandler(APIVersionCompatibilityServiceInstance)); apiApp.use(apiVersionCompatibility.errorHandler);
apiApp.use(errorHandler.handleJSONResponse(sentry)); apiApp.use(errorHandler.handleJSONResponse(sentry));
debug('Content API canary setup end'); debug('Content API canary setup end');

View file

@ -58,7 +58,7 @@
"@sentry/node": "6.19.7", "@sentry/node": "6.19.7",
"@tryghost/adapter-manager": "0.2.29", "@tryghost/adapter-manager": "0.2.29",
"@tryghost/admin-api-schema": "2.14.0", "@tryghost/admin-api-schema": "2.14.0",
"@tryghost/api-version-compatibility-service": "0.1.1", "@tryghost/api-version-compatibility-service": "0.2.0",
"@tryghost/bookshelf-plugins": "0.4.1", "@tryghost/bookshelf-plugins": "0.4.1",
"@tryghost/bootstrap-socket": "0.2.18", "@tryghost/bootstrap-socket": "0.2.18",
"@tryghost/color-utils": "0.1.13", "@tryghost/color-utils": "0.1.13",
@ -93,7 +93,7 @@
"@tryghost/members-stripe-service": "0.10.3", "@tryghost/members-stripe-service": "0.10.3",
"@tryghost/metrics": "1.0.11", "@tryghost/metrics": "1.0.11",
"@tryghost/minifier": "0.1.13", "@tryghost/minifier": "0.1.13",
"@tryghost/mw-api-version-mismatch": "0.1.1", "@tryghost/mw-api-version-mismatch": "0.1.3",
"@tryghost/mw-error-handler": "0.2.4", "@tryghost/mw-error-handler": "0.2.4",
"@tryghost/mw-session-from-token": "0.1.30", "@tryghost/mw-session-from-token": "0.1.30",
"@tryghost/nodemailer": "0.3.22", "@tryghost/nodemailer": "0.3.22",

View file

@ -1727,10 +1727,12 @@
"@tryghost/errors" "^1.0.0" "@tryghost/errors" "^1.0.0"
lodash "^4.17.11" lodash "^4.17.11"
"@tryghost/api-version-compatibility-service@0.1.1": "@tryghost/api-version-compatibility-service@0.2.0":
version "0.1.1" version "0.2.0"
resolved "https://registry.yarnpkg.com/@tryghost/api-version-compatibility-service/-/api-version-compatibility-service-0.1.1.tgz#037ec31a745f59577d531abc0e67558fb83b287e" resolved "https://registry.yarnpkg.com/@tryghost/api-version-compatibility-service/-/api-version-compatibility-service-0.2.0.tgz#439cb89ab09f5af276ed2649ba9924122a960ffd"
integrity sha512-NLpSqTQIP4be8keF8L9vwXtoFeiwldH/WNyieMlqjBWVnAEHVpdGqQzEpltDVkIrkti1T6jT2NP0OIddM3GMYQ== integrity sha512-/i0zqxNhZ2yao0EtUiAdgOeEggXJDs+yyGwBP2Kzmt8cpe3hB7FnMvSSPfJDVGowhCEXWsKn4/SWwLB2AY1W3g==
dependencies:
"@tryghost/email-content-generator" "^0.1.1"
"@tryghost/bookshelf-collision@^0.1.22": "@tryghost/bookshelf-collision@^0.1.22":
version "0.1.22" version "0.1.22"
@ -1937,6 +1939,13 @@
dependencies: dependencies:
html-to-text "^5.1.1" html-to-text "^5.1.1"
"@tryghost/email-content-generator@^0.1.1":
version "0.1.1"
resolved "https://registry.yarnpkg.com/@tryghost/email-content-generator/-/email-content-generator-0.1.1.tgz#95bf2eb1cc8e3eb1c3c0e5d7d4950de30aa30811"
integrity sha512-FWtIrmCs3EU+RptoTCElTSoxf/HiAfdVe15tGJIQNArJ7OVAA9dQgHGIgXIiK6cvUYoE6KqxGKX15TJsyXc2rQ==
dependencies:
html-to-text "^5.1.1"
"@tryghost/errors@1.2.10": "@tryghost/errors@1.2.10":
version "1.2.10" version "1.2.10"
resolved "https://registry.yarnpkg.com/@tryghost/errors/-/errors-1.2.10.tgz#b01b16744986005784ffd6916eec48a3e93976a9" resolved "https://registry.yarnpkg.com/@tryghost/errors/-/errors-1.2.10.tgz#b01b16744986005784ffd6916eec48a3e93976a9"
@ -2296,10 +2305,10 @@
dependencies: dependencies:
lodash "^4.17.11" lodash "^4.17.11"
"@tryghost/mw-api-version-mismatch@0.1.1": "@tryghost/mw-api-version-mismatch@0.1.3":
version "0.1.1" version "0.1.3"
resolved "https://registry.yarnpkg.com/@tryghost/mw-api-version-mismatch/-/mw-api-version-mismatch-0.1.1.tgz#913c8941ebe274eac4c3ac872fbe6268534f0003" resolved "https://registry.yarnpkg.com/@tryghost/mw-api-version-mismatch/-/mw-api-version-mismatch-0.1.3.tgz#64304d65d6cf6c92cae270801be466c154932283"
integrity sha512-N1H3P/ua7MCJTQrhFd6RjBFL95pjB+y3Ih1ZyKToBzicU3RShLUsgVlBC7YNaJVGFG/RYCImzlm09QCV8qwgpg== integrity sha512-+J/s4KGnSGZ4LBQCzx2fvkkeyTqeOEJBcfUHOF5726r1L32wQnwJ+WVIS7KHNNPevGSXyZupG4jmyLZub9RGsw==
"@tryghost/mw-error-handler@0.2.4": "@tryghost/mw-error-handler@0.2.4":
version "0.2.4" version "0.2.4"