more updates to privileges revamp

v1.18.x
Julian Lam 11 years ago
parent 72ca0d6d40
commit 7c8b442dcd

@ -305,6 +305,7 @@ define(['uploader'], function(uploader) {
uid = anchorEl.parents('li[data-uid]').attr('data-uid'), uid = anchorEl.parents('li[data-uid]').attr('data-uid'),
privilege = anchorEl.attr('data-priv'); privilege = anchorEl.attr('data-priv');
e.preventDefault(); e.preventDefault();
e.stopPropagation();
socket.emit('admin.categories.setPrivilege', { socket.emit('admin.categories.setPrivilege', {
cid: cid, cid: cid,
@ -341,6 +342,7 @@ define(['uploader'], function(uploader) {
name = anchorEl.parents('li[data-name]').attr('data-name'), name = anchorEl.parents('li[data-name]').attr('data-name'),
privilege = anchorEl.attr('data-priv'); privilege = anchorEl.attr('data-priv');
e.preventDefault(); e.preventDefault();
e.stopPropagation();
socket.emit('admin.categories.setGroupPrivilege', { socket.emit('admin.categories.setGroupPrivilege', {
cid: cid, cid: cid,

@ -37,7 +37,7 @@ CategoryTools.exists = function(cid, callback) {
CategoryTools.privileges = function(cid, uid, callback) { CategoryTools.privileges = function(cid, uid, callback) {
async.parallel({ async.parallel({
disabled: function(next) { "disabled": function(next) {
categories.getCategoryField(cid, 'disabled', next); categories.getCategoryField(cid, 'disabled', next);
}, },
read: function(next) { read: function(next) {
@ -49,53 +49,39 @@ CategoryTools.privileges = function(cid, uid, callback) {
"topics:reply": function(next) { "topics:reply": function(next) {
internals.isMember('cid:' + cid + ':privileges:topics:reply', uid, next); internals.isMember('cid:' + cid + ':privileges:topics:reply', uid, next);
}, },
// "+r": function(next) { "groups:read": function(next) {
// internals.isMember('cid:' + cid + ':privileges:+r', uid, next); internals.isMemberOfGroupList('cid:' + cid + ':privileges:groups:read', uid, next);
// }, },
// "+w": function(next) { "groups:topics:create": function(next) {
// internals.isMember('cid:' + cid + ':privileges:+w', uid, next); internals.isMemberOfGroupList('cid:' + cid + ':privileges:groups:topics:create', uid, next);
// }, },
// "g+r": function(next) { "groups:topics:reply": function(next) {
// internals.isMemberOfGroupList('cid:' + cid + ':privileges:g+r', uid, next); internals.isMemberOfGroupList('cid:' + cid + ':privileges:groups:topics:reply', uid, next);
// }, },
// "g+w": function(next) { mods: function(next) {
// internals.isMemberOfGroupList('cid:' + cid + ':privileges:g+w', uid, next);
// },
moderator: function(next) {
User.isModerator(uid, cid, next); User.isModerator(uid, cid, next);
}, },
admin: function(next) { admin: function(next) {
User.isAdministrator(uid, next); User.isAdministrator(uid, next);
} }
}, function(err, privileges) { }, function(err, privileges) {
callback(err, !privileges ? null : { if (privileges) {
"+r": privileges['+r'], privileges.meta = {
"+w": privileges['+w'], read: (
"g+r": privileges['g+r'], (
"g+w": privileges['g+w'], parseInt(privileges.disabled, 10) !== 1 &&
read: ( (privileges.read || privileges.read === null) &&
( (privileges['groups:read'] || privileges['groups:read'] === null)
parseInt(privileges.disabled, 10) !== 1 && ) ||
(privileges['+r'] || privileges['+r'] === null) && privileges.mods ||
(privileges['g+r'] || privileges['g+r'] === null) privileges.admin
) || ),
privileges.moderator || editable: privileges.mods || privileges.admin,
privileges.admin view_deleted: privileges.mods || privileges.admin
), };
// write: ( }
// (
// parseInt(privileges.disabled, 10) !== 1 && callback(err, privileges || null);
// (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
});
}); });
}; };

@ -77,7 +77,7 @@ categoriesController.get = function(req, res, next) {
return next(err); return next(err);
} }
if (!categoryPrivileges.read) { if (!categoryPrivileges.meta.read) {
next(new Error('[[error:no-privileges]]')); next(new Error('[[error:no-privileges]]'));
} else { } else {
next(null, categoryPrivileges); next(null, categoryPrivileges);

@ -71,7 +71,7 @@ Controllers.home = function(req, res, next) {
function canSee(category, next) { function canSee(category, next) {
categoryTools.privileges(category.cid, ((req.user) ? req.user.uid || 0 : 0), function(err, privileges) { categoryTools.privileges(category.cid, ((req.user) ? req.user.uid || 0 : 0), function(err, privileges) {
next(!err && privileges.read); next(!err && privileges.meta.read);
}); });
} }

@ -54,6 +54,10 @@ module.exports = function(app, middleware, controllers) {
}); });
app.get('/test', function(req, res) { app.get('/test', function(req, res) {
var tools = require('../categoryTools');
tools.privileges(1, 2, function() {
console.log(arguments);
})
res.send(200); res.send(200);
}); });
}); });

@ -14,7 +14,7 @@ SocketCategories.getRecentReplies = function(socket, cid, callback) {
return callback(err); return callback(err);
} }
if (!privileges || !privileges.read) { if (!privileges || !privileges.meta.read) {
return callback(null, []); return callback(null, []);
} }

@ -290,7 +290,7 @@ SocketTopics.moveAll = function(socket, data, callback) {
return callback(err); 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]]')); return callback(new Error('[[error:no-privileges]]'));
} }

@ -43,14 +43,15 @@ var winston = require('winston'),
} }
} }
}, function(err, results) { }, function(err, results) {
callback(err, !results ? undefined : { if (err) {
read: results.categoryPrivs.read, return callback(err);
write: results.categoryPrivs.write, }
editable: results.categoryPrivs.editable || results.hasEnoughRep,
view_deleted: results.categoryPrivs.view_deleted || results.hasEnoughRep, var privileges = results.categoryPrivs;
moderator: results.categoryPrivs.moderator, privileges.meta.editable = privileges.meta.editable || results.hasEnoughRep;
admin: results.categoryPrivs.admin privileges.meta.view_deleted = privileges.meta.view_deleted || results.hasEnoughRep;
});
callback(null, privileges);
}); });
}; };

@ -185,7 +185,7 @@ var async = require('async'),
function isTopicVisible(topicData, topicInfo) { function isTopicVisible(topicData, topicInfo) {
var deleted = parseInt(topicData.deleted, 10) !== 0; 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({ async.parallel({

@ -101,7 +101,7 @@ module.exports = function(Topics) {
categoryTools.privileges(cid, uid, next); categoryTools.privileges(cid, uid, next);
}, },
function(privileges, next) { function(privileges, next) {
if(!privileges.write) { if(!privileges['topics:create']) {
return next(new Error('[[error:no-privileges]]')); return next(new Error('[[error:no-privileges]]'));
} }
next(); next();

Loading…
Cancel
Save