mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
9ff8d7f910
refs https://github.com/TryGhost/Team/issues/1367 Because we are passing through a different member object as the context in the get helper, the content gating was not working correctly, as the member was missing a status property, this adds the property which fixes content gating. - Added extra tests for get helper {{access}} property - Added extra test for {{access}} property in next_post helper - In the future we might want to update the tests so they test the whole request -> HBS context flow. Currently the has context is still stubbed manually.
54 lines
2 KiB
JavaScript
54 lines
2 KiB
JavaScript
const _ = require('lodash');
|
|
const hbs = require('../engine');
|
|
const urlUtils = require('../../../../shared/url-utils');
|
|
const customThemeSettingsCache = require('../../../../shared/custom-theme-settings-cache');
|
|
const preview = require('../preview');
|
|
|
|
function updateLocalTemplateOptions(req, res, next) {
|
|
const localTemplateOptions = hbs.getLocalTemplateOptions(res.locals);
|
|
|
|
// adjust @site.url for http/https based on the incoming request
|
|
const siteData = {
|
|
url: urlUtils.urlFor('home', {secure: req.secure, trailingSlash: false}, true)
|
|
};
|
|
|
|
// @TODO: it would be nicer if this was proper middleware somehow...
|
|
const previewData = preview.handle(req, Object.keys(customThemeSettingsCache.getAll()));
|
|
|
|
// strip custom off of preview data so it doesn't get merged into @site
|
|
const customData = previewData.custom;
|
|
delete previewData.custom;
|
|
|
|
// update site data with any preview values from the request
|
|
Object.assign(siteData, previewData);
|
|
|
|
const member = req.member ? {
|
|
uuid: req.member.uuid,
|
|
email: req.member.email,
|
|
name: req.member.name,
|
|
firstname: req.member.name && req.member.name.split(' ')[0],
|
|
avatar_image: req.member.avatar_image,
|
|
subscriptions: req.member.subscriptions && req.member.subscriptions.map((sub) => {
|
|
return Object.assign({}, sub, {
|
|
default_payment_card_last4: sub.default_payment_card_last4 || '****'
|
|
});
|
|
}),
|
|
paid: req.member.status !== 'free',
|
|
status: req.member.status,
|
|
products: req.member.products
|
|
} : null;
|
|
|
|
hbs.updateLocalTemplateOptions(res.locals, _.merge({}, localTemplateOptions, {
|
|
data: {
|
|
member: member,
|
|
site: siteData,
|
|
custom: customData,
|
|
// @deprecated: a gscan warning for @blog was added before 3.0 which replaced it with @site
|
|
blog: siteData
|
|
}
|
|
}));
|
|
|
|
next();
|
|
}
|
|
|
|
module.exports = updateLocalTemplateOptions;
|