0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

Allow setting context for members importer and use correct source

no issue

When importing members, the members-importer isn't aware of the context and therefore falls back to use `member` as a source in members event table. This makes it impossible to determine imported members from others.
- Added an `context` property to the options in the members-importer constructor
- Checked for `importer` context when creating member events and assigned the source `admin` to it
This commit is contained in:
Aileen Nowak 2022-04-06 15:12:38 -04:00 committed by Aileen Booker
parent a0a50f7acc
commit dd702f6ef8
3 changed files with 12 additions and 6 deletions

View file

@ -228,7 +228,7 @@ module.exports = class MemberRepository {
source = 'import';
} else if (context.internal) {
source = 'system';
} else if (context.user) {
} else if (context.user || context.importer) {
source = 'admin';
} else if (context.api_key) {
source = 'api';

View file

@ -23,8 +23,9 @@ module.exports = class MembersCSVImporter {
* @param {({name, at, job, data, offloaded}) => void} options.addJob - Method registering an async job
* @param {Object} options.knex - An instance of the Ghost Database connection
* @param {Function} options.urlFor - function generating urls
* @param {Object} options.context
*/
constructor({storagePath, getTimezone, getMembersApi, sendEmail, isSet, addJob, knex, urlFor}) {
constructor({storagePath, getTimezone, getMembersApi, sendEmail, isSet, addJob, knex, urlFor, context}) {
this._storagePath = storagePath;
this._getTimezone = getTimezone;
this._getMembersApi = getMembersApi;
@ -33,6 +34,7 @@ module.exports = class MembersCSVImporter {
this._addJob = addJob;
this._knex = knex;
this._urlFor = urlFor;
this._context = context;
}
/**
@ -134,7 +136,8 @@ module.exports = class MembersCSVImporter {
const trx = await this._knex.transaction();
const options = {
transacting: trx
transacting: trx,
context: this._context
};
try {

View file

@ -68,7 +68,8 @@ describe('Importer', function () {
isSet: sinon.stub(),
addJob: sinon.stub(),
knex: knexStub,
urlFor: sinon.stub()
urlFor: sinon.stub(),
context: {importer: true}
});
const result = await importer.process({
@ -112,7 +113,8 @@ describe('Importer', function () {
isSet: sinon.stub(),
addJob: sinon.stub(),
knex: sinon.stub(),
urlFor: sinon.stub()
urlFor: sinon.stub(),
context: {importer: true}
});
const result = await membersImporter.prepare(`${csvPath}/single-column-with-header.csv`);
@ -135,7 +137,8 @@ describe('Importer', function () {
isSet: sinon.stub(),
addJob: sinon.stub(),
knex: sinon.stub(),
urlFor: sinon.stub()
urlFor: sinon.stub(),
context: {importer: true}
});
await membersImporter.prepare(`${csvPath}/single-column-with-header.csv`);