mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-02 20:59:56 +01:00
Merge remote-tracking branch 'origin/master' into flagging-refactor
This commit is contained in:
@@ -366,7 +366,7 @@ $(document).ready(function () {
|
||||
}
|
||||
|
||||
// Default behaviour for rss feeds
|
||||
if (internalLink && $(this).attr('href').endsWith('.rss')) {
|
||||
if (internalLink && $(this).attr('href') && $(this).attr('href').endsWith('.rss')) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -336,91 +336,85 @@ module.exports = function (Groups) {
|
||||
return process.nextTick(callback, null, cache.get(cacheKey));
|
||||
}
|
||||
|
||||
db.isSortedSetMember('group:' + groupName + ':members', uid, function (err, isMember) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.isSortedSetMember('group:' + groupName + ':members', uid, next);
|
||||
},
|
||||
function (isMember, next) {
|
||||
cache.set(cacheKey, isMember);
|
||||
next(null, isMember);
|
||||
}
|
||||
|
||||
cache.set(cacheKey, isMember);
|
||||
callback(null, isMember);
|
||||
});
|
||||
], callback);
|
||||
};
|
||||
|
||||
Groups.isMembers = function (uids, groupName, callback) {
|
||||
function getFromCache(next) {
|
||||
process.nextTick(next, null, uids.map(function (uid) {
|
||||
return cache.get(uid + ':' + groupName);
|
||||
}));
|
||||
}
|
||||
|
||||
if (!groupName || !uids.length) {
|
||||
return callback(null, uids.map(function () {return false;}));
|
||||
}
|
||||
|
||||
var nonCachedUids = [];
|
||||
uids.forEach(function (uid) {
|
||||
if (!cache.has(uid + ':' + groupName)) {
|
||||
nonCachedUids.push(uid);
|
||||
}
|
||||
var nonCachedUids = uids.filter(function (uid) {
|
||||
return !cache.has(uid + ':' + groupName);
|
||||
});
|
||||
|
||||
if (!nonCachedUids.length) {
|
||||
var result = uids.map(function (uid) {
|
||||
return cache.get(uid + ':' + groupName);
|
||||
});
|
||||
return process.nextTick(callback, null, result);
|
||||
return getFromCache(callback);
|
||||
}
|
||||
|
||||
db.isSortedSetMembers('group:' + groupName + ':members', nonCachedUids, function (err, isMembers) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.isSortedSetMembers('group:' + groupName + ':members', nonCachedUids, next);
|
||||
},
|
||||
function (isMembers, next) {
|
||||
nonCachedUids.forEach(function (uid, index) {
|
||||
cache.set(uid + ':' + groupName, isMembers[index]);
|
||||
});
|
||||
|
||||
getFromCache(next);
|
||||
}
|
||||
|
||||
nonCachedUids.forEach(function (uid, index) {
|
||||
cache.set(uid + ':' + groupName, isMembers[index]);
|
||||
});
|
||||
|
||||
var result = uids.map(function (uid) {
|
||||
return cache.get(uid + ':' + groupName);
|
||||
});
|
||||
|
||||
callback(null, result);
|
||||
});
|
||||
], callback);
|
||||
};
|
||||
|
||||
Groups.isMemberOfGroups = function (uid, groups, callback) {
|
||||
function getFromCache(next) {
|
||||
process.nextTick(next, null, groups.map(function (groupName) {
|
||||
return cache.get(uid + ':' + groupName);
|
||||
}));
|
||||
}
|
||||
|
||||
if (!uid || parseInt(uid, 10) <= 0 || !groups.length) {
|
||||
return callback(null, groups.map(function () {return false;}));
|
||||
}
|
||||
|
||||
var nonCachedGroups = [];
|
||||
|
||||
groups.forEach(function (groupName) {
|
||||
if (!cache.has(uid + ':' + groupName)) {
|
||||
nonCachedGroups.push(groupName);
|
||||
}
|
||||
var nonCachedGroups = groups.filter(function (groupName) {
|
||||
return !cache.has(uid + ':' + groupName);
|
||||
});
|
||||
|
||||
// are they all cached?
|
||||
if (!nonCachedGroups.length) {
|
||||
var result = groups.map(function (groupName) {
|
||||
return cache.get(uid + ':' + groupName);
|
||||
});
|
||||
return process.nextTick(callback, null, result);
|
||||
return getFromCache(callback);
|
||||
}
|
||||
|
||||
var nonCachedGroupsMemberSets = nonCachedGroups.map(function (groupName) {
|
||||
return 'group:' + groupName + ':members';
|
||||
});
|
||||
|
||||
db.isMemberOfSortedSets(nonCachedGroupsMemberSets, uid, function (err, isMembers) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.isMemberOfSortedSets(nonCachedGroupsMemberSets, uid, next);
|
||||
},
|
||||
function (isMembers, next) {
|
||||
nonCachedGroups.forEach(function (groupName, index) {
|
||||
cache.set(uid + ':' + groupName, isMembers[index]);
|
||||
});
|
||||
|
||||
getFromCache(next);
|
||||
}
|
||||
|
||||
nonCachedGroups.forEach(function (groupName, index) {
|
||||
cache.set(uid + ':' + groupName, isMembers[index]);
|
||||
});
|
||||
|
||||
var result = groups.map(function (groupName) {
|
||||
return cache.get(uid + ':' + groupName);
|
||||
});
|
||||
callback(null, result);
|
||||
});
|
||||
], callback);
|
||||
};
|
||||
|
||||
Groups.getMemberCount = function (groupName, callback) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
|
||||
var db = require('../database');
|
||||
var plugins = require('../plugins');
|
||||
|
||||
@@ -18,20 +20,20 @@ module.exports = function (Meta) {
|
||||
};
|
||||
|
||||
Meta.settings.set = function (hash, values, callback) {
|
||||
var key = 'settings:' + hash;
|
||||
db.setObject(key, values, function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.setObject('settings:' + hash, values, next);
|
||||
},
|
||||
function (next) {
|
||||
plugins.fireHook('action:settings.set', {
|
||||
plugin: hash,
|
||||
settings: values
|
||||
});
|
||||
|
||||
Meta.reloadRequired = true;
|
||||
next();
|
||||
}
|
||||
|
||||
plugins.fireHook('action:settings.set', {
|
||||
plugin: hash,
|
||||
settings: values
|
||||
});
|
||||
|
||||
Meta.reloadRequired = true;
|
||||
callback();
|
||||
});
|
||||
], callback);
|
||||
};
|
||||
|
||||
Meta.settings.setOne = function (hash, field, value, callback) {
|
||||
@@ -39,23 +41,25 @@ module.exports = function (Meta) {
|
||||
};
|
||||
|
||||
Meta.settings.setOnEmpty = function (hash, values, callback) {
|
||||
db.getObject('settings:' + hash, function (err, settings) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
settings = settings || {};
|
||||
var empty = {};
|
||||
Object.keys(values).forEach(function (key) {
|
||||
if (!settings.hasOwnProperty(key)) {
|
||||
empty[key] = values[key];
|
||||
}
|
||||
});
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.getObject('settings:' + hash, next);
|
||||
},
|
||||
function (settings, next) {
|
||||
settings = settings || {};
|
||||
var empty = {};
|
||||
Object.keys(values).forEach(function (key) {
|
||||
if (!settings.hasOwnProperty(key)) {
|
||||
empty[key] = values[key];
|
||||
}
|
||||
});
|
||||
|
||||
if (Object.keys(empty).length) {
|
||||
db.setObject('settings:' + hash, empty, callback);
|
||||
} else {
|
||||
callback();
|
||||
if (Object.keys(empty).length) {
|
||||
db.setObject('settings:' + hash, empty, next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
});
|
||||
], callback);
|
||||
};
|
||||
};
|
||||
@@ -14,7 +14,6 @@ var helpers = require('./helpers');
|
||||
|
||||
|
||||
describe('Messaging Library', function () {
|
||||
//var testUids;
|
||||
var fooUid;
|
||||
var bazUid;
|
||||
var herpUid;
|
||||
|
||||
104
test/meta.js
Normal file
104
test/meta.js
Normal file
@@ -0,0 +1,104 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var async = require('async');
|
||||
|
||||
var db = require('./mocks/databasemock');
|
||||
var meta = require('../src/meta');
|
||||
var User = require('../src/user');
|
||||
var Groups = require('../src/groups');
|
||||
|
||||
describe('Messaging Library', function () {
|
||||
var fooUid;
|
||||
var bazUid;
|
||||
var herpUid;
|
||||
|
||||
before(function (done) {
|
||||
Groups.resetCache();
|
||||
// Create 3 users: 1 admin, 2 regular
|
||||
async.series([
|
||||
async.apply(User.create, { username: 'foo', password: 'barbar' }), // admin
|
||||
async.apply(User.create, { username: 'baz', password: 'quuxquux' }), // restricted user
|
||||
async.apply(User.create, { username: 'herp', password: 'derpderp' }) // regular user
|
||||
], function (err, uids) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
fooUid = uids[0];
|
||||
bazUid = uids[1];
|
||||
herpUid = uids[2];
|
||||
|
||||
Groups.join('administrators', fooUid, done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('settings', function () {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
it('it should set setting', function (done) {
|
||||
socketAdmin.settings.set({uid: fooUid}, {hash: 'some:hash', values: {foo: '1', derp: 'value'}}, function (err) {
|
||||
assert.ifError(err);
|
||||
db.getObject('settings:some:hash', function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.foo, '1');
|
||||
assert.equal(data.derp, 'value');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('it should get setting', function (done) {
|
||||
socketAdmin.settings.get({uid: fooUid}, {hash: 'some:hash'}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.foo, '1');
|
||||
assert.equal(data.derp, 'value');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not set setting if not empty', function (done) {
|
||||
meta.settings.setOnEmpty('some:hash', {foo: 2}, function (err) {
|
||||
assert.ifError(err);
|
||||
db.getObject('settings:some:hash', function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.foo, '1');
|
||||
assert.equal(data.derp, 'value');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should set setting if empty', function (done) {
|
||||
meta.settings.setOnEmpty('some:hash', {empty: '2'}, function (err) {
|
||||
assert.ifError(err);
|
||||
db.getObject('settings:some:hash', function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.foo, '1');
|
||||
assert.equal(data.derp, 'value');
|
||||
assert.equal(data.empty, '2');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should set one and get one', function (done) {
|
||||
meta.settings.setOne('some:hash', 'myField', 'myValue', function (err) {
|
||||
assert.ifError(err);
|
||||
meta.settings.getOne('some:hash', 'myField', function (err, myValue) {
|
||||
assert.ifError(err);
|
||||
assert.equal(myValue, 'myValue');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
after(function (done) {
|
||||
db.emptydb(done);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user