From 55bd600d960c891ebae64f3f1fc099f8833e227c Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Tue, 13 Dec 2016 16:13:29 -0700 Subject: [PATCH] Removed public function in favor of filterForUser transformer --- models/setting.js | 23 +++++++++-------------- routes/api/stream/index.js | 2 +- tests/models/setting.js | 14 -------------- 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/models/setting.js b/models/setting.js index 6f142c760..46ebce741 100644 --- a/models/setting.js +++ b/models/setting.js @@ -84,7 +84,15 @@ SettingSchema.method('merge', function(src) { */ SettingSchema.method('filterForUser', function(user = false) { if (!user || !user.roles.includes('admin')) { - return _.pick(this.toJSON(), ['moderation', 'infoBoxEnable', 'infoBoxContent']); + return _.pick(this.toJSON(), [ + 'moderation', + 'infoBoxEnable', + 'infoBoxContent', + 'closeTimeout', + 'closedMessage', + 'charCountEnable', + 'charCount' + ]); } return this.toJSON(); @@ -106,11 +114,6 @@ const SettingService = module.exports = {}; */ const selector = {id: '1'}; -/** - * The list of settings that can be viewed publicly. - */ -const publicSettings = 'moderation infoBoxEnable infoBoxContent closeTimeout closedMessage charCountEnable charCount'; - /** * Cache expiry time in seconds for when the cached entry of the settings object * expires. 2 minutes. @@ -125,14 +128,6 @@ SettingService.retrieve = () => cache.wrap('settings', EXPIRY_TIME, () => { return Setting.findOne(selector); }).then((setting) => new Setting(setting)); -/** - * Gets publicly available settings records - * @return {Promise} settings the publicly viewable settings record - */ -SettingService.public = () => cache.wrap('publicSettings', EXPIRY_TIME, () => { - return Setting.findOne(selector, publicSettings); -}).then((setting) => new Setting(setting)); - /** * This will update the settings object with whatever you pass in * @param {object} setting a hash of whatever settings you want to update diff --git a/routes/api/stream/index.js b/routes/api/stream/index.js index 246e71b15..8d70adbb4 100644 --- a/routes/api/stream/index.js +++ b/routes/api/stream/index.js @@ -38,7 +38,7 @@ router.get('/', (req, res, next) => { }), // Get the moderation setting from the settings. - Setting.public() + Setting.retrieve() ]) .then(([asset, settings]) => { diff --git a/tests/models/setting.js b/tests/models/setting.js index f62e0a7df..a7c97abfb 100644 --- a/tests/models/setting.js +++ b/tests/models/setting.js @@ -20,20 +20,6 @@ describe('models.Setting', () => { }); }); - describe('#public()', () => { - it('should have a moderation field defined', () => { - return Setting.public().then(settings => { - expect(settings).to.have.property('moderation').and.to.equal('pre'); - }); - }); - - it('should not have the wordlist field defined', () => { - return Setting.public().then(settings => { - expect(settings).to.have.property('wordlist').and.to.have.length(0); - }); - }); - }); - describe('#update()', () => { it('should update the settings with a passed object', () => { const mockSettings = {moderation: 'post', infoBoxEnable: true, infoBoxContent: 'yeah'};