mirror of
https://github.com/wassname/talk.git
synced 2026-07-26 13:37:38 +08:00
Merge branch 'master' into pluralize-asset
This commit is contained in:
+18
-3
@@ -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);
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,7 +38,7 @@ router.get('/', (req, res, next) => {
|
||||
}),
|
||||
|
||||
// Get the moderation setting from the settings.
|
||||
Setting.retrieve()
|
||||
Setting.public()
|
||||
])
|
||||
.then(([asset, settings]) => {
|
||||
|
||||
|
||||
+15
-1
@@ -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'};
|
||||
|
||||
Reference in New Issue
Block a user