mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-09-05 21:40:03 +02:00
Merge branch 'code-quality' of https://github.com/miksago/NodeBB into miksago-code-quality
Conflicts: src/database.js
This commit is contained in:
@@ -324,4 +324,4 @@ var db = require('./database'),
|
||||
|
||||
emitter.on('event:newpost', Categories.onNewPostMade);
|
||||
|
||||
}(exports));
|
||||
}(exports));
|
||||
|
||||
@@ -80,4 +80,4 @@ module.exports = function(Categories) {
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -43,4 +43,4 @@ module.exports = function(Categories) {
|
||||
});
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -4,9 +4,31 @@ var Groups = require('./groups'),
|
||||
User = require('./user'),
|
||||
|
||||
async = require('async'),
|
||||
db = require('./database'),
|
||||
db = require('./database');
|
||||
|
||||
CategoryTools = {};
|
||||
var internals = {
|
||||
isMember: function(key, candidate, next){
|
||||
Groups.exists(key, function(err, exists) {
|
||||
if (exists) {
|
||||
Groups.isMember(candidate, key, next);
|
||||
} else {
|
||||
next(null, null);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
isMemberOfGroupList: function(key, candidate, next){
|
||||
Groups.exists(key, function(err, exists) {
|
||||
if (exists) {
|
||||
Groups.isMemberOfGroupList(candidate, key, next);
|
||||
} else {
|
||||
next(null, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var CategoryTools = {};
|
||||
|
||||
CategoryTools.exists = function(cid, callback) {
|
||||
db.isSortedSetMember('categories:cid', cid, callback);
|
||||
@@ -15,44 +37,16 @@ CategoryTools.exists = function(cid, callback) {
|
||||
CategoryTools.privileges = function(cid, uid, callback) {
|
||||
async.parallel({
|
||||
"+r": function(next) {
|
||||
var key = 'cid:' + cid + ':privileges:+r';
|
||||
Groups.exists(key, function(err, exists) {
|
||||
if (exists) {
|
||||
Groups.isMember(uid, key, next);
|
||||
} else {
|
||||
next(null, null);
|
||||
}
|
||||
});
|
||||
internals.isMember('cid:' + cid + ':privileges:+r', uid, next);
|
||||
},
|
||||
"+w": function(next) {
|
||||
var key = 'cid:' + cid + ':privileges:+w';
|
||||
Groups.exists(key, function(err, exists) {
|
||||
if (exists) {
|
||||
Groups.isMember(uid, key, next);
|
||||
} else {
|
||||
next(null, null);
|
||||
}
|
||||
});
|
||||
internals.isMember('cid:' + cid + ':privileges:+w', uid, next);
|
||||
},
|
||||
"g+r": function(next) {
|
||||
var key = 'cid:' + cid + ':privileges:g+r';
|
||||
Groups.exists(key, function(err, exists) {
|
||||
if (exists) {
|
||||
Groups.isMemberOfGroupList(uid, key, next);
|
||||
} else {
|
||||
next(null, null);
|
||||
}
|
||||
});
|
||||
internals.isMemberOfGroupList('cid:' + cid + ':privileges:g+r', uid, next);
|
||||
},
|
||||
"g+w": function(next) {
|
||||
var key = 'cid:' + cid + ':privileges:g+w';
|
||||
Groups.exists(key, function(err, exists) {
|
||||
if (exists) {
|
||||
Groups.isMemberOfGroupList(uid, key, next);
|
||||
} else {
|
||||
next(null, null);
|
||||
}
|
||||
});
|
||||
internals.isMemberOfGroupList('cid:' + cid + ':privileges:g+w', uid, next);
|
||||
},
|
||||
moderator: function(next) {
|
||||
User.isModerator(uid, cid, next);
|
||||
@@ -93,23 +87,13 @@ CategoryTools.privileges = function(cid, uid, callback) {
|
||||
CategoryTools.groupPrivileges = function(cid, groupName, callback) {
|
||||
async.parallel({
|
||||
"g+r": function(next) {
|
||||
var key = 'cid:' + cid + ':privileges:g+r';
|
||||
Groups.exists(key, function(err, exists) {
|
||||
if (exists) {
|
||||
Groups.isMember(groupName, key, next);
|
||||
} else {
|
||||
next(null, false);
|
||||
}
|
||||
internals.isMember('cid:' + cid + ':privileges:g+r', groupName, function(err, isMember){
|
||||
next(err, !!isMember);
|
||||
});
|
||||
},
|
||||
"g+w": function(next) {
|
||||
var key = 'cid:' + cid + ':privileges:g+w';
|
||||
Groups.exists(key, function(err, exists) {
|
||||
if (exists) {
|
||||
Groups.isMember(groupName, key, next);
|
||||
} else {
|
||||
next(null, false);
|
||||
}
|
||||
internals.isMember('cid:' + cid + ':privileges:g+w', groupName, function(err, isMember){
|
||||
next(err, !!isMember);
|
||||
});
|
||||
}
|
||||
}, function(err, privileges) {
|
||||
|
||||
@@ -468,4 +468,4 @@ accountsController.getNotifications = function(req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = accountsController;
|
||||
module.exports = accountsController;
|
||||
|
||||
@@ -169,4 +169,4 @@ adminController.sounds.get = function(req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = adminController;
|
||||
module.exports = adminController;
|
||||
|
||||
@@ -47,4 +47,4 @@ usersController.getCSV = function(req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = usersController;
|
||||
module.exports = usersController;
|
||||
|
||||
@@ -70,4 +70,4 @@ apiController.getConfig = function(req, res, next) {
|
||||
};
|
||||
|
||||
|
||||
module.exports = apiController;
|
||||
module.exports = apiController;
|
||||
|
||||
@@ -266,4 +266,4 @@ Controllers.outgoing = function(req, res, next) {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Controllers;
|
||||
module.exports = Controllers;
|
||||
|
||||
@@ -181,4 +181,4 @@ topicsController.get = function(req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = topicsController;
|
||||
module.exports = topicsController;
|
||||
|
||||
@@ -100,4 +100,4 @@ usersController.getUsersForSearch = function(req, res, next) {
|
||||
|
||||
|
||||
|
||||
module.exports = usersController;
|
||||
module.exports = usersController;
|
||||
|
||||
@@ -50,4 +50,4 @@ Emailer.send = function(template, uid, params) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Emailer;
|
||||
module.exports = Emailer;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var events = require('events'),
|
||||
eventEmitter = new events.EventEmitter();
|
||||
|
||||
module.exports = eventEmitter;
|
||||
module.exports = eventEmitter;
|
||||
|
||||
@@ -113,4 +113,4 @@ var fs = require('fs'),
|
||||
});
|
||||
};
|
||||
|
||||
}(module.exports));
|
||||
}(module.exports));
|
||||
|
||||
@@ -217,4 +217,4 @@ var async = require('async'),
|
||||
}, callback);
|
||||
};
|
||||
|
||||
}(exports));
|
||||
}(exports));
|
||||
|
||||
@@ -44,4 +44,4 @@ image.convertImageToBase64 = function(path, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = image;
|
||||
module.exports = image;
|
||||
|
||||
@@ -429,4 +429,4 @@ install.save = function (server_conf, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = install;
|
||||
module.exports = install;
|
||||
|
||||
@@ -42,4 +42,4 @@ Languages.list = function(callback) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Languages;
|
||||
module.exports = Languages;
|
||||
|
||||
@@ -147,4 +147,4 @@ var db = require('./database'),
|
||||
});
|
||||
};
|
||||
|
||||
}(exports));
|
||||
}(exports));
|
||||
|
||||
@@ -89,4 +89,4 @@ middleware.buildHeader = function(req, res, next) {
|
||||
module.exports = function(webserver) {
|
||||
app = webserver;
|
||||
return middleware;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -217,4 +217,4 @@ module.exports = function(app, data) {
|
||||
});
|
||||
|
||||
return middleware;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -345,4 +345,4 @@ module.exports = function(webserver) {
|
||||
middleware.admin = require('./admin')(webserver);
|
||||
|
||||
return middleware;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -72,25 +72,21 @@ var fs = require('fs'),
|
||||
db.getSetMembers('plugins:active', next);
|
||||
},
|
||||
function(plugins, next) {
|
||||
if (plugins && Array.isArray(plugins)) {
|
||||
plugins.push(meta.config['theme:id']);
|
||||
if (!plugins || !Array.isArray(plugins)) {
|
||||
next();
|
||||
}
|
||||
|
||||
async.each(plugins, function(plugin, next) {
|
||||
if (!plugin || typeof plugin !== 'string') {
|
||||
return next();
|
||||
}
|
||||
plugins.push(meta.config['theme:id']);
|
||||
|
||||
var modulePath = path.join(__dirname, '../node_modules/', plugin);
|
||||
if (fs.existsSync(modulePath)) {
|
||||
Plugins.loadPlugin(modulePath, next);
|
||||
} else {
|
||||
if (global.env === 'development') {
|
||||
winston.warn('[plugins] Plugin \'' + plugin + '\' not found');
|
||||
}
|
||||
next(); // Ignore this plugin silently
|
||||
}
|
||||
}, next);
|
||||
} else next();
|
||||
plugins = plugins.filter(function(plugin){
|
||||
return plugin && typeof plugin === 'string';
|
||||
}).map(function(plugin){
|
||||
return path.join(__dirname, '../node_modules/', plugin);
|
||||
});
|
||||
|
||||
async.filter(plugins, fs.exists, function(plugins){
|
||||
async.each(plugins, Plugins.loadPlugin, next);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
if (global.env === 'development') winston.info('[plugins] Sorting hooks to fire in priority sequence');
|
||||
@@ -434,28 +430,31 @@ var fs = require('fs'),
|
||||
};
|
||||
|
||||
Plugins.showInstalled = function(callback) {
|
||||
npmPluginPath = path.join(__dirname, '../node_modules');
|
||||
var npmPluginPath = path.join(__dirname, '../node_modules');
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
fs.readdir(npmPluginPath, function(err, dirs) {
|
||||
dirs = dirs.map(function(file) {
|
||||
return path.join(npmPluginPath, file);
|
||||
}).filter(function(file) {
|
||||
if (fs.existsSync(file)) {
|
||||
var stats = fs.statSync(file),
|
||||
isPlugin = file.substr(npmPluginPath.length + 1, 14) === 'nodebb-plugin-' || file.substr(npmPluginPath.length + 1, 14) === 'nodebb-widget-';
|
||||
async.apply(fs.readdir, npmPluginPath),
|
||||
|
||||
if (stats.isDirectory() && isPlugin) return true;
|
||||
else return false;
|
||||
} else {
|
||||
return false;
|
||||
function(dirs, next) {
|
||||
dirs = dirs.filter(function(dir){
|
||||
return dir.substr(0, 14) === 'nodebb-plugin-' || dir.substr(0, 14) === 'nodebb-widget-';
|
||||
}).map(function(dir){
|
||||
return path.join(npmPluginPath, dir);
|
||||
});
|
||||
|
||||
async.filter(dirs, function(dir, callback){
|
||||
fs.stat(dir, function(err, stats){
|
||||
if (err) {
|
||||
return callback(false);
|
||||
}
|
||||
});
|
||||
|
||||
next(err, dirs);
|
||||
callback(stats.isDirectory());
|
||||
})
|
||||
}, function(plugins){
|
||||
next(null, plugins);
|
||||
});
|
||||
},
|
||||
|
||||
function(files, next) {
|
||||
var plugins = [];
|
||||
|
||||
|
||||
@@ -214,4 +214,4 @@
|
||||
uid: uid
|
||||
});
|
||||
});
|
||||
}(exports));
|
||||
}(exports));
|
||||
|
||||
@@ -58,4 +58,4 @@ module.exports = function(app, middleware, controllers) {
|
||||
res.send(200);
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@@ -166,4 +166,4 @@ module.exports = function(app, middleware, controllers){
|
||||
app.get('/category/:category_id.rss', hasCategoryPrivileges, generateForCategory);
|
||||
app.get('/recent.rss', generateForRecent);
|
||||
app.get('/popular.rss', generateForPopular);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -152,4 +152,4 @@ module.exports = function(app, middleware) {
|
||||
require('./debug')(app, middleware, controllers);
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@@ -51,4 +51,4 @@ module.exports = function(app, middleware, controllers) {
|
||||
res.redirect('/404');
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@@ -88,4 +88,4 @@ var path = require('path'),
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = sitemap;
|
||||
module.exports = sitemap;
|
||||
|
||||
@@ -47,4 +47,4 @@ SocketCategories.getTopicCount = function(socket, cid, callback) {
|
||||
categories.getCategoryField(cid, 'topic_count', callback);
|
||||
};
|
||||
|
||||
module.exports = SocketCategories;
|
||||
module.exports = SocketCategories;
|
||||
|
||||
@@ -319,4 +319,4 @@ function emitOnlineUserCount(callback) {
|
||||
|
||||
|
||||
/* Exporting */
|
||||
module.exports = Sockets;
|
||||
module.exports = Sockets;
|
||||
|
||||
@@ -111,4 +111,4 @@ SocketMeta.rooms.getAll = function(socket, data, callback) {
|
||||
|
||||
/* Exports */
|
||||
|
||||
module.exports = SocketMeta;
|
||||
module.exports = SocketMeta;
|
||||
|
||||
@@ -231,4 +231,4 @@ SocketModules.sounds.getMapping = function(socket, data, callback) {
|
||||
meta.sounds.getMapping(callback);
|
||||
};
|
||||
|
||||
module.exports = SocketModules;
|
||||
module.exports = SocketModules;
|
||||
|
||||
@@ -12,4 +12,4 @@ SocketNotifs.getCount = function(socket, data, callback) {
|
||||
user.notifications.getUnreadCount(socket.uid, callback);
|
||||
};
|
||||
|
||||
module.exports = SocketNotifs;
|
||||
module.exports = SocketNotifs;
|
||||
|
||||
@@ -318,4 +318,4 @@ SocketPosts.getCategory = function(socket, pid, callback) {
|
||||
posts.getCidByPid(pid, callback);
|
||||
};
|
||||
|
||||
module.exports = SocketPosts;
|
||||
module.exports = SocketPosts;
|
||||
|
||||
@@ -6,4 +6,4 @@ SocketTools.log = function(socket, data, callback) {
|
||||
//winston.info("captured console.log:", data)
|
||||
};
|
||||
|
||||
module.exports = SocketTools;
|
||||
module.exports = SocketTools;
|
||||
|
||||
@@ -313,4 +313,4 @@ SocketTopics.getTidIndex = function(socket, tid, callback) {
|
||||
categories.getTopicIndex(tid, callback);
|
||||
};
|
||||
|
||||
module.exports = SocketTopics;
|
||||
module.exports = SocketTopics;
|
||||
|
||||
@@ -248,4 +248,4 @@ SocketUser.setStatus = function(socket, status, callback) {
|
||||
|
||||
/* Exports */
|
||||
|
||||
module.exports = SocketUser;
|
||||
module.exports = SocketUser;
|
||||
|
||||
@@ -8,4 +8,4 @@ SocketWidgets.render = function(socket, data, callback) {
|
||||
widgets.render(socket.uid, data, callback);
|
||||
};
|
||||
|
||||
module.exports = SocketWidgets;
|
||||
module.exports = SocketWidgets;
|
||||
|
||||
@@ -293,4 +293,4 @@ var winston = require('winston'),
|
||||
});
|
||||
});
|
||||
};
|
||||
}(exports));
|
||||
}(exports));
|
||||
|
||||
@@ -478,4 +478,4 @@ var async = require('async'),
|
||||
});
|
||||
});
|
||||
};
|
||||
}(exports));
|
||||
}(exports));
|
||||
|
||||
@@ -219,4 +219,4 @@ module.exports = function(Topics) {
|
||||
], callback);
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -99,4 +99,4 @@ module.exports = function(Topics) {
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -223,4 +223,4 @@ module.exports = function(Topics) {
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -628,4 +628,4 @@ Upgrade.upgrade = function(callback) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Upgrade;
|
||||
module.exports = Upgrade;
|
||||
|
||||
@@ -141,4 +141,4 @@ module.exports = function(User) {
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -65,4 +65,4 @@ module.exports = function(User) {
|
||||
db.isSetMember('following:' + uid, theirid, callback);
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -180,4 +180,4 @@ var async = require('async'),
|
||||
});
|
||||
};
|
||||
|
||||
}(exports));
|
||||
}(exports));
|
||||
|
||||
@@ -253,4 +253,4 @@ module.exports = function(User) {
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -89,4 +89,4 @@ var async = require('async'),
|
||||
});
|
||||
};
|
||||
|
||||
}(exports));
|
||||
}(exports));
|
||||
|
||||
@@ -41,4 +41,3 @@ module.exports = function(User) {
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -52,4 +52,4 @@ module.exports = function(User) {
|
||||
language: data.language || meta.config.defaultLang
|
||||
}, callback);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -99,4 +99,4 @@ var async = require('async'),
|
||||
});
|
||||
};
|
||||
|
||||
}(exports));
|
||||
}(exports));
|
||||
|
||||
Reference in New Issue
Block a user