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'),
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,

@ -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);
});
};

@ -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);

@ -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);
});
}

@ -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);
});
});

@ -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, []);
}

@ -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]]'));
}

@ -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);
});
};

@ -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({

@ -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();

Loading…
Cancel
Save