From f3119cbf77371536b370fa9ec684bd5012b140cf Mon Sep 17 00:00:00 2001 From: Rishabh Garg Date: Fri, 4 Feb 2022 21:00:08 +0530 Subject: [PATCH] Handled default value in post for specific tier content visibility (#14121) refs https://github.com/TryGhost/Team/issues/1071 Default visibility for a post when set to specific tiers needs special handling as data for specific tiers is stored as an array of tiers on a pivot table. This change handles the default visibility for a new post when set to specific tiers to generate the right default values in model. --- core/server/models/post.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/core/server/models/post.js b/core/server/models/post.js index d573bef8e4..ef472d8110 100644 --- a/core/server/models/post.js +++ b/core/server/models/post.js @@ -54,9 +54,20 @@ Post = ghostBookshelf.Model.extend({ */ defaults: function defaults() { let visibility = 'public'; - - if (settingsCache.get('default_content_visibility')) { - visibility = settingsCache.get('default_content_visibility'); + let tiers = []; + const defaultContentVisibility = settingsCache.get('default_content_visibility'); + if (defaultContentVisibility) { + if (defaultContentVisibility === 'tiers') { + const tiersData = settingsCache.get('default_content_visibility_tiers') || []; + visibility = 'tiers', + tiers = tiersData.map((tierId) => { + return { + id: tierId + }; + }); + } else if (defaultContentVisibility !== 'tiers') { + visibility = settingsCache.get('default_content_visibility'); + } } return { @@ -64,6 +75,7 @@ Post = ghostBookshelf.Model.extend({ status: 'draft', featured: false, type: 'post', + tiers, visibility: visibility, email_recipient_filter: 'none' };