From 5c41c67ffc1ed6478555936f0b86ba3dca72b8ae Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Mon, 19 Apr 2021 18:28:51 +0100 Subject: [PATCH] Set `@labs.members` to false when `members_signup_acess == 'none'` refs https://github.com/TryGhost/Team/issues/579 - setting `members_signup_access` to `'none'` effectively disables all built-in members functions on the front-end so setting `@labs.members` to `false` allows themes to react accordingly - `@labs.members` keeps backwards compatibility with pre-4.0 versions where themes were using it to toggle member-related functionality --- core/server/services/labs.js | 3 ++- test/unit/services/labs_spec.js | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/core/server/services/labs.js b/core/server/services/labs.js index 4e528604ec..e1abfd0532 100644 --- a/core/server/services/labs.js +++ b/core/server/services/labs.js @@ -4,9 +4,10 @@ const SafeString = require('../../frontend/services/themes/engine').SafeString; const errors = require('@tryghost/errors'); const {i18n} = require('../lib/common'); const logging = require('../../shared/logging'); +const settingsCache = require('../services/settings/cache'); module.exports.getAll = () => ({ - members: true + members: settingsCache.get('members_signup_access') !== 'none' }); module.exports.isSet = function isSet(flag) { diff --git a/test/unit/services/labs_spec.js b/test/unit/services/labs_spec.js index ed41c4592d..6ae79a5767 100644 --- a/test/unit/services/labs_spec.js +++ b/test/unit/services/labs_spec.js @@ -2,13 +2,17 @@ const should = require('should'); const sinon = require('sinon'); const labs = require('../../../core/server/services/labs'); +const settingsCache = require('../../../core/server/services/settings/cache'); describe('Labs Service', function () { afterEach(function () { sinon.restore(); }); - it('always returns members true flag', function () { + it('members flag is true when members_signup_access setting is "all"', function () { + sinon.stub(settingsCache, 'get'); + settingsCache.get.withArgs('members_signup_access').returns('all'); + labs.getAll().should.eql({ members: true }); @@ -16,6 +20,17 @@ describe('Labs Service', function () { labs.isSet('members').should.be.true; }); + it('members flag is false when members_signup_access setting is "none"', function () { + sinon.stub(settingsCache, 'get'); + settingsCache.get.withArgs('members_signup_access').returns('none'); + + labs.getAll().should.eql({ + members: false + }); + + labs.isSet('members').should.be.false; + }); + it('isSet returns false for undefined', function () { labs.isSet('bar').should.be.false; });