From c7edf256f651deb4c7d29c6893357e9f2a10633f Mon Sep 17 00:00:00 2001 From: Naz Date: Tue, 20 Jul 2021 18:42:26 +0400 Subject: [PATCH] Refactored Ghost mailer dependency out of MembersCSVImporter refs https://github.com/TryGhost/Team/issues/916 - The refactor was done follow the DI Constructor pattern and prepare module for extraction --- core/server/services/members/importer/importer.js | 9 +++++---- core/server/services/members/service.js | 9 ++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/core/server/services/members/importer/importer.js b/core/server/services/members/importer/importer.js index 83180ad963..6bbd355a70 100644 --- a/core/server/services/members/importer/importer.js +++ b/core/server/services/members/importer/importer.js @@ -4,7 +4,7 @@ const fs = require('fs-extra'); const membersCSV = require('@tryghost/members-csv'); const errors = require('@tryghost/errors'); const tpl = require('@tryghost/tpl'); -const GhostMailer = require('../../mail').GhostMailer; + const urlUtils = require('../../../../shared/url-utils'); const db = require('../../../data/db'); const emailTemplate = require('./email-template'); @@ -16,18 +16,19 @@ const messages = { jobAlreadyComplete: 'Job is already complete.' }; -const ghostMailer = new GhostMailer(); module.exports = class MembersCSVImporter { /** * @param {Object} config * @param {string} config.storagePath - The path to store CSV's in before importing * @param {Object} settingsCache - An instance of the Ghost Settings Cache + * @param {Object} ghostMailer - An instance of GhostMailer * @param {() => Object} getMembersApi */ - constructor(config, settingsCache, getMembersApi) { + constructor(config, settingsCache, getMembersApi, ghostMailer) { this._storagePath = config.storagePath; this._settingsCache = settingsCache; this._getMembersApi = getMembersApi; + this._ghostMailer = ghostMailer; } /** @@ -289,7 +290,7 @@ module.exports = class MembersCSVImporter { const errorCSV = this.generateErrorCSV(result); const emailSubject = result.imported > 0 ? 'Your member import is complete' : 'Your member import was unsuccessful'; - await ghostMailer.send({ + await this._ghostMailer.send({ to: emailRecipient, subject: emailSubject, html: emailContent, diff --git a/core/server/services/members/service.js b/core/server/services/members/service.js index bda20885b6..6d9af15afa 100644 --- a/core/server/services/members/service.js +++ b/core/server/services/members/service.js @@ -13,6 +13,7 @@ const settingsCache = require('../../../shared/settings-cache'); const config = require('../../../shared/config'); const ghostVersion = require('@tryghost/version'); const _ = require('lodash'); +const {GhostMailer} = require('../mail'); const messages = { noLiveKeysInDevelopment: 'Cannot use live stripe keys in development. Please restart in production mode.', @@ -23,6 +24,8 @@ const messages = { // Bind to settings.edited to update systems based on settings changes, similar to the bridge and models/base/listeners const events = require('../../lib/common/events'); +const ghostMailer = new GhostMailer(); + const membersConfig = new MembersConfigProvider({ config, settingsCache, @@ -122,7 +125,11 @@ const membersService = { stripeConnect: require('./stripe-connect'), - importer: new MembersCSVImporter({storagePath: config.getContentPath('data')}, settingsCache, () => membersApi), + importer: new MembersCSVImporter({ + storagePath: config.getContentPath('data')}, + settingsCache, () => membersApi, + ghostMailer + ), stats: new MembersStats({ db: db,