Merge branch 'code-quality' of https://github.com/miksago/NodeBB into miksago-code-quality

Conflicts:
	src/database.js
This commit is contained in:
psychobunny
2014-04-14 17:36:10 -04:00
107 changed files with 485 additions and 466 deletions

View File

@@ -324,4 +324,4 @@ var db = require('./database'),
emitter.on('event:newpost', Categories.onNewPostMade);
}(exports));
}(exports));

View File

@@ -80,4 +80,4 @@ module.exports = function(Categories) {
}
});
};
};
};

View File

@@ -43,4 +43,4 @@ module.exports = function(Categories) {
});
};
};
};

View File

@@ -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) {

View File

@@ -468,4 +468,4 @@ accountsController.getNotifications = function(req, res, next) {
});
};
module.exports = accountsController;
module.exports = accountsController;

View File

@@ -169,4 +169,4 @@ adminController.sounds.get = function(req, res, next) {
});
};
module.exports = adminController;
module.exports = adminController;

View File

@@ -47,4 +47,4 @@ usersController.getCSV = function(req, res, next) {
});
};
module.exports = usersController;
module.exports = usersController;

View File

@@ -70,4 +70,4 @@ apiController.getConfig = function(req, res, next) {
};
module.exports = apiController;
module.exports = apiController;

View File

@@ -266,4 +266,4 @@ Controllers.outgoing = function(req, res, next) {
}
};
module.exports = Controllers;
module.exports = Controllers;

View File

@@ -181,4 +181,4 @@ topicsController.get = function(req, res, next) {
});
};
module.exports = topicsController;
module.exports = topicsController;

View File

@@ -100,4 +100,4 @@ usersController.getUsersForSearch = function(req, res, next) {
module.exports = usersController;
module.exports = usersController;

View File

@@ -50,4 +50,4 @@ Emailer.send = function(template, uid, params) {
});
};
module.exports = Emailer;
module.exports = Emailer;

View File

@@ -1,4 +1,4 @@
var events = require('events'),
eventEmitter = new events.EventEmitter();
module.exports = eventEmitter;
module.exports = eventEmitter;

View File

@@ -113,4 +113,4 @@ var fs = require('fs'),
});
};
}(module.exports));
}(module.exports));

View File

@@ -217,4 +217,4 @@ var async = require('async'),
}, callback);
};
}(exports));
}(exports));

View File

@@ -44,4 +44,4 @@ image.convertImageToBase64 = function(path, callback) {
});
};
module.exports = image;
module.exports = image;

View File

@@ -429,4 +429,4 @@ install.save = function (server_conf, callback) {
});
};
module.exports = install;
module.exports = install;

View File

@@ -42,4 +42,4 @@ Languages.list = function(callback) {
});
};
module.exports = Languages;
module.exports = Languages;

View File

@@ -147,4 +147,4 @@ var db = require('./database'),
});
};
}(exports));
}(exports));

View File

@@ -89,4 +89,4 @@ middleware.buildHeader = function(req, res, next) {
module.exports = function(webserver) {
app = webserver;
return middleware;
};
};

View File

@@ -217,4 +217,4 @@ module.exports = function(app, data) {
});
return middleware;
};
};

View File

@@ -345,4 +345,4 @@ module.exports = function(webserver) {
middleware.admin = require('./admin')(webserver);
return middleware;
};
};

View File

@@ -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 = [];

View File

@@ -214,4 +214,4 @@
uid: uid
});
});
}(exports));
}(exports));

View File

@@ -58,4 +58,4 @@ module.exports = function(app, middleware, controllers) {
res.send(200);
});
});
};
};

View File

@@ -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);
};
};

View File

@@ -152,4 +152,4 @@ module.exports = function(app, middleware) {
require('./debug')(app, middleware, controllers);
}
});
};
};

View File

@@ -51,4 +51,4 @@ module.exports = function(app, middleware, controllers) {
res.redirect('/404');
}
});
};
};

