mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
added filterUids method to privileges
used to filter uids on a single category
This commit is contained in:
@@ -20,7 +20,7 @@ helpers.some = function(tasks, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
helpers.allowedTo = function(privilege, uid, cids, callback) {
|
||||
helpers.isUserAllowedTo = function(privilege, uid, cids, callback) {
|
||||
if (parseInt(uid, 10) === 0) {
|
||||
return isGuestAllowedTo(privilege, cids, callback);
|
||||
}
|
||||
@@ -61,6 +61,35 @@ helpers.allowedTo = function(privilege, uid, cids, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
helpers.isUsersAllowedTo = function(privilege, uids, cid, callback) {
|
||||
async.parallel({
|
||||
userPrivilegeExists: function(next) {
|
||||
groups.exists('cid:' + cid + ':privileges:' + privilege, next);
|
||||
},
|
||||
groupPrivilegeExists: function(next) {
|
||||
groups.exists('cid:' + cid + ':privileges:groups:' + privilege, next);
|
||||
},
|
||||
hasUserPrivilege: function(next) {
|
||||
groups.isMembers(uids, 'cid:' + cid + ':privileges:' + privilege, next);
|
||||
},
|
||||
hasGroupPrivilege: function(next) {
|
||||
groups.isMembersOfGroupList(uids, 'cid:' + cid + ':privileges:groups:' + privilege, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var result = [];
|
||||
|
||||
for(var i=0; i<uids.length; ++i) {
|
||||
result.push((!results.userPrivilegeExists && !results.groupPrivilegeExists) || results.hasUserPrivilege[i] || results.hasGroupPrivilege[i]);
|
||||
}
|
||||
|
||||
callback(null, result);
|
||||
});
|
||||
};
|
||||
|
||||
function isGuestAllowedTo(privilege, cids, callback) {
|
||||
var userKeys = [], groupKeys = [];
|
||||
for (var i=0; i<cids.length; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user