From 840deaf8d7fd7836208bf585bf59f0f8873ed77b Mon Sep 17 00:00:00 2001 From: Naz Date: Mon, 24 Oct 2022 18:03:44 +0800 Subject: [PATCH] Restricted members importer to ignore "products" column refs https://github.com/TryGhost/Team/issues/1076 refs https://github.com/TryGhost/Ghost/commit/70229e4fd328b3890f4cd02246b0ba77b510ff48#diff-b67ecda91b5bd79c598e5c5a9ec2ccf28dbfab6a924b21352273865e07cd7ceaR57 - The "products" column has not been doing any logic anything since at least 5.20.0 (see refed commit). The concept of columns in the export file was mostly there for analytical/data filtering reasons - so the user could analyze their exports. CSV was never a good suite for relational data that "products" (or now tiers) represent - The "tiers" column will still be present in the exported CSV file, but there is not going to be any logic attached to it. - The only columns that can effect the "tiers" state of the member are: "complimentary_plan" (assign default tier to the member) and "stripe_customer_id" (pulls in subscription/tier data from Stripe) --- ghost/members-csv/lib/parse.js | 6 ------ ghost/members-csv/test/unparse.test.js | 2 +- ghost/members-importer/lib/importer.js | 17 +++-------------- .../test/fixtures/member-csv-export.csv | 2 +- ghost/members-importer/test/importer.test.js | 5 ++--- 5 files changed, 7 insertions(+), 25 deletions(-) diff --git a/ghost/members-csv/lib/parse.js b/ghost/members-csv/lib/parse.js index 16add0b831..a2a4df5ccf 100644 --- a/ghost/members-csv/lib/parse.js +++ b/ghost/members-csv/lib/parse.js @@ -29,12 +29,6 @@ module.exports = (path, headerMapping, defaultLabels = []) => { } } - if (header === 'products') { - if (value && typeof value === 'string') { - return value.split(',').map(name => ({name})); - } - } - if (header === 'subscribed') { return value.toLowerCase() !== 'false'; } diff --git a/ghost/members-csv/test/unparse.test.js b/ghost/members-csv/test/unparse.test.js index 41b7ecdd1f..89154778c2 100644 --- a/ghost/members-csv/test/unparse.test.js +++ b/ghost/members-csv/test/unparse.test.js @@ -87,7 +87,7 @@ third-member-email@email.com,"banana, avocado"`; assert.equal(result, expected); }); - it('handles the tiers to products property serialization', function () { + it('handles the tiers property serialization', function () { const json = [{ email: 'member-email@email.com', tiers: [{ diff --git a/ghost/members-importer/lib/importer.js b/ghost/members-importer/lib/importer.js index 351491cd61..d7745082b8 100644 --- a/ghost/members-importer/lib/importer.js +++ b/ghost/members-importer/lib/importer.js @@ -21,9 +21,9 @@ const DEFAULT_CSV_HEADER_MAPPING = { created_at: 'created_at', complimentary_plan: 'complimentary_plan', stripe_customer_id: 'stripe_customer_id', - labels: 'labels', - products: 'products' + labels: 'labels' }; + module.exports = class MembersCSVImporter { /** * @param {Object} options @@ -159,19 +159,8 @@ module.exports = class MembersCSVImporter { member_id: member.id }, options); } else if (row.complimentary_plan) { - if (!row.products) { - await membersApi.members.update({ - products: [{id: defaultProduct.id}] - }, { - ...options, - id: member.id - }); - } - } - - if (row.products) { await membersApi.members.update({ - products: row.products + products: [{id: defaultProduct.id}] }, { ...options, id: member.id diff --git a/ghost/members-importer/test/fixtures/member-csv-export.csv b/ghost/members-importer/test/fixtures/member-csv-export.csv index 3b009d6dc3..827cf1859c 100644 --- a/ghost/members-importer/test/fixtures/member-csv-export.csv +++ b/ghost/members-importer/test/fixtures/member-csv-export.csv @@ -1,3 +1,3 @@ -id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at,labels,products +id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at,labels,tiers 634e48e056ef99c6a7af5850,member_complimentary_test@example.com,"bobby tables","a note",true,true,,2022-10-18T06:34:08.000Z,,"user import label",This is a Bronze Tier 634e566dde68acf282cd311e,member_stripe_test@example.com,"stirpey beaver","testing notes",false,,cus_MdR9tqW6bAreiq,2022-10-18T07:31:57.000Z,,,This is a Premium Tier diff --git a/ghost/members-importer/test/importer.test.js b/ghost/members-importer/test/importer.test.js index 98fdcad1bb..9fb4109302 100644 --- a/ghost/members-importer/test/importer.test.js +++ b/ghost/members-importer/test/importer.test.js @@ -25,8 +25,7 @@ describe('Importer', function () { created_at: 'created_at', complimentary_plan: 'complimentary_plan', stripe_customer_id: 'stripe_customer_id', - labels: 'labels', - products: 'products' + labels: 'labels' }; beforeEach(function () { @@ -201,7 +200,7 @@ describe('Importer', function () { should.equal(membersApiStub.members.linkStripeCustomer.args[0][0].customer_id, 'cus_MdR9tqW6bAreiq'); should.equal(membersApiStub.members.linkStripeCustomer.args[0][0].member_id, 'test_member_id'); - // products import + // complimentary_plan import membersApiStub.members.update.calledOnce.should.be.true(); should.deepEqual(membersApiStub.members.update.args[0][0].products, [{ id: 'default_product_id'