2018-11-09 14:42:21 +03:00
|
|
|
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 = {};
|
2015-11-03 22:17:24 +03:00
|
|
|
|
2017-03-23 22:00:58 +03:00
|
|
|
labs.isSet = function isSet(flag) {
|
2018-11-09 14:42:21 +03:00
|
|
|
/**
|
|
|
|
* TODO: Uses hard-check for members prototype, removed here when added to settings
|
|
|
|
*/
|
|
|
|
if (flag === 'members' && config.get('enableDeveloperExperiments')) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-02-03 16:15:11 +03:00
|
|
|
var labsConfig = settingsCache.get('labs');
|
2015-12-01 19:13:05 +03:00
|
|
|
return labsConfig && labsConfig[flag] && labsConfig[flag] === true;
|
2015-11-03 22:17:24 +03:00
|
|
|
};
|
|
|
|
|
2017-03-23 22:00:58 +03:00
|
|
|
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 = {
|
2017-12-12 00:47:46 +03:00
|
|
|
message: common.i18n.t('warnings.helpers.helperNotAvailable', {helperName: options.helperName}),
|
|
|
|
context: common.i18n.t('warnings.helpers.flagMustBeEnabled', {
|
2017-03-23 22:00:58 +03:00
|
|
|
helperName: options.helperName,
|
|
|
|
flagName: options.flagName
|
|
|
|
}),
|
2017-12-12 00:47:46 +03:00
|
|
|
help: common.i18n.t('warnings.helpers.seeLink', {url: options.helpUrl})
|
2017-03-23 22:00:58 +03:00
|
|
|
};
|
|
|
|
|
2017-12-12 00:47:46 +03:00
|
|
|
common.logging.error(new common.errors.DisabledFeatureError(errDetails));
|
2017-03-23 22:00:58 +03:00
|
|
|
|
2017-04-04 19:07:35 +03:00
|
|
|
errString = new SafeString(
|
2017-03-23 22:00:58 +03:00
|
|
|
'<script>console.error("' + _.values(errDetails).join(' ') + '");</script>'
|
|
|
|
);
|
|
|
|
|
|
|
|
if (options.async) {
|
|
|
|
return Promise.resolve(function asyncError() {
|
|
|
|
return errString;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return errString;
|
|
|
|
};
|