Ghost/core/server/services/labs.js
Rishabh Garg f2b44322a3
Enabled members lab setting for developer experiment flag (#10132)
closes #10114
 
* Members lab enabled to be always true behind developer experiments flag

* Members lab set to true for themes behind developer experiments flag

Note: This change uses hard-coded labs value for members based on enableDeveloperExperiments flag, ideal implementation for later is to pick those value from settings.
2018-11-09 17:12:21 +05:30

52 lines
1.6 KiB
JavaScript

const settingsCache = require('./settings/cache');
const _ = require('lodash');
const Promise = require('bluebird');
const SafeString = require('./themes/engine').SafeString;
const common = require('../lib/common');
const config = require('../config');
let labs = module.exports = {};
labs.isSet = function isSet(flag) {
/**
* TODO: Uses hard-check for members prototype, removed here when added to settings
*/
if (flag === 'members' && config.get('enableDeveloperExperiments')) {
return true;
}
var labsConfig = settingsCache.get('labs');
return labsConfig && labsConfig[flag] && labsConfig[flag] === true;
};
labs.enabledHelper = function enabledHelper(options, callback) {
var errDetails, errString;
if (labs.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: common.i18n.t('warnings.helpers.helperNotAvailable', {helperName: options.helperName}),
context: common.i18n.t('warnings.helpers.flagMustBeEnabled', {
helperName: options.helperName,
flagName: options.flagName
}),
help: common.i18n.t('warnings.helpers.seeLink', {url: options.helpUrl})
};
common.logging.error(new common.errors.DisabledFeatureError(errDetails));
errString = new SafeString(
'<script>console.error("' + _.values(errDetails).join(' ') + '");</script>'
);
if (options.async) {
return Promise.resolve(function asyncError() {
return errString;
});
}
return errString;
};