Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fixed free tier showing in the tiers-only paywall in posts #19807

Merged
merged 14 commits into from
Mar 6, 2024
Merged
6 changes: 6 additions & 0 deletions ghost/core/core/server/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,12 @@ Post = ghostBookshelf.Model.extend({
});
}

// If visibility is set to specific tiers, make sure we are only saving paid tiers
if (this.get('visibility') === 'tiers' && this.get('tiers')) {
const paidTiers = this.get('tiers').filter(t => t.type === 'paid');
this.set('tiers', paidTiers);
}
sagzy marked this conversation as resolved.
Show resolved Hide resolved

if (this.get('tiers')) {
this.set('tiers', this.get('tiers').map(t => ({
id: t.id
Expand Down
14 changes: 8 additions & 6 deletions ghost/core/test/e2e-api/admin/pages-bulk.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ describe('Pages Bulk API', function () {

const products = await models.Product.findAll();

const tier1 = products.models[0];
const tier2 = products.models[1];
const freeTier = products.models[0];
const paidTier = products.models[1];

assert(tier1.id && tier2.id);
assert(freeTier.id && paidTier.id);

// Check all the pages that should be affected
const changedPages = await models.Post.findPage({filter: forcePageFilter(filter), limit: 1, status: 'all'});
Expand All @@ -144,10 +144,12 @@ describe('Pages Bulk API', function () {
visibility: 'tiers',
tiers: [
{
id: tier1.id
id: freeTier.id,
type: freeTier.get('type')
sagzy marked this conversation as resolved.
Show resolved Hide resolved
},
{
id: tier2.id
id: paidTier.id,
type: paidTier.get('type')
}
]
}
Expand All @@ -164,7 +166,7 @@ describe('Pages Bulk API', function () {

for (const page of pages) {
assert(page.get('visibility') === 'tiers', `Expect page ${page.id} to have access 'tiers'`);
assert.equal(page.related('tiers').length, 2);
assert.equal(page.related('tiers').length, 1); // Only the paid tier, not the free tier
}
});

Expand Down
14 changes: 8 additions & 6 deletions ghost/core/test/e2e-api/admin/posts-bulk.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ describe('Posts Bulk API', function () {

const products = await models.Product.findAll();

const tier1 = products.models[0];
const tier2 = products.models[1];
const freeTier = products.models[0];
const paidTier = products.models[1];

assert(tier1.id && tier2.id);
assert(freeTier.id && paidTier.id);

// Check all the posts that should be affected
const changedPosts = await models.Post.findPage({filter, limit: 1, status: 'all'});
Expand All @@ -179,10 +179,12 @@ describe('Posts Bulk API', function () {
visibility: 'tiers',
tiers: [
{
id: tier1.id
id: freeTier.id,
type: freeTier.get('type')
sagzy marked this conversation as resolved.
Show resolved Hide resolved
},
{
id: tier2.id
id: paidTier.id,
type: paidTier.get('type')
}
]
}
Expand All @@ -199,7 +201,7 @@ describe('Posts Bulk API', function () {

for (const post of posts) {
assert(post.get('visibility') === 'tiers', `Expect post ${post.id} to have access 'tiers'`);
assert.equal(post.related('tiers').length, 2);
assert.equal(post.related('tiers').length, 1); // Only the paid tier, not the free tier
}
});

Expand Down
3 changes: 2 additions & 1 deletion ghost/core/test/e2e-api/members-comments/comments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,8 @@ describe('Comments API', function () {
visibility: 'tiers',
tiers: [
{
id: product.id
id: product.id,
type: product.get('type')
sagzy marked this conversation as resolved.
Show resolved Hide resolved
}
]
}, {id: post.id});
Expand Down
2 changes: 1 addition & 1 deletion ghost/posts-service/lib/PostsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class PostsService {
message: tpl(messages.invalidTiers)
});
}
tiers = data.meta.tiers;
tiers = data.meta.tiers.filter(t => t.type === 'paid');
}
return await this.#updatePosts({visibility: data.meta.visibility, tiers}, {filter: options.filter, context: options.context});
}
Expand Down
Loading