From 81de2fe223e47255899523a113b63b1423c2de14 Mon Sep 17 00:00:00 2001 From: Fabien 'egg' O'Carroll Date: Thu, 3 Jun 2021 18:28:14 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20saving=20Members=20w?= =?UTF-8?q?ith=20Complimentary=20plans=20(#13008)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛 Fixed saving Members with Complimentary plans refs https://github.com/TryGhost/Team/issues/758 Since 4.6 The Admin is using the comped flag again, rather than creating subscriptions for zero-amount prices directly. With the `comped` flag removed, the default state was for it to be falsy in the Admin, and when saved would trigger the legacy comped flow, cancelling the subscription. This reverts commit 57a176ff3d18b58db635d20d397412741b53a627. --- .../canary/utils/serializers/output/members.js | 16 ++++++++++++++++ test/api-acceptance/admin/members_spec.js | 2 ++ test/api-acceptance/admin/utils.js | 1 + test/regression/api/canary/admin/members_spec.js | 3 +++ test/regression/api/canary/admin/utils.js | 3 ++- 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/server/api/canary/utils/serializers/output/members.js b/core/server/api/canary/utils/serializers/output/members.js index ec292b1ae3..eaf8382c37 100644 --- a/core/server/api/canary/utils/serializers/output/members.js +++ b/core/server/api/canary/utils/serializers/output/members.js @@ -79,6 +79,20 @@ function exportCSV(page, _apiConfig, frame) { function serializeMember(member, options) { const json = member.toJSON(options); + let comped = false; + if (json.subscriptions) { + const hasCompedSubscription = !!json.subscriptions.find( + /** + * @param {SerializedMemberStripeSubscription} sub + */ + function (sub) { + return sub.plan.nickname === 'Complimentary' && sub.status === 'active'; + } + ); + if (hasCompedSubscription) { + comped = true; + } + } const subscriptions = json.subscriptions || []; const serialized = { @@ -94,6 +108,7 @@ function serializeMember(member, options) { labels: json.labels, subscriptions: subscriptions, avatar_image: json.avatar_image, + comped: comped, email_count: json.email_count, email_opened_count: json.email_opened_count, email_open_rate: json.email_open_rate, @@ -148,6 +163,7 @@ function createSerializer(debugString, serialize) { * @prop {SerializedMemberStripeSubscription[]} subscriptions * @prop {SerializedMemberProduct[]=} products * @prop {string} avatar_image + * @prop {boolean} comped * @prop {number} email_count * @prop {number} email_opened_count * @prop {number} email_open_rate diff --git a/test/api-acceptance/admin/members_spec.js b/test/api-acceptance/admin/members_spec.js index 7b3977f8c8..9e2ef79f5a 100644 --- a/test/api-acceptance/admin/members_spec.js +++ b/test/api-acceptance/admin/members_spec.js @@ -358,6 +358,7 @@ describe('Members API', function () { importedMember1.subscribed.should.equal(true); importedMember1.labels.length.should.equal(1); testUtils.API.isISO8601(importedMember1.created_at).should.be.true(); + importedMember1.comped.should.equal(false); importedMember1.subscriptions.should.not.be.undefined(); importedMember1.subscriptions.length.should.equal(0); @@ -369,6 +370,7 @@ describe('Members API', function () { importedMember2.labels.length.should.equal(2); testUtils.API.isISO8601(importedMember2.created_at).should.be.true(); importedMember2.created_at.should.equal('1991-10-02T20:30:31.000Z'); + importedMember2.comped.should.equal(false); importedMember2.subscriptions.should.not.be.undefined(); importedMember2.subscriptions.length.should.equal(0); }); diff --git a/test/api-acceptance/admin/utils.js b/test/api-acceptance/admin/utils.js index b92368e4f1..be6aa7827f 100644 --- a/test/api-acceptance/admin/utils.js +++ b/test/api-acceptance/admin/utils.js @@ -127,6 +127,7 @@ const expectedProperties = { member: _(schema.members) .keys() .concat('avatar_image') + .concat('comped') .concat('labels') , member_signin_url: ['member_id', 'url'], diff --git a/test/regression/api/canary/admin/members_spec.js b/test/regression/api/canary/admin/members_spec.js index df85acc885..d62723942c 100644 --- a/test/regression/api/canary/admin/members_spec.js +++ b/test/regression/api/canary/admin/members_spec.js @@ -366,6 +366,7 @@ describe('Members API (canary)', function () { should(importedMember1.name).equal(null); should(importedMember1.note).equal(null); importedMember1.subscribed.should.equal(true); + importedMember1.comped.should.equal(false); importedMember1.subscriptions.should.not.be.undefined(); importedMember1.subscriptions.length.should.equal(0); @@ -432,6 +433,7 @@ describe('Members API (canary)', function () { should(importedMember1.name).equal('Hannah'); should(importedMember1.note).equal('no need to map me'); importedMember1.subscribed.should.equal(true); + importedMember1.comped.should.equal(false); importedMember1.subscriptions.should.not.be.undefined(); importedMember1.subscriptions.length.should.equal(0); importedMember1.labels.length.should.equal(1); // auto-generated import label @@ -476,6 +478,7 @@ describe('Members API (canary)', function () { should(defaultMember1.name).equal(null); should(defaultMember1.note).equal(null); defaultMember1.subscribed.should.equal(true); + defaultMember1.comped.should.equal(false); defaultMember1.subscriptions.should.not.be.undefined(); defaultMember1.subscriptions.length.should.equal(0); defaultMember1.labels.length.should.equal(1); // auto-generated import label diff --git a/test/regression/api/canary/admin/utils.js b/test/regression/api/canary/admin/utils.js index 2539b34395..94d2807a12 100644 --- a/test/regression/api/canary/admin/utils.js +++ b/test/regression/api/canary/admin/utils.js @@ -134,7 +134,8 @@ const expectedProperties = { 'created_at', 'updated_at', 'avatar_image', - 'labels' + 'labels', + 'comped' ], member_signin_url: ['member_id', 'url'], role: ['id', 'name', 'description', 'created_at', 'updated_at'], From 625406ede5f0e2947b626ee9304ece0ac932c511 Mon Sep 17 00:00:00 2001 From: Sam Lord Date: Mon, 7 Jun 2021 11:25:17 +0100 Subject: [PATCH 2/3] Updated Ghost-Admin to v4.6.5 --- core/client | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/client b/core/client index 13fc1c7005..8c952ff834 160000 --- a/core/client +++ b/core/client @@ -1 +1 @@ -Subproject commit 13fc1c7005f3d6c17f324bef7fe9204f62d6a891 +Subproject commit 8c952ff834b8606b855e694f674293117d7680fd From 4de81087ccd70406b6a73eb6306aeb87c800fcf8 Mon Sep 17 00:00:00 2001 From: Sam Lord Date: Mon, 7 Jun 2021 11:25:17 +0100 Subject: [PATCH 3/3] v4.6.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cd78fffc43..82f20692e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ghost", - "version": "4.6.4", + "version": "4.6.5", "description": "The professional publishing platform", "author": "Ghost Foundation", "homepage": "https://ghost.org",