From da3620ca8eb8eab66b6d8bc058ed370ec3c02ebb Mon Sep 17 00:00:00 2001 From: Naz Date: Tue, 20 Jul 2021 19:31:22 +0400 Subject: [PATCH] Refactored url-uitls 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 | 11 ++++++----- core/server/services/members/service.js | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/server/services/members/importer/importer.js b/core/server/services/members/importer/importer.js index ca71fc616d..1ab3e31a21 100644 --- a/core/server/services/members/importer/importer.js +++ b/core/server/services/members/importer/importer.js @@ -5,7 +5,6 @@ const membersCSV = require('@tryghost/members-csv'); const errors = require('@tryghost/errors'); const tpl = require('@tryghost/tpl'); -const urlUtils = require('../../../../shared/url-utils'); const emailTemplate = require('./email-template'); const messages = { @@ -19,12 +18,13 @@ module.exports = class MembersCSVImporter { * @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} getMembersApi - * @param {Object} ghostMailer - An instance of GhostMailer + * @param {Object} ghostMailer - An instance of GhostMailer * @param {(string) => boolean} isSet - Method checking if specific feature is enabled * @param {({name, at, job, data, offloaded}) => void} addJob - Method registering an async job * @param {Object} knex - An instance of the Ghost Database connection + * @param {Function} urlFor - function generating urls */ - constructor(config, settingsCache, getMembersApi, ghostMailer, isSet, addJob, knex) { + constructor(config, settingsCache, getMembersApi, ghostMailer, isSet, addJob, knex, urlFor) { this._storagePath = config.storagePath; this._settingsCache = settingsCache; this._getMembersApi = getMembersApi; @@ -32,6 +32,7 @@ module.exports = class MembersCSVImporter { this._isSet = isSet; this._addJob = addJob; this._knex = knex; + this._urlFor = urlFor; } /** @@ -212,8 +213,8 @@ module.exports = class MembersCSVImporter { } generateCompletionEmail(result, data) { - const siteUrl = new URL(urlUtils.urlFor('home', null, true)); - const membersUrl = new URL('members', urlUtils.urlFor('admin', null, true)); + const siteUrl = new URL(this._urlFor('home', null, true)); + const membersUrl = new URL('members', this._urlFor('admin', null, true)); if (data.importLabel) { membersUrl.searchParams.set('label', data.importLabel.slug); } diff --git a/core/server/services/members/service.js b/core/server/services/members/service.js index 8acc59d707..857cc29bb8 100644 --- a/core/server/services/members/service.js +++ b/core/server/services/members/service.js @@ -135,7 +135,8 @@ const membersService = { ghostMailer, labsService.isSet, jobsService.addJob, - db.knex + db.knex, + urlUtils.urlFor ), stats: new MembersStats({