diff --git a/client/coral-framework/actions/config.js b/client/coral-framework/actions/config.js index c88138534..77e7f5af5 100644 --- a/client/coral-framework/actions/config.js +++ b/client/coral-framework/actions/config.js @@ -16,7 +16,7 @@ export const updateConfiguration = newConfig => (dispatch, getState) => { .toArray()[0]; dispatch(updateConfigRequest()); - coralApi(`/asset/${assetId}/settings`, {method: 'PUT', body: newConfig}) + coralApi(`/assets/${assetId}/settings`, {method: 'PUT', body: newConfig}) .then(() => { dispatch(addNotification('success', lang.t('successUpdateSettings'))); dispatch(updateConfigSuccess(newConfig)); @@ -31,7 +31,7 @@ export const updateOpenStream = closedBody => (dispatch, getState) => { dispatch(updateConfigRequest()); - coralApi(`/asset/${assetId}/status`, {method: 'PUT', body: closedBody}) + coralApi(`/assets/${assetId}/status`, {method: 'PUT', body: closedBody}) .then(() => { dispatch(addNotification('success', lang.t('successUpdateSettings'))); dispatch(updateConfigSuccess(closedBody)); diff --git a/docs/swagger.yaml b/docs/swagger.yaml index e819f451c..f6aba4d25 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -256,7 +256,7 @@ paths: description: An error occured. schema: $ref: '#/definitions/Error' - /asset: + /assets: get: parameters: - name: limit @@ -294,7 +294,7 @@ paths: items: $ref: '#/definitions/Asset' - /asset/{asset_id}: + /assets/{asset_id}: get: parameters: - name: asset_id @@ -315,7 +315,7 @@ paths: $ref: '#/definitions/Error' - /asset/{asset_id}/scrape: + /assets/{asset_id}/scrape: post: parameters: - name: asset_id @@ -335,7 +335,7 @@ paths: schema: $ref: '#/definitions/Error' - /asset/{asset_id}/settings: + /assets/{asset_id}/settings: put: parameters: - name: asset_id diff --git a/models/setting.js b/models/setting.js index 967b5fd7e..6f142c760 100644 --- a/models/setting.js +++ b/models/setting.js @@ -106,6 +106,11 @@ 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. @@ -120,6 +125,14 @@ 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 @@ -134,9 +147,11 @@ SettingService.update = (settings) => Setting.findOneAndUpdate(selector, { }).then((settings) => { // Invalidate the settings cache. - return cache - .set('settings', settings, EXPIRY_TIME) - .then(() => settings); + return Promise.all([ + cache.set('settings', settings, EXPIRY_TIME), + cache.invalidate('publicSettings') + ]) + .then(() => settings); }); /** diff --git a/routes/api/asset/index.js b/routes/api/assets/index.js similarity index 100% rename from routes/api/asset/index.js rename to routes/api/assets/index.js diff --git a/routes/api/index.js b/routes/api/index.js index 6a7f6ff10..316d284e0 100644 --- a/routes/api/index.js +++ b/routes/api/index.js @@ -7,7 +7,7 @@ const router = express.Router(); // Filter all content going down the pipe based on user roles. router.use(payloadFilter); -router.use('/asset', authorization.needed('admin'), require('./asset')); +router.use('/assets', authorization.needed('admin'), require('./assets')); router.use('/settings', authorization.needed('admin'), require('./settings')); router.use('/queue', authorization.needed('admin'), require('./queue')); diff --git a/routes/api/stream/index.js b/routes/api/stream/index.js index 8d70adbb4..246e71b15 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.retrieve() + Setting.public() ]) .then(([asset, settings]) => { diff --git a/tests/models/setting.js b/tests/models/setting.js index 8fd23d6a0..f62e0a7df 100644 --- a/tests/models/setting.js +++ b/tests/models/setting.js @@ -3,7 +3,7 @@ const expect = require('chai').expect; describe('models.Setting', () => { - beforeEach(() => Setting.init({moderation: 'pre'})); + beforeEach(() => Setting.init({moderation: 'pre', wordlist: ['donut']})); describe('#retrieve()', () => { it('should have a moderation field defined', () => { @@ -20,6 +20,20 @@ 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'}; diff --git a/tests/routes/api/assets/index.js b/tests/routes/api/assets/index.js index 64e820722..8e94c81fc 100644 --- a/tests/routes/api/assets/index.js +++ b/tests/routes/api/assets/index.js @@ -32,7 +32,7 @@ describe('/api/v1/assets', () => { it('should return all assets without a search query', () => { return chai.request(app) - .get('/api/v1/asset') + .get('/api/v1/assets') .set(passport.inject({roles: ['admin']})) .then((res) => { const body = res.body; @@ -48,7 +48,7 @@ describe('/api/v1/assets', () => { it('should return assets that we search for', () => { return chai.request(app) - .get('/api/v1/asset?search=term2') + .get('/api/v1/assets?search=term2') .set(passport.inject({roles: ['admin']})) .then((res) => { const body = res.body; @@ -69,7 +69,7 @@ describe('/api/v1/assets', () => { it('should not return assets that we do not search for', () => { return chai.request(app) - .get('/api/v1/asset?search=term3') + .get('/api/v1/assets?search=term3') .set(passport.inject({roles: ['admin']})) .then((res) => { const body = res.body; @@ -94,7 +94,7 @@ describe('/api/v1/assets', () => { expect(asset).to.have.property('closedAt', null); return chai.request(app) - .put(`/api/v1/asset/${asset.id}/status`) + .put(`/api/v1/assets/${asset.id}/status`) .set(passport.inject({roles: ['admin']})) .send({closedAt: today}); })