partially revert fa9f1ac7fe

extending module.exports instead of overwriting fixes the issue
v1.18.x
barisusakli 9 years ago
parent 3dae8f5529
commit b933385b76

@ -1,6 +1,6 @@
"use strict";
var privileges = {};
var privileges = module.exports;
privileges.userPrivilegeList = [
'find',
@ -38,5 +38,3 @@ require('./privileges/categories')(privileges);
require('./privileges/topics')(privileges);
require('./privileges/posts')(privileges);
require('./privileges/users')(privileges);
module.exports = privileges;

@ -4,7 +4,11 @@
var async = require('async');
var _ = require('underscore');
var categories = require('../categories');
var user = require('../user');
var groups = require('../groups');
var helpers = require('./helpers');
var plugins = require('../plugins');
module.exports = function(privileges) {
@ -12,9 +16,6 @@ module.exports = function(privileges) {
privileges.categories.list = function(cid, callback) {
// Method used in admin/category controller to show all users/groups with privs in that given cid
var plugins = require('../plugins');
var groups = require('../groups');
var user = require('../user');
var privilegeLabels = [
{name: 'Find Category'},
@ -156,7 +157,6 @@ module.exports = function(privileges) {
};
privileges.categories.get = function(cid, uid, callback) {
var user = require('../user');
async.parallel({
'topics:create': function(next) {
helpers.isUserAllowedTo('topics:create', uid, [cid], next);
@ -179,7 +179,7 @@ module.exports = function(privileges) {
}
var isAdminOrMod = results.isAdministrator || results.isModerator;
var plugins = require('../plugins');
plugins.fireHook('filter:privileges.categories.get', {
cid: cid,
uid: uid,
@ -197,7 +197,6 @@ module.exports = function(privileges) {
if (!parseInt(uid, 10)) {
return callback(null, false);
}
var user = require('../user');
helpers.some([
function (next) {
user.isModerator(uid, cid, next);
@ -221,8 +220,7 @@ module.exports = function(privileges) {
if (!cid) {
return callback(null, false);
}
var categories = require('../categories');
var user = require('../user');
categories.getCategoryField(cid, 'disabled', function(err, disabled) {
if (err) {
return callback(err);
@ -272,8 +270,6 @@ module.exports = function(privileges) {
};
privileges.categories.getBase = function(privilege, cids, uid, callback) {
var categories = require('../categories');
var user = require('../user');
async.parallel({
categories: function(next) {
categories.getCategoriesFields(cids, ['disabled'], next);
@ -298,7 +294,7 @@ module.exports = function(privileges) {
uids = uids.filter(function(uid, index, array) {
return array.indexOf(uid) === index;
});
var user = require('../user');
async.parallel({
allowedTo: function(next) {
helpers.isUsersAllowedTo(privilege, uids, cid, next);
@ -322,12 +318,10 @@ module.exports = function(privileges) {
};
privileges.categories.give = function(privileges, cid, groupName, callback) {
var groups = require('../groups');
giveOrRescind(groups.join, privileges, cid, groupName, callback);
};
privileges.categories.rescind = function(privileges, cid, groupName, callback) {
var groups = require('../groups');
giveOrRescind(groups.leave, privileges, cid, groupName, callback);
};
@ -338,7 +332,6 @@ module.exports = function(privileges) {
}
privileges.categories.canMoveAllTopics = function(currentCid, targetCid, uid, callback) {
var user = require('../user');
async.parallel({
isAdministrator: function(next) {
user.isAdministrator(uid, next);
@ -359,8 +352,6 @@ module.exports = function(privileges) {
};
privileges.categories.userPrivileges = function(cid, uid, callback) {
var user = require('../user');
var groups = require('../groups');
async.parallel({
find: async.apply(groups.isMember, uid, 'cid:' + cid + ':privileges:find'),
read: function(next) {
@ -391,7 +382,6 @@ module.exports = function(privileges) {
};
privileges.categories.groupPrivileges = function(cid, groupName, callback) {
var groups = require('../groups');
async.parallel({
'groups:find': async.apply(groups.isMember, groupName, 'cid:' + cid + ':privileges:groups:find'),
'groups:read': function(next) {

@ -2,6 +2,7 @@
'use strict';
var async = require('async');
var groups = require('../groups');
var helpers = {};
@ -26,7 +27,6 @@ helpers.isUserAllowedTo = function(privilege, uid, cids, callback) {
groupKeys.push('cid:' + cids[i] + ':privileges:groups:' + privilege);
}
var groups = require('../groups');
async.parallel({
hasUserPrivilege: function(next) {
groups.isMemberOfGroups(uid, userKeys, next);
@ -49,7 +49,6 @@ helpers.isUserAllowedTo = function(privilege, uid, cids, callback) {
};
helpers.isUsersAllowedTo = function(privilege, uids, cid, callback) {
var groups = require('../groups');
async.parallel({
hasUserPrivilege: function(next) {
groups.isMembers(uids, 'cid:' + cid + ':privileges:' + privilege, next);
@ -76,7 +75,7 @@ function isGuestAllowedTo(privilege, cids, callback) {
for (var i=0; i<cids.length; ++i) {
groupKeys.push('cid:' + cids[i] + ':privileges:groups:' + privilege);
}
var groups = require('../groups');
groups.isMemberOfGroups('guests', groupKeys, callback);
}

@ -3,7 +3,12 @@
var async = require('async');
var meta = require('../meta');
var posts = require('../posts');
var topics = require('../topics');
var user = require('../user');
var helpers = require('./helpers');
var plugins = require('../plugins');
module.exports = function(privileges) {
@ -13,8 +18,7 @@ module.exports = function(privileges) {
if (!Array.isArray(pids) || !pids.length) {
return callback(null, []);
}
var posts = require('../posts');
var user = require('../user');
async.waterfall([
function(next) {
posts.getCidsByPids(pids, next);
@ -55,7 +59,6 @@ module.exports = function(privileges) {
};
privileges.posts.can = function(privilege, pid, uid, callback) {
var posts = require('../posts');
posts.getCidByPid(pid, function(err, cid) {
if (err) {
return callback(err);
@ -66,8 +69,6 @@ module.exports = function(privileges) {
};
privileges.posts.filter = function(privilege, pids, uid, callback) {
var posts = require('../posts');
var topics = require('../topics');
if (!Array.isArray(pids) || !pids.length) {
return callback(null, []);
}
@ -126,7 +127,6 @@ module.exports = function(privileges) {
return post.pid;
});
var plugins = require('../plugins');
plugins.fireHook('filter:privileges.posts.filter', {
privilege: privilege,
uid: uid,
@ -155,12 +155,7 @@ module.exports = function(privileges) {
};
privileges.posts.canDelete = function(pid, uid, callback) {
var posts = require('../posts');
var topics = require('../topics');
var meta = require('../meta');
var postData;
async.waterfall([
function(next) {
posts.getPostFields(pid, ['tid', 'timestamp'], next);
@ -201,7 +196,6 @@ module.exports = function(privileges) {
};
privileges.posts.canMove = function(pid, uid, callback) {
var posts = require('../posts');
posts.isMain(pid, function(err, isMain) {
if (err || isMain) {
return callback(err || new Error('[[error:cant-move-mainpost]]'));
@ -211,7 +205,6 @@ module.exports = function(privileges) {
};
privileges.posts.canPurge = function(pid, uid, callback) {
var posts = require('../posts');
async.waterfall([
function (next) {
posts.getCidByPid(pid, next);
@ -230,10 +223,6 @@ module.exports = function(privileges) {
};
function isPostEditable(pid, uid, callback) {
var posts = require('../posts');
var topics = require('../topics');
var meta = require('../meta');
var tid;
async.waterfall([
function(next) {
@ -264,8 +253,6 @@ module.exports = function(privileges) {
}
function isAdminOrMod(pid, uid, callback) {
var posts = require('../posts');
var user = require('../user');
helpers.some([
function(next) {
posts.getCidByPid(pid, function(err, cid) {

@ -3,17 +3,18 @@
var async = require('async');
var meta = require('../meta');
var topics = require('../topics');
var user = require('../user');
var helpers = require('./helpers');
var categories = require('../categories');
var plugins = require('../plugins');
module.exports = function(privileges) {
privileges.topics = {};
privileges.topics.get = function(tid, uid, callback) {
var topics = require('../topics');
var user = require('../user');
var categories = require('../categories');
var plugins = require('../plugins');
var topic;
async.waterfall([
async.apply(topics.getTopicFields, tid, ['cid', 'uid', 'locked', 'deleted']),
@ -67,7 +68,6 @@ module.exports = function(privileges) {
};
privileges.topics.can = function(privilege, tid, uid, callback) {
var topics = require('../topics');
topics.getTopicField(tid, 'cid', function(err, cid) {
if (err) {
return callback(err);
@ -83,7 +83,6 @@ module.exports = function(privileges) {
}
var cids;
var topicsData;
var topics = require('../topics');
async.waterfall([
function(next) {
topics.getTopicsFields(tids, ['tid', 'cid', 'deleted'], next);
@ -114,7 +113,6 @@ module.exports = function(privileges) {
return topic.tid;
});
var plugins = require('../plugins');
plugins.fireHook('filter:privileges.topics.filter', {
privilege: privilege,
uid: uid,
@ -135,9 +133,6 @@ module.exports = function(privileges) {
return array.indexOf(uid) === index;
});
var topics = require('../topics');
var categories = require('../categories');
var user = require('../user');
async.waterfall([
function(next) {
topics.getTopicFields(tid, ['tid', 'cid', 'deleted'], next);
@ -173,7 +168,6 @@ module.exports = function(privileges) {
};
privileges.topics.canPurge = function(tid, uid, callback) {
var topics = require('../topics');
async.waterfall([
function (next) {
topics.getTopicField(tid, 'cid', next);
@ -192,9 +186,6 @@ module.exports = function(privileges) {
};
privileges.topics.canDelete = function(tid, uid, callback) {
var topics = require('../topics');
var user = require('../user');
var meta = require('../meta');
var topicData;
async.waterfall([
function(next) {
@ -239,7 +230,6 @@ module.exports = function(privileges) {
};
privileges.topics.isOwnerOrAdminOrMod = function(tid, uid, callback) {
var topics = require('../topics');
helpers.some([
function(next) {
topics.isOwner(tid, uid, next);
@ -252,8 +242,6 @@ module.exports = function(privileges) {
privileges.topics.isAdminOrMod = function(tid, uid, callback) {
var topics = require('../topics');
var user = require('../user');
helpers.some([
function(next) {
topics.getTopicField(tid, 'cid', function(err, cid) {

@ -3,12 +3,14 @@
var async = require('async');
var groups = require('../groups');
var plugins = require('../plugins');
module.exports = function(privileges) {
privileges.users = {};
privileges.users.isAdministrator = function(uid, callback) {
var groups = require('../groups');
if (Array.isArray(uid)) {
groups.isMembers(uid, 'administrators', callback);
} else {
@ -17,7 +19,6 @@ module.exports = function(privileges) {
};
privileges.users.isGlobalModerator = function(uid, callback) {
var groups = require('../groups');
if (Array.isArray(uid)) {
groups.isMembers(uid, 'Global Moderators', callback);
} else {
@ -62,7 +63,7 @@ module.exports = function(privileges) {
var groupListNames = uniqueCids.map(function(cid) {
return 'cid:' + cid + ':privileges:groups:moderate';
});
var groups = require('../groups');
async.parallel({
user: async.apply(groups.isMemberOfGroups, uid, groupNames),
group: async.apply(groups.isMemberOfGroupsList, uid, groupListNames)
@ -90,7 +91,6 @@ module.exports = function(privileges) {
}
function isModeratorsOfCategory(cid, uids, callback) {
var groups = require('../groups');
async.parallel([
async.apply(privileges.users.isGlobalModerator, uids),
async.apply(groups.isMembers, uids, 'cid:' + cid + ':privileges:mods'),
@ -109,7 +109,6 @@ module.exports = function(privileges) {
}
function isModeratorOfCategory(cid, uid, callback) {
var groups = require('../groups');
async.parallel([
async.apply(privileges.users.isGlobalModerator, uid),
async.apply(groups.isMember, uid, 'cid:' + cid + ':privileges:mods'),
@ -125,7 +124,6 @@ module.exports = function(privileges) {
}
function filterIsModerator(cid, uid, isModerator, callback) {
var plugins = require('../plugins');
plugins.fireHook('filter:user.isModerator', {uid: uid, cid: cid, isModerator: isModerator}, function(err, data) {
if (err) {
return callback(err);

Loading…
Cancel
Save