0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-25 02:31:59 -05:00

Moved tier visibility usage from portal settings to tier object

refs https://github.com/TryGhost/Team/issues/1387

We have moved away from the portal_products and portal_plans settings to using the visibility property on tiers to determine whether or not a tier should be visible in Portal. This updates Portal to use new tier visibility property to determine visibility at base API level, and in future we will update to remove all usage of portal settings.
This commit is contained in:
Rishabh 2022-03-07 15:14:38 +05:30
parent 30703842b5
commit ca29b5dc65
2 changed files with 31 additions and 1 deletions

View file

@ -1,3 +1,5 @@
import {transformApiSiteData} from './helpers';
function getAnalyticsMetadata() {
const analyticsTag = document.querySelector('meta[name=ghost-analytics-id]');
const analyticsId = analyticsTag?.content;
@ -339,10 +341,11 @@ function setupGhostApi({siteUrl = window.location.origin}) {
};
api.init = async () => {
const [{site}, member] = await Promise.all([
let [{site}, member] = await Promise.all([
api.site.read(),
api.member.sessionData()
]);
site = transformApiSiteData({site});
return {site, member};
};

View file

@ -188,6 +188,33 @@ export function hasMultipleProductsFeature({site}) {
return !!portalProducts;
}
export function transformApiSiteData({site}) {
if (!site) {
return null;
}
if (site.tiers) {
site.products = site.tiers;
}
// Map tier visibility to old settings
if (site.products?.[0]?.visibility) {
// Map paid tier visibility to portal products
site.portal_products = site.products.filter((p) => {
return p.visibility !== 'none' && p.type === 'paid';
}).map(p => p.id);
// Map free tier visibility to portal plans
const freeProduct = site.products.find(p => p.type === 'free');
site.portal_plans = site.portal_plans?.filter(d => d !== 'free');
if (freeProduct.visibility === 'public') {
site.portal_plans?.push('free');
}
}
return site;
}
export function getAvailableProducts({site}) {
const {portal_products: portalProducts, products = [], portal_plans: portalPlans = []} = site || {};