mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 14:35:47 +01:00
Adding support for restricting category read access based on user groups
This commit is contained in:
@@ -263,4 +263,40 @@
|
||||
});
|
||||
};
|
||||
|
||||
Groups.getCategoryAccess = function(cid, uid, callback){
|
||||
var access = false;
|
||||
// check user group read access level
|
||||
async.series([function(callback){
|
||||
// get groups with read permission
|
||||
db.getObjectField('group:gid', 'cid:' + cid + ':privileges:+gr', function(err, gid){
|
||||
// get the user groups that belong to this read group
|
||||
db.getSetMembers('gid:' + gid + ':members', function (err, gids) {
|
||||
// check if user belong to any of these user groups
|
||||
var groups_check = new Array();
|
||||
gids.forEach(function(cgid){
|
||||
groups_check.push(function(callback){
|
||||
Groups.isMember(uid, cgid, function(err, isMember){
|
||||
if (isMember){
|
||||
access = true;
|
||||
}
|
||||
callback(null, gids);
|
||||
})
|
||||
});
|
||||
});
|
||||
// do a series check. We want to make sure we check all the groups before determining if the user
|
||||
// has access or not.
|
||||
async.series(groups_check, function(err, results){
|
||||
callback(null, results);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}],
|
||||
function(err, results){
|
||||
// if the read group is empty we will asume that read access has been granted to ALL
|
||||
if (results[0].length == 0){ access = true; }
|
||||
callback(false, access);
|
||||
});
|
||||
};
|
||||
|
||||
}(module.exports));
|
||||
|
||||
Reference in New Issue
Block a user