mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-03 00:15:11 +03:00
🐛 Fixed member CSV import setting subscribed to true
as default
no issue - When importing through CSV we should remain the defaults of 'subscribed' fields (`true` at the moment), unless it is explicitly set to `false` or `FALSE` (the latter uppercase value often comes from scpredsheets)
This commit is contained in:
parent
28071a242a
commit
6db07ce34d
@ -343,13 +343,21 @@ const members = {
|
||||
entry.labels = (entry.labels && entry.labels.split(',')) || [];
|
||||
const entryLabels = serializeMemberLabels(entry.labels);
|
||||
cleanupUndefined(entry);
|
||||
|
||||
let subscribed;
|
||||
if (_.isUndefined(entry.subscribed_to_emails)) {
|
||||
subscribed = entry.subscribed_to_emails;
|
||||
} else {
|
||||
subscribed = (String(entry.subscribed_to_emails).toLowerCase() !== 'false');
|
||||
}
|
||||
|
||||
return Promise.resolve(api.members.add.query({
|
||||
data: {
|
||||
members: [{
|
||||
email: entry.email,
|
||||
name: entry.name,
|
||||
note: entry.note,
|
||||
subscribed: (String(entry.subscribed_to_emails).toLowerCase() === 'true'),
|
||||
subscribed: subscribed,
|
||||
stripe_customer_id: entry.stripe_customer_id,
|
||||
comped: (String(entry.complimentary_plan).toLocaleLowerCase() === 'true'),
|
||||
labels: entryLabels
|
||||
|
@ -304,6 +304,55 @@ describe('Members API', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Can import CSV with minimum one field', function () {
|
||||
return request
|
||||
.post(localUtils.API.getApiQuery(`members/csv/`))
|
||||
.attach('membersfile', path.join(__dirname, '/../../../../utils/fixtures/csv/valid-members-defaults.csv'))
|
||||
.set('Origin', config.get('url'))
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(201)
|
||||
.then((res) => {
|
||||
should.not.exist(res.headers['x-cache-invalidate']);
|
||||
const jsonResponse = res.body;
|
||||
|
||||
should.exist(jsonResponse);
|
||||
should.exist(jsonResponse.meta);
|
||||
should.exist(jsonResponse.meta.stats);
|
||||
|
||||
jsonResponse.meta.stats.imported.should.equal(2);
|
||||
jsonResponse.meta.stats.duplicates.should.equal(0);
|
||||
jsonResponse.meta.stats.invalid.should.equal(0);
|
||||
})
|
||||
.then(() => {
|
||||
return request
|
||||
.get(localUtils.API.getApiQuery(`members/`))
|
||||
.set('Origin', config.get('url'))
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(200);
|
||||
})
|
||||
.then((res) => {
|
||||
should.not.exist(res.headers['x-cache-invalidate']);
|
||||
const jsonResponse = res.body;
|
||||
|
||||
should.exist(jsonResponse);
|
||||
should.exist(jsonResponse.members);
|
||||
|
||||
const defaultMember1 = jsonResponse.members.find(member => (member.email === 'member+defaults_1@example.com'));
|
||||
should(defaultMember1.name).equal(null);
|
||||
should(defaultMember1.note).equal(null);
|
||||
defaultMember1.subscribed.should.equal(true);
|
||||
defaultMember1.comped.should.equal(false);
|
||||
defaultMember1.stripe.should.not.be.undefined();
|
||||
defaultMember1.stripe.subscriptions.length.should.equal(0);
|
||||
defaultMember1.labels.length.should.equal(0);
|
||||
|
||||
const defaultMember2 = jsonResponse.members.find(member => (member.email === 'member+defaults_2@example.com'));
|
||||
should(defaultMember2).not.be.undefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('Can import file with duplicate stripe customer ids', function () {
|
||||
return request
|
||||
.post(localUtils.API.getApiQuery(`members/csv/`))
|
||||
|
3
core/test/utils/fixtures/csv/valid-members-defaults.csv
Normal file
3
core/test/utils/fixtures/csv/valid-members-defaults.csv
Normal file
@ -0,0 +1,3 @@
|
||||
email
|
||||
member+defaults_1@example.com
|
||||
member+defaults_2@example.com
|
|
Loading…
Reference in New Issue
Block a user