mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 21:40:39 +03:00
d0e0760dae
refs https://github.com/TryGhost/Ghost/issues/10318 - Because members is effectively "enabled" by default starting Ghost 4.0 have hardcoded labs setting to be such. The alternative of removing this key from labs would be equivalent to `labs.members === false` which is undesireable and would mean additional work on theme developer's side.
45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
const _ = require('lodash');
|
|
const Promise = require('bluebird');
|
|
const SafeString = require('../../frontend/services/themes/engine').SafeString;
|
|
const errors = require('@tryghost/errors');
|
|
const {i18n} = require('../lib/common');
|
|
const logging = require('../../shared/logging');
|
|
|
|
module.exports.getAll = () => ({
|
|
members: true
|
|
});
|
|
|
|
module.exports.isSet = function isSet(flag) {
|
|
const labsConfig = module.exports.getAll();
|
|
|
|
return !!(labsConfig && labsConfig[flag] && labsConfig[flag] === true);
|
|
};
|
|
|
|
module.exports.enabledHelper = function enabledHelper(options, callback) {
|
|
const errDetails = {};
|
|
let errString;
|
|
|
|
if (module.exports.isSet(options.flagKey) === true) {
|
|
// helper is active, use the callback
|
|
return callback();
|
|
}
|
|
|
|
// Else, the helper is not active and we need to handle this as an error
|
|
errDetails.message = i18n.t(options.errMessagePath || 'warnings.helpers.helperNotAvailable', {helperName: options.helperName}),
|
|
errDetails.context = i18n.t(options.errContextPath || 'warnings.helpers.flagMustBeEnabled', {
|
|
helperName: options.helperName,
|
|
flagName: options.flagName
|
|
});
|
|
errDetails.help = i18n.t(options.errHelpPath || 'warnings.helpers.seeLink', {url: options.helpUrl});
|
|
|
|
logging.error(new errors.DisabledFeatureError(errDetails));
|
|
|
|
errString = new SafeString(`<script>console.error("${_.values(errDetails).join(' ')}");</script>`);
|
|
|
|
if (options.async) {
|
|
return Promise.resolve(errString);
|
|
}
|
|
|
|
return errString;
|
|
};
|