fix dependency errors

v1.18.x
barisusakli 9 years ago
parent 56118ec1da
commit fa9f1ac7fe

@ -7,7 +7,7 @@ var db = require('./database');
var user = require('./user'); var user = require('./user');
var Groups = require('./groups'); var Groups = require('./groups');
var plugins = require('./plugins'); var plugins = require('./plugins');
var privileges = require('./privileges');
(function(Categories) { (function(Categories) {
@ -102,7 +102,6 @@ var plugins = require('./plugins');
}; };
Categories.getCategoriesByPrivilege = function(set, uid, privilege, callback) { Categories.getCategoriesByPrivilege = function(set, uid, privilege, callback) {
var privileges = require('./privileges');
async.waterfall([ async.waterfall([
function(next) { function(next) {
db.getSortedSetRange(set, 0, -1, next); db.getSortedSetRange(set, 0, -1, next);
@ -239,7 +238,6 @@ var plugins = require('./plugins');
}; };
function getChildrenRecursive(category, uid, callback) { function getChildrenRecursive(category, uid, callback) {
var privileges = require('./privileges');
async.waterfall([ async.waterfall([
function (next) { function (next) {
db.getSortedSetRange('cid:' + category.cid + ':children', 0, -1, next); db.getSortedSetRange('cid:' + category.cid + ':children', 0, -1, next);

@ -5,6 +5,7 @@ var async = require('async');
var db = require('../database'); var db = require('../database');
var groups = require('../groups'); var groups = require('../groups');
var plugins = require('../plugins'); var plugins = require('../plugins');
var privileges = require('../privileges');
var utils = require('../../public/src/utils'); var utils = require('../../public/src/utils');
module.exports = function(Categories) { module.exports = function(Categories) {
@ -49,7 +50,7 @@ module.exports = function(Categories) {
category = data.category; category = data.category;
var defaultPrivileges = ['find', 'read', 'topics:read', 'topics:create', 'topics:reply', 'posts:edit', 'posts:delete', 'topics:delete', 'upload:post:image']; var defaultPrivileges = ['find', 'read', 'topics:read', 'topics:create', 'topics:reply', 'posts:edit', 'posts:delete', 'topics:delete', 'upload:post:image'];
var privileges = require('../privileges');
async.series([ async.series([
async.apply(db.setObject, 'category:' + category.cid, category), async.apply(db.setObject, 'category:' + category.cid, category),
function (next) { function (next) {
@ -138,7 +139,6 @@ module.exports = function(Categories) {
}; };
Categories.copyPrivilegesFrom = function(fromCid, toCid, callback) { Categories.copyPrivilegesFrom = function(fromCid, toCid, callback) {
var privileges = require('../privileges');
async.each(privileges.privilegeList, function(privilege, next) { async.each(privileges.privilegeList, function(privilege, next) {
copyPrivilege(privilege, fromCid, toCid, next); copyPrivilege(privilege, fromCid, toCid, next);
}, callback); }, callback);

@ -6,6 +6,7 @@ var batch = require('../batch');
var plugins = require('../plugins'); var plugins = require('../plugins');
var topics = require('../topics'); var topics = require('../topics');
var groups = require('../groups'); var groups = require('../groups');
var privileges = require('../privileges');
module.exports = function(Categories) { module.exports = function(Categories) {
@ -45,7 +46,6 @@ module.exports = function(Categories) {
], next); ], next);
}, },
function(next) { function(next) {
var privileges = require('../privileges');
async.each(privileges.privilegeList, function(privilege, next) { async.each(privileges.privilegeList, function(privilege, next) {
groups.destroy('cid:' + cid + ':privileges:' + privilege, next); groups.destroy('cid:' + cid + ':privileges:' + privilege, next);
}, next); }, next);

@ -9,7 +9,7 @@ var _ = require('underscore');
var db = require('../database'); var db = require('../database');
var posts = require('../posts'); var posts = require('../posts');
var topics = require('../topics'); var topics = require('../topics');
var categories = require('../categories'); var privileges = require('../privileges');
module.exports = function(Categories) { module.exports = function(Categories) {
@ -18,7 +18,7 @@ module.exports = function(Categories) {
if (!parseInt(count, 10)) { if (!parseInt(count, 10)) {
return callback(null, []); return callback(null, []);
} }
var privileges = require('../privileges');
async.waterfall([ async.waterfall([
function(next) { function(next) {
db.getSortedSetRevRange('cid:' + cid + ':pids', 0, count - 1, next); db.getSortedSetRevRange('cid:' + cid + ':pids', 0, count - 1, next);
@ -36,7 +36,7 @@ module.exports = function(Categories) {
if (!Array.isArray(categoryData) || !categoryData.length) { if (!Array.isArray(categoryData) || !categoryData.length) {
return callback(); return callback();
} }
var privileges = require('../privileges');
async.waterfall([ async.waterfall([
function(next) { function(next) {
async.map(categoryData, getRecentTopicTids, next); async.map(categoryData, getRecentTopicTids, next);
@ -121,7 +121,7 @@ module.exports = function(Categories) {
}); });
async.parallel({ async.parallel({
categoryData: async.apply(categories.getCategoriesFields, cids, ['cid', 'parentCid']), categoryData: async.apply(Categories.getCategoriesFields, cids, ['cid', 'parentCid']),
teasers: async.apply(topics.getTeasers, _topicData), teasers: async.apply(topics.getTeasers, _topicData),
}, next); }, next);
}, },

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

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

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

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

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

Loading…
Cancel
Save