|
|
|
@ -155,6 +155,8 @@ module.exports = function (privileges) {
|
|
|
|
|
|
|
|
|
|
privileges.categories.get = function (cid, uid, callback) {
|
|
|
|
|
var privs = ['topics:create', 'topics:read', 'read'];
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
privileges: function (next) {
|
|
|
|
|
helpers.isUserAllowedTo(privs, uid, cid, next);
|
|
|
|
@ -165,10 +167,9 @@ module.exports = function (privileges) {
|
|
|
|
|
isModerator: function (next) {
|
|
|
|
|
user.isModerator(uid, cid, next);
|
|
|
|
|
},
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
var privData = _.object(privs, results.privileges);
|
|
|
|
|
var isAdminOrMod = results.isAdministrator || results.isModerator;
|
|
|
|
|
|
|
|
|
@ -181,8 +182,9 @@ module.exports = function (privileges) {
|
|
|
|
|
editable: isAdminOrMod,
|
|
|
|
|
view_deleted: isAdminOrMod,
|
|
|
|
|
isAdminOrMod: isAdminOrMod,
|
|
|
|
|
}, callback);
|
|
|
|
|
});
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
privileges.categories.isAdminOrMod = function (cid, uid, callback) {
|
|
|
|
@ -213,15 +215,14 @@ module.exports = function (privileges) {
|
|
|
|
|
return callback(null, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
categories.getCategoryField(cid, 'disabled', function (err, disabled) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
categories.getCategoryField(cid, 'disabled', next);
|
|
|
|
|
},
|
|
|
|
|
function (disabled, next) {
|
|
|
|
|
if (parseInt(disabled, 10) === 1) {
|
|
|
|
|
return callback(null, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
helpers.some([
|
|
|
|
|
function (next) {
|
|
|
|
|
helpers.isUserAllowedTo(privilege, uid, [cid], function (err, results) {
|
|
|
|
@ -234,8 +235,9 @@ module.exports = function (privileges) {
|
|
|
|
|
function (next) {
|
|
|
|
|
user.isAdministrator(uid, next);
|
|
|
|
|
},
|
|
|
|
|
], next);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
privileges.categories.filterCids = function (privilege, cids, uid, callback) {
|
|
|
|
@ -247,18 +249,19 @@ module.exports = function (privileges) {
|
|
|
|
|
return array.indexOf(cid) === index;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
privileges.categories.getBase(privilege, cids, uid, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
privileges.categories.getBase(privilege, cids, uid, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
cids = cids.filter(function (cid, index) {
|
|
|
|
|
return !results.categories[index].disabled &&
|
|
|
|
|
(results.allowedTo[index] || results.isAdmin || results.isModerators[index]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
callback(null, cids.filter(Boolean));
|
|
|
|
|
});
|
|
|
|
|
next(null, cids.filter(Boolean));
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
privileges.categories.getBase = function (privilege, cids, uid, callback) {
|
|
|
|
@ -287,6 +290,8 @@ module.exports = function (privileges) {
|
|
|
|
|
return array.indexOf(uid) === index;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
allowedTo: function (next) {
|
|
|
|
|
helpers.isUsersAllowedTo(privilege, uids, cid, next);
|
|
|
|
@ -297,16 +302,15 @@ module.exports = function (privileges) {
|
|
|
|
|
isAdmin: function (next) {
|
|
|
|
|
user.isAdministrator(uids, next);
|
|
|
|
|
},
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
uids = uids.filter(function (uid, index) {
|
|
|
|
|
return results.allowedTo[index] || results.isModerators[index] || results.isAdmin[index];
|
|
|
|
|
});
|
|
|
|
|
callback(null, uids);
|
|
|
|
|
});
|
|
|
|
|
next(null, uids);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
privileges.categories.give = function (privileges, cid, groupName, callback) {
|
|
|
|
@ -324,6 +328,8 @@ module.exports = function (privileges) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
privileges.categories.canMoveAllTopics = function (currentCid, targetCid, uid, callback) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
isAdministrator: function (next) {
|
|
|
|
|
user.isAdministrator(uid, next);
|
|
|
|
@ -334,13 +340,12 @@ module.exports = function (privileges) {
|
|
|
|
|
moderatorOfTarget: function (next) {
|
|
|
|
|
user.isModerator(uid, targetCid, next);
|
|
|
|
|
},
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(null, results.isAdministrator || (results.moderatorOfCurrent && results.moderatorOfTarget));
|
|
|
|
|
});
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
next(null, results.isAdministrator || (results.moderatorOfCurrent && results.moderatorOfTarget));
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
privileges.categories.userPrivileges = function (cid, uid, callback) {
|
|
|
|
|