mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
🐛 Fixed members importer overwriting name and note if left blank (#19663)
fixes ENG-610 - Previously, when importing an existing member, if the name or note field is left blank in the CSV file, this would overwrite (re: delete) the existing name or note in the database. - This change ensures that the name and note fields are only updated if they are not blank in the CSV file.
This commit is contained in:
parent
c2fd22a246
commit
90ebdacabb
2 changed files with 32 additions and 0 deletions
|
@ -178,6 +178,14 @@ module.exports = class MembersCSVImporter {
|
||||||
memberValues.subscribed = false;
|
memberValues.subscribed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't overwrite name or note if they are blank in the file
|
||||||
|
if (!row.name) {
|
||||||
|
memberValues.name = existingMember.name;
|
||||||
|
}
|
||||||
|
if (!row.note) {
|
||||||
|
memberValues.note = existingMember.note;
|
||||||
|
}
|
||||||
|
|
||||||
member = await membersRepository.update({
|
member = await membersRepository.update({
|
||||||
...memberValues,
|
...memberValues,
|
||||||
labels: existingLabels.concat(memberValues.labels)
|
labels: existingLabels.concat(memberValues.labels)
|
||||||
|
|
|
@ -610,6 +610,30 @@ describe('MembersCSVImporter', function () {
|
||||||
assert.deepEqual(membersRepositoryStub.update.args[0][0].newsletters, newsletters);
|
assert.deepEqual(membersRepositoryStub.update.args[0][0].newsletters, newsletters);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not overwrite name or note fields for existing members when left blank in the import file', async function () {
|
||||||
|
const importer = buildMockImporterInstance();
|
||||||
|
|
||||||
|
const member = {
|
||||||
|
name: 'John Bloggs',
|
||||||
|
note: 'A note',
|
||||||
|
related: sinon.stub()
|
||||||
|
};
|
||||||
|
|
||||||
|
member.related.withArgs('labels').returns(null);
|
||||||
|
member.related.withArgs('newsletters').returns({length: 0});
|
||||||
|
|
||||||
|
membersRepositoryStub.get = sinon.stub();
|
||||||
|
|
||||||
|
membersRepositoryStub.get
|
||||||
|
.withArgs({email: 'test@example.com'})
|
||||||
|
.resolves(member);
|
||||||
|
|
||||||
|
await importer.perform(`${csvPath}/single-column-with-header.csv`);
|
||||||
|
|
||||||
|
assert.equal(membersRepositoryStub.update.args[0][0].name, 'John Bloggs');
|
||||||
|
assert.equal(membersRepositoryStub.update.args[0][0].note, 'A note');
|
||||||
|
});
|
||||||
|
|
||||||
it('does not add subscriptions for existing member when they do not have any subscriptions', async function () {
|
it('does not add subscriptions for existing member when they do not have any subscriptions', async function () {
|
||||||
const importer = buildMockImporterInstance();
|
const importer = buildMockImporterInstance();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue