Skip to content

Commit

Permalink
🐛 Fixed free tier showing in the tiers-only paywall in posts
Browse files Browse the repository at this point in the history
refs INC-36

- The tiers-only paywall was incorrectly rendering "Free". Example: "This post is for subscribers of the Free, Silver and Gold tiers only"
- Steps to reproduce the issue:
    1. Create a post with public visibility, publish it
    2. Then swap the visibility to specific tiers. The default selects all paid tiers. Leave it like that
    3. Update the post. The paywall show Free, even though it should be showing only the paid tiers
- This fix filters out the "free" tier when visibility is set to tiers, before updating a Post. It also throws a loud error when using the bulkEdit action
  • Loading branch information
sagzy committed Mar 6, 2024
1 parent cbb27c2 commit 29ea3ae
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ghost/posts-service/lib/PostsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ class PostsService {
}
}

// If the visibility is set to specific tiers, make sure that only paid tiers can be set
if (frame.data.posts[0] && frame.data.posts[0].visibility === 'tiers' && Array.isArray(frame.data.posts[0].tiers)) {
frame.data.posts[0].tiers = frame.data.posts[0].tiers.filter(t => t.type === 'paid');
}

if (this.isSet('collections') && frame.data.posts[0].collections) {
const existingCollections = await this.collectionsService.getCollectionsForPost(frame.options.id);
for (const collection of frame.data.posts[0].collections) {
Expand Down Expand Up @@ -266,7 +271,7 @@ class PostsService {
}
let tiers = undefined;
if (data.meta.visibility === 'tiers') {
if (!Array.isArray(data.meta.tiers)) {
if (!Array.isArray(data.meta.tiers) || data.meta.tiers.some(tier => tier.type === 'free')) {
throw new errors.IncorrectUsageError({
message: tpl(messages.invalidTiers)
});
Expand Down

0 comments on commit 29ea3ae

Please sign in to comment.