View File

@@ -88,4 +88,4 @@ var path = require('path'),
}
};
module.exports = sitemap;
module.exports = sitemap;

View File

@@ -47,4 +47,4 @@ SocketCategories.getTopicCount = function(socket, cid, callback) {
categories.getCategoryField(cid, 'topic_count', callback);
};
module.exports = SocketCategories;
module.exports = SocketCategories;

View File

@@ -319,4 +319,4 @@ function emitOnlineUserCount(callback) {
/* Exporting */
module.exports = Sockets;
module.exports = Sockets;

View File

@@ -111,4 +111,4 @@ SocketMeta.rooms.getAll = function(socket, data, callback) {
/* Exports */
module.exports = SocketMeta;
module.exports = SocketMeta;

View File

@@ -231,4 +231,4 @@ SocketModules.sounds.getMapping = function(socket, data, callback) {
meta.sounds.getMapping(callback);
};
module.exports = SocketModules;
module.exports = SocketModules;

View File

@@ -12,4 +12,4 @@ SocketNotifs.getCount = function(socket, data, callback) {
user.notifications.getUnreadCount(socket.uid, callback);
};
module.exports = SocketNotifs;
module.exports = SocketNotifs;

View File

@@ -318,4 +318,4 @@ SocketPosts.getCategory = function(socket, pid, callback) {
posts.getCidByPid(pid, callback);
};
module.exports = SocketPosts;
module.exports = SocketPosts;

View File

@@ -6,4 +6,4 @@ SocketTools.log = function(socket, data, callback) {
//winston.info("captured console.log:", data)
};
module.exports = SocketTools;
module.exports = SocketTools;

View File

@@ -313,4 +313,4 @@ SocketTopics.getTidIndex = function(socket, tid, callback) {
categories.getTopicIndex(tid, callback);
};
module.exports = SocketTopics;
module.exports = SocketTopics;

View File

@@ -248,4 +248,4 @@ SocketUser.setStatus = function(socket, status, callback) {
/* Exports */
module.exports = SocketUser;
module.exports = SocketUser;

View File

@@ -8,4 +8,4 @@ SocketWidgets.render = function(socket, data, callback) {
widgets.render(socket.uid, data, callback);
};
module.exports = SocketWidgets;
module.exports = SocketWidgets;

View File

@@ -293,4 +293,4 @@ var winston = require('winston'),
});
});
};
}(exports));
}(exports));

View File

@@ -478,4 +478,4 @@ var async = require('async'),
});
});
};
}(exports));
}(exports));

View File

@@ -219,4 +219,4 @@ module.exports = function(Topics) {
], callback);
};
};
};

View File

@@ -99,4 +99,4 @@ module.exports = function(Topics) {
});
});
};
};
};

View File

@@ -223,4 +223,4 @@ module.exports = function(Topics) {
};
};
};

View File

@@ -628,4 +628,4 @@ Upgrade.upgrade = function(callback) {
});
};
module.exports = Upgrade;
module.exports = Upgrade;

View File

@@ -141,4 +141,4 @@ module.exports = function(User) {
});
});
};
};
};

View File

@@ -65,4 +65,4 @@ module.exports = function(User) {
db.isSetMember('following:' + uid, theirid, callback);
};
};
};

View File

@@ -180,4 +180,4 @@ var async = require('async'),
});
};
}(exports));
}(exports));

View File

@@ -253,4 +253,4 @@ module.exports = function(User) {
}
};
};
};

View File

@@ -89,4 +89,4 @@ var async = require('async'),
});
};
}(exports));
}(exports));

View File

@@ -41,4 +41,3 @@ module.exports = function(User) {
});
};
};

View File

@@ -52,4 +52,4 @@ module.exports = function(User) {
language: data.language || meta.config.defaultLang
}, callback);
};
};
};

View File

@@ -99,4 +99,4 @@ var async = require('async'),
});
};
}(exports));
}(exports));