Hardcoded labs to always return members:true

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.
This commit is contained in:
Naz 2021-02-17 12:24:54 +13:00 committed by naz
parent 37ef40b46e
commit d0e0760dae
7 changed files with 11 additions and 47 deletions

View File

@ -1,21 +1,13 @@
const settingsCache = require('./settings/cache');
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');
const deprecatedFeatures = ['subscribers', 'publicAPI'];
module.exports.getAll = () => {
let labs = _.cloneDeep(settingsCache.get('labs')) || {};
// Remove old labs flags that should always be false now
deprecatedFeatures.forEach((feature) => {
delete labs[feature];
});
return labs;
};
module.exports.getAll = () => ({
members: true
});
module.exports.isSet = function isSet(flag) {
const labsConfig = module.exports.getAll();

View File

@ -62,7 +62,6 @@ const defaultSettingsKeyTypes = [
{key: 'email_track_opens', type: 'bulk_email'},
{key: 'amp', type: 'blog'},
{key: 'amp_gtag_id', type: 'blog'},
{key: 'labs', type: 'blog'},
{key: 'slack', type: 'blog'},
{key: 'slack_url', type: 'blog'},
{key: 'slack_username', type: 'blog'},
@ -190,7 +189,7 @@ describe('Settings API (canary)', function () {
jsonResponse.settings.should.be.an.Object();
const settings = jsonResponse.settings;
Object.keys(settings).length.should.equal(68);
Object.keys(settings).length.should.equal(defaultSettingsKeyTypes.length);
localUtils.API.checkResponse(jsonResponse, 'settings');
});

View File

@ -59,7 +59,6 @@ const defaultSettingsKeyTypes = [
{key: 'email_track_opens', type: 'bulk_email'},
{key: 'amp', type: 'blog'},
{key: 'amp_gtag_id', type: 'blog'},
{key: 'labs', type: 'blog'},
{key: 'slack', type: 'blog'},
{key: 'unsplash', type: 'blog'},
{key: 'shared_views', type: 'blog'},

View File

@ -62,7 +62,6 @@ const defaultSettingsKeyTypes = [
{key: 'email_track_opens', type: 'bulk_email'},
{key: 'amp', type: 'blog'},
{key: 'amp_gtag_id', type: 'blog'},
{key: 'labs', type: 'blog'},
{key: 'slack', type: 'blog'},
{key: 'slack_url', type: 'blog'},
{key: 'slack_username', type: 'blog'},

View File

@ -113,7 +113,7 @@ const exportedLegacyBody = () => {
};
// Tests in here do an import for each test
describe.only('Integration: Importer', function () {
describe('Integration: Importer', function () {
before(testUtils.teardownDb);
beforeEach(function () {

View File

@ -1,51 +1,26 @@
const should = require('should');
const sinon = require('sinon');
const settingsCache = require('../../../core/server/services/settings/cache');
const labs = require('../../../core/server/services/labs');
describe('Labs Service', function () {
let labsCacheStub;
beforeEach(function () {
labsCacheStub = sinon.stub(settingsCache, 'get').withArgs('labs');
});
afterEach(function () {
sinon.restore();
});
it('can getAll, even if empty', function () {
labs.getAll().should.eql({});
});
it('always returns members true flag', function () {
labs.getAll().should.eql({
members: true
});
it('can getAll from cache', function () {
labsCacheStub.returns({members: true, foo: 'bar'});
labs.getAll().should.eql({members: true, foo: 'bar'});
});
it('can getAll from cache, ignoring deprecated', function () {
labsCacheStub.returns({members: true, foo: 'bar', subscribers: false, publicAPI: true});
labs.getAll().should.eql({members: true, foo: 'bar'});
});
it('isSet returns true string flag', function () {
labsCacheStub.returns({foo: 'bar'});
labs.isSet('foo').should.be.true;
labs.isSet('members').should.be.true;
});
it('isSet returns false for undefined', function () {
labsCacheStub.returns({foo: 'bar'});
labs.isSet('bar').should.be.false;
});
it('isSet always returns false for deprecated', function () {
labsCacheStub.returns({subscribers: true, publicAPI: true});
labs.isSet('subscribers').should.be.false;
labs.isSet('publicAPI').should.be.false;
});

View File

@ -53,7 +53,7 @@ describe('Themes middleware', function () {
// labs data is deep cloned,
// if we want to compare it
// we will need some unique content
'@@REQUIRED@@': true
members: true
};
sandbox.stub(activeTheme, 'get')