diff --git a/public/src/forum/admin/categories.js b/public/src/forum/admin/categories.js index 2d880336aa..12b5cf7aee 100644 --- a/public/src/forum/admin/categories.js +++ b/public/src/forum/admin/categories.js @@ -305,6 +305,7 @@ define(['uploader'], function(uploader) { uid = anchorEl.parents('li[data-uid]').attr('data-uid'), privilege = anchorEl.attr('data-priv'); e.preventDefault(); + e.stopPropagation(); socket.emit('admin.categories.setPrivilege', { cid: cid, @@ -341,6 +342,7 @@ define(['uploader'], function(uploader) { name = anchorEl.parents('li[data-name]').attr('data-name'), privilege = anchorEl.attr('data-priv'); e.preventDefault(); + e.stopPropagation(); socket.emit('admin.categories.setGroupPrivilege', { cid: cid, diff --git a/src/categoryTools.js b/src/categoryTools.js index 209b3c29a2..69209db0a9 100644 --- a/src/categoryTools.js +++ b/src/categoryTools.js @@ -37,7 +37,7 @@ CategoryTools.exists = function(cid, callback) { CategoryTools.privileges = function(cid, uid, callback) { async.parallel({ - disabled: function(next) { + "disabled": function(next) { categories.getCategoryField(cid, 'disabled', next); }, read: function(next) { @@ -49,53 +49,39 @@ CategoryTools.privileges = function(cid, uid, callback) { "topics:reply": function(next) { internals.isMember('cid:' + cid + ':privileges:topics:reply', uid, next); }, - // "+r": function(next) { - // internals.isMember('cid:' + cid + ':privileges:+r', uid, next); - // }, - // "+w": function(next) { - // internals.isMember('cid:' + cid + ':privileges:+w', uid, next); - // }, - // "g+r": function(next) { - // internals.isMemberOfGroupList('cid:' + cid + ':privileges:g+r', uid, next); - // }, - // "g+w": function(next) { - // internals.isMemberOfGroupList('cid:' + cid + ':privileges:g+w', uid, next); - // }, - moderator: function(next) { + "groups:read": function(next) { + internals.isMemberOfGroupList('cid:' + cid + ':privileges:groups:read', uid, next); + }, + "groups:topics:create": function(next) { + internals.isMemberOfGroupList('cid:' + cid + ':privileges:groups:topics:create', uid, next); + }, + "groups:topics:reply": function(next) { + internals.isMemberOfGroupList('cid:' + cid + ':privileges:groups:topics:reply', uid, next); + }, + mods: function(next) { User.isModerator(uid, cid, next); }, admin: function(next) { User.isAdministrator(uid, next); } }, function(err, privileges) { - callback(err, !privileges ? null : { - "+r": privileges['+r'], - "+w": privileges['+w'], - "g+r": privileges['g+r'], - "g+w": privileges['g+w'], - read: ( - ( - parseInt(privileges.disabled, 10) !== 1 && - (privileges['+r'] || privileges['+r'] === null) && - (privileges['g+r'] || privileges['g+r'] === null) - ) || - privileges.moderator || - privileges.admin - ), - // write: ( - // ( - // parseInt(privileges.disabled, 10) !== 1 && - // (privileges['+w'] || privileges['+w'] === null) && - // (privileges['g+w'] || privileges['g+w'] === null) - // ) || - // privileges.moderator || - // privileges.admin - // ), - editable: privileges.moderator || privileges.admin, - view_deleted: privileges.moderator || privileges.admin, - moderator: privileges.moderator, - admin: privileges.admin - }); + if (privileges) { + privileges.meta = { + read: ( + ( + parseInt(privileges.disabled, 10) !== 1 && + (privileges.read || privileges.read === null) && + (privileges['groups:read'] || privileges['groups:read'] === null) + ) || + privileges.mods || + privileges.admin + ), + editable: privileges.mods || privileges.admin, + view_deleted: privileges.mods || privileges.admin + }; + } + + callback(err, privileges || null); }); }; diff --git a/src/controllers/categories.js b/src/controllers/categories.js index f878b38c05..58fd5e80d5 100644 --- a/src/controllers/categories.js +++ b/src/controllers/categories.js @@ -77,7 +77,7 @@ categoriesController.get = function(req, res, next) { return next(err); } - if (!categoryPrivileges.read) { + if (!categoryPrivileges.meta.read) { next(new Error('[[error:no-privileges]]')); } else { next(null, categoryPrivileges); diff --git a/src/controllers/index.js b/src/controllers/index.js index d361fd85e7..31ea691136 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -71,7 +71,7 @@ Controllers.home = function(req, res, next) { function canSee(category, next) { categoryTools.privileges(category.cid, ((req.user) ? req.user.uid || 0 : 0), function(err, privileges) { - next(!err && privileges.read); + next(!err && privileges.meta.read); }); } diff --git a/src/routes/debug.js b/src/routes/debug.js index ca7a13b665..6d6641615f 100644 --- a/src/routes/debug.js +++ b/src/routes/debug.js @@ -54,6 +54,10 @@ module.exports = function(app, middleware, controllers) { }); app.get('/test', function(req, res) { + var tools = require('../categoryTools'); + tools.privileges(1, 2, function() { + console.log(arguments); + }) res.send(200); }); }); diff --git a/src/socket.io/categories.js b/src/socket.io/categories.js index 3687424bd5..a3ca8abb37 100644 --- a/src/socket.io/categories.js +++ b/src/socket.io/categories.js @@ -14,7 +14,7 @@ SocketCategories.getRecentReplies = function(socket, cid, callback) { return callback(err); } - if (!privileges || !privileges.read) { + if (!privileges || !privileges.meta.read) { return callback(null, []); } diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js index 6ca38f9ce9..48e0c806ac 100644 --- a/src/socket.io/topics.js +++ b/src/socket.io/topics.js @@ -290,7 +290,7 @@ SocketTopics.moveAll = function(socket, data, callback) { return callback(err); } - if (!results.from.admin && (!results.from.moderator || !results.to.moderator)) { + if (!results.from.admin && (!results.from.mods || !results.to.mods)) { return callback(new Error('[[error:no-privileges]]')); } diff --git a/src/threadTools.js b/src/threadTools.js index f2ce8286a3..72d5a5d13e 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -43,14 +43,15 @@ var winston = require('winston'), } } }, function(err, results) { - callback(err, !results ? undefined : { - read: results.categoryPrivs.read, - write: results.categoryPrivs.write, - editable: results.categoryPrivs.editable || results.hasEnoughRep, - view_deleted: results.categoryPrivs.view_deleted || results.hasEnoughRep, - moderator: results.categoryPrivs.moderator, - admin: results.categoryPrivs.admin - }); + if (err) { + return callback(err); + } + + var privileges = results.categoryPrivs; + privileges.meta.editable = privileges.meta.editable || results.hasEnoughRep; + privileges.meta.view_deleted = privileges.meta.view_deleted || results.hasEnoughRep; + + callback(null, privileges); }); }; diff --git a/src/topics.js b/src/topics.js index 37f5062df6..5f626b3d4a 100644 --- a/src/topics.js +++ b/src/topics.js @@ -185,7 +185,7 @@ var async = require('async'), function isTopicVisible(topicData, topicInfo) { var deleted = parseInt(topicData.deleted, 10) !== 0; - return !deleted || (deleted && topicInfo.privileges.view_deleted) || parseInt(topicData.uid, 10) === parseInt(uid, 10); + return !deleted || (deleted && topicInfo.privileges.meta.view_deleted) || parseInt(topicData.uid, 10) === parseInt(uid, 10); } async.parallel({ diff --git a/src/topics/create.js b/src/topics/create.js index 3bfa24a0e4..b121224d05 100644 --- a/src/topics/create.js +++ b/src/topics/create.js @@ -101,7 +101,7 @@ module.exports = function(Topics) { categoryTools.privileges(cid, uid, next); }, function(privileges, next) { - if(!privileges.write) { + if(!privileges['topics:create']) { return next(new Error('[[error:no-privileges]]')); } next();