Fixed member import with created_at in the future (#16580)

closes TryGhost/Team#2793

- if a member is imported with a created_at in the future, the member
will not appear in the members list in admin
- this commit updates created_at to the current date if it is in the
future upon import
This commit is contained in:
Chris Raible 2023-04-06 23:01:23 -07:00 committed by GitHub
parent 7552873072
commit af1ff7902e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View File

@ -124,12 +124,16 @@ module.exports = class MembersCSVImporter {
};
try {
// If the member is created in the future, set created_at to now
// Members created in the future will not appear in admin members list
// Refs https://github.com/TryGhost/Team/issues/2793
const createdAt = moment(row.created_at).isAfter(moment()) ? moment().toDate() : row.created_at;
const memberValues = {
email: row.email,
name: row.name,
note: row.note,
subscribed: row.subscribed,
created_at: row.created_at,
created_at: createdAt,
labels: row.labels
};
const existingMember = await membersRepository.get({email: memberValues.email}, {

View File

@ -0,0 +1,3 @@
id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at,labels,tiers
634e48e056ef99c6a7af5850,timetraveler@example.com,"From the cuture","a note",true,true,,9999-10-18T06:34:08.000Z,,"user import label",This is a Bronze Tier
1 id email name note subscribed_to_emails complimentary_plan stripe_customer_id created_at deleted_at labels tiers
2 634e48e056ef99c6a7af5850 timetraveler@example.com From the cuture a note true true 9999-10-18T06:34:08.000Z user import label This is a Bronze Tier

View File

@ -324,5 +324,24 @@ describe('Importer', function () {
assert.equal(result.imported, 2);
assert.equal(result.errors.length, 0);
});
it ('handles various special cases', async function () {
const importer = buildMockImporterInstance();
const result = await importer.perform(`${csvPath}/special-cases.csv`);
// CASE: Member has created_at in the future
// The member will not appear in the members list in admin
// In this case, we should overwrite create_at to current timestamp
// Refs: https://github.com/TryGhost/Team/issues/2793
assert.equal(membersRepositoryStub.create.args[0][0].email, 'timetraveler@example.com');
assert.equal(membersRepositoryStub.create.args[0][0].subscribed, true);
assert.notDeepEqual(membersRepositoryStub.create.args[0][0].created_at, '9999-10-18T06:34:08.000Z');
assert.equal(membersRepositoryStub.create.args[0][0].created_at <= new Date(), true);
assert.equal(result.total, 1);
assert.equal(result.imported, 1);
assert.equal(result.errors.length, 0);
});
});
});