mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Included all subscriptions in stripeSubscriptions (#12414)
refs https://github.com/TryGhost/Ghost/issues/12256 We no longer want to filter out cancelled subscriptions, so we are able to remove the whereIn clause of the relation. * Fixed paid flag on member * Fixed content gating for members Now that the subscriptions for a member include all of them, we must explicitly check that the member has an active subscription in order to consider them "paid"
This commit is contained in:
parent
200e83c75d
commit
18b87d9734
6 changed files with 74 additions and 6 deletions
|
@ -133,7 +133,9 @@ function updateLocalTemplateOptions(req, res, next) {
|
|||
firstname: req.member.name && req.member.name.split(' ')[0],
|
||||
avatar_image: req.member.avatar_image,
|
||||
subscriptions: req.member.stripe.subscriptions,
|
||||
paid: req.member.stripe.subscriptions.length !== 0
|
||||
paid: req.member.stripe.subscriptions.filter((subscription) => {
|
||||
return ['active', 'trialing', 'unpaid', 'past_due'].includes(subscription.status);
|
||||
}).length !== 0
|
||||
} : null;
|
||||
|
||||
hbs.updateLocalTemplateOptions(res.locals, _.merge({}, localTemplateOptions, {
|
||||
|
|
|
@ -45,7 +45,7 @@ const Member = ghostBookshelf.Model.extend({
|
|||
'customer_id',
|
||||
'id',
|
||||
'customer_id'
|
||||
).query('whereIn', 'status', ['active', 'trialing', 'past_due', 'unpaid']);
|
||||
);
|
||||
},
|
||||
|
||||
serialize(options) {
|
||||
|
|
|
@ -23,7 +23,10 @@ function checkPostAccess(post, member) {
|
|||
return PERMIT_ACCESS;
|
||||
}
|
||||
|
||||
const memberHasPlan = member.stripe && member.stripe.subscriptions && member.stripe.subscriptions.length;
|
||||
const activeSubscriptions = member.stripe && member.stripe.subscriptions && member.stripe.subscriptions.filter((subscription) => {
|
||||
return ['active', 'trialing', 'unpaid', 'past_due'].includes(subscription.status);
|
||||
});
|
||||
const memberHasPlan = activeSubscriptions && activeSubscriptions.length;
|
||||
|
||||
if (post.visibility === 'paid' && memberHasPlan) {
|
||||
return PERMIT_ACCESS;
|
||||
|
|
|
@ -10,6 +10,8 @@ module.exports.formattedMemberResponse = function formattedMemberResponse(member
|
|||
avatar_image: member.avatar_image,
|
||||
subscribed: !!member.subscribed,
|
||||
subscriptions: member.stripe ? member.stripe.subscriptions : [],
|
||||
paid: member.stripe ? member.stripe.subscriptions.length !== 0 : false
|
||||
paid: member.stripe && member.stripe.subscriptions && member.stripe.subscriptions.filter((subscription) => {
|
||||
return ['active', 'trialing', 'unpaid', 'past_due'].includes(subscription.status);
|
||||
}).length !== 0
|
||||
};
|
||||
};
|
||||
|
|
|
@ -111,6 +111,34 @@ describe('Unit: canary/utils/serializers/output/utils/post-gating', function ()
|
|||
attrs.html.should.eql('');
|
||||
});
|
||||
|
||||
it('should hide content attributes when visibility is "paid" and member has cancelled subscription', function () {
|
||||
const attrs = {
|
||||
visibility: 'paid',
|
||||
plaintext: 'I see dead people',
|
||||
html: '<p>What\'s the matter?</p>'
|
||||
};
|
||||
|
||||
const frame = {
|
||||
options: {},
|
||||
original: {
|
||||
context: {
|
||||
member: {
|
||||
stripe: {
|
||||
subscriptions: [{
|
||||
status: 'canceled'
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
gating.forPost(attrs, frame);
|
||||
|
||||
attrs.plaintext.should.eql('');
|
||||
attrs.html.should.eql('');
|
||||
});
|
||||
|
||||
it('should NOT hide content attributes when visibility is "paid" and member has a subscription', function () {
|
||||
const attrs = {
|
||||
visibility: 'paid',
|
||||
|
@ -124,7 +152,9 @@ describe('Unit: canary/utils/serializers/output/utils/post-gating', function ()
|
|||
context: {
|
||||
member: {
|
||||
stripe: {
|
||||
subscriptions: ['I pay money dollaz']
|
||||
subscriptions: [{
|
||||
status: 'active'
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,6 +107,34 @@ describe('Unit: v2/utils/serializers/output/utils/post-gating', function () {
|
|||
attrs.html.should.eql('');
|
||||
});
|
||||
|
||||
it('should hide content attributes when visibility is "paid" and member has cancelled subscription', function () {
|
||||
const attrs = {
|
||||
visibility: 'paid',
|
||||
plaintext: 'I see dead people',
|
||||
html: '<p>What\'s the matter?</p>'
|
||||
};
|
||||
|
||||
const frame = {
|
||||
options: {},
|
||||
original: {
|
||||
context: {
|
||||
member: {
|
||||
stripe: {
|
||||
subscriptions: [{
|
||||
status: 'canceled'
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
gating.forPost(attrs, frame);
|
||||
|
||||
attrs.plaintext.should.eql('');
|
||||
attrs.html.should.eql('');
|
||||
});
|
||||
|
||||
it('should NOT hide content attributes when visibility is "paid" and member has a subscription', function () {
|
||||
const attrs = {
|
||||
visibility: 'paid',
|
||||
|
@ -115,11 +143,14 @@ describe('Unit: v2/utils/serializers/output/utils/post-gating', function () {
|
|||
};
|
||||
|
||||
const frame = {
|
||||
options: {},
|
||||
original: {
|
||||
context: {
|
||||
member: {
|
||||
stripe: {
|
||||
subscriptions: ['I pay money dollaz']
|
||||
subscriptions: [{
|
||||
status: 'active'
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue