diff --git a/src/categories.js b/src/categories.js index 46af3f1c5a..539a643f80 100644 --- a/src/categories.js +++ b/src/categories.js @@ -7,7 +7,7 @@ var db = require('./database'); var user = require('./user'); var Groups = require('./groups'); var plugins = require('./plugins'); - +var privileges = require('./privileges'); (function(Categories) { @@ -102,7 +102,6 @@ var plugins = require('./plugins'); }; Categories.getCategoriesByPrivilege = function(set, uid, privilege, callback) { - var privileges = require('./privileges'); async.waterfall([ function(next) { db.getSortedSetRange(set, 0, -1, next); @@ -239,7 +238,6 @@ var plugins = require('./plugins'); }; function getChildrenRecursive(category, uid, callback) { - var privileges = require('./privileges'); async.waterfall([ function (next) { db.getSortedSetRange('cid:' + category.cid + ':children', 0, -1, next); diff --git a/src/categories/create.js b/src/categories/create.js index fc841679d2..5c3a81578d 100644 --- a/src/categories/create.js +++ b/src/categories/create.js @@ -5,6 +5,7 @@ var async = require('async'); var db = require('../database'); var groups = require('../groups'); var plugins = require('../plugins'); +var privileges = require('../privileges'); var utils = require('../../public/src/utils'); module.exports = function(Categories) { @@ -49,7 +50,7 @@ module.exports = function(Categories) { category = data.category; 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.apply(db.setObject, 'category:' + category.cid, category), function (next) { @@ -138,7 +139,6 @@ module.exports = function(Categories) { }; Categories.copyPrivilegesFrom = function(fromCid, toCid, callback) { - var privileges = require('../privileges'); async.each(privileges.privilegeList, function(privilege, next) { copyPrivilege(privilege, fromCid, toCid, next); }, callback); diff --git a/src/categories/delete.js b/src/categories/delete.js index e7713bb426..897e45916e 100644 --- a/src/categories/delete.js +++ b/src/categories/delete.js @@ -6,6 +6,7 @@ var batch = require('../batch'); var plugins = require('../plugins'); var topics = require('../topics'); var groups = require('../groups'); +var privileges = require('../privileges'); module.exports = function(Categories) { @@ -45,7 +46,6 @@ module.exports = function(Categories) { ], next); }, function(next) { - var privileges = require('../privileges'); async.each(privileges.privilegeList, function(privilege, next) { groups.destroy('cid:' + cid + ':privileges:' + privilege, next); }, next); diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js index bd89939078..c7a9e9cb67 100644 --- a/src/categories/recentreplies.js +++ b/src/categories/recentreplies.js @@ -9,7 +9,7 @@ var _ = require('underscore'); var db = require('../database'); var posts = require('../posts'); var topics = require('../topics'); -var categories = require('../categories'); +var privileges = require('../privileges'); module.exports = function(Categories) { @@ -18,7 +18,7 @@ module.exports = function(Categories) { if (!parseInt(count, 10)) { return callback(null, []); } - var privileges = require('../privileges'); + async.waterfall([ function(next) { db.getSortedSetRevRange('cid:' + cid + ':pids', 0, count - 1, next); @@ -36,7 +36,7 @@ module.exports = function(Categories) { if (!Array.isArray(categoryData) || !categoryData.length) { return callback(); } - var privileges = require('../privileges'); + async.waterfall([ function(next) { async.map(categoryData, getRecentTopicTids, next); @@ -121,7 +121,7 @@ module.exports = function(Categories) { }); async.parallel({ - categoryData: async.apply(categories.getCategoriesFields, cids, ['cid', 'parentCid']), + categoryData: async.apply(Categories.getCategoriesFields, cids, ['cid', 'parentCid']), teasers: async.apply(topics.getTeasers, _topicData), }, next); }, diff --git a/src/privileges/categories.js b/src/privileges/categories.js index bebb50f4a9..ad07b6eda3 100644 --- a/src/privileges/categories.js +++ b/src/privileges/categories.js @@ -4,10 +4,7 @@ var async = require('async'); var _ = require('underscore'); -var user = require('../user'); -var groups = require('../groups'); var helpers = require('./helpers'); -var plugins = require('../plugins'); module.exports = function(privileges) { @@ -15,6 +12,9 @@ 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,6 +156,7 @@ 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); @@ -178,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, @@ -196,6 +197,7 @@ 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); @@ -220,6 +222,7 @@ module.exports = function(privileges) { return callback(null, false); } var categories = require('../categories'); + var user = require('../user'); categories.getCategoryField(cid, 'disabled', function(err, disabled) { if (err) { return callback(err); @@ -270,6 +273,7 @@ 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); @@ -294,7 +298,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); @@ -318,10 +322,12 @@ 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); }; @@ -332,6 +338,7 @@ 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); @@ -352,6 +359,8 @@ 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) { @@ -382,6 +391,7 @@ 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) { diff --git a/src/privileges/helpers.js b/src/privileges/helpers.js index 7b5cb0c561..d15a2f3787 100644 --- a/src/privileges/helpers.js +++ b/src/privileges/helpers.js @@ -2,7 +2,6 @@ 'use strict'; var async = require('async'); -var groups = require('../groups'); var helpers = {}; @@ -27,6 +26,7 @@ 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,6 +49,7 @@ 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); @@ -75,7 +76,7 @@ function isGuestAllowedTo(privilege, cids, callback) { for (var i=0; i