feat: #7743, privileges
parent
627ecaf6bb
commit
faccb191ec
@ -1,232 +1,164 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var _ = require('lodash');
|
||||
const _ = require('lodash');
|
||||
|
||||
var categories = require('../categories');
|
||||
var user = require('../user');
|
||||
var groups = require('../groups');
|
||||
var helpers = require('./helpers');
|
||||
var plugins = require('../plugins');
|
||||
const categories = require('../categories');
|
||||
const user = require('../user');
|
||||
const groups = require('../groups');
|
||||
const helpers = require('./helpers');
|
||||
const plugins = require('../plugins');
|
||||
const utils = require('../utils');
|
||||
|
||||
module.exports = function (privileges) {
|
||||
privileges.categories = {};
|
||||
|
||||
privileges.categories.list = function (cid, callback) {
|
||||
// Method used in admin/category controller to show all users/groups with privs in that given cid
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
labels: function (next) {
|
||||
async.parallel({
|
||||
users: async.apply(plugins.fireHook, 'filter:privileges.list_human', privileges.privilegeLabels.slice()),
|
||||
groups: async.apply(plugins.fireHook, 'filter:privileges.groups.list_human', privileges.privilegeLabels.slice()),
|
||||
}, next);
|
||||
},
|
||||
users: function (next) {
|
||||
helpers.getUserPrivileges(cid, 'filter:privileges.list', privileges.userPrivilegeList, next);
|
||||
},
|
||||
groups: function (next) {
|
||||
helpers.getGroupPrivileges(cid, 'filter:privileges.groups.list', privileges.groupPrivilegeList, next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (payload, next) {
|
||||
privileges.categories.list = async function (cid) {
|
||||
async function getLabels() {
|
||||
return await utils.promiseParallel({
|
||||
users: plugins.fireHook('filter:privileges.list_human', privileges.privilegeLabels.slice()),
|
||||
groups: plugins.fireHook('filter:privileges.groups.list_human', privileges.privilegeLabels.slice()),
|
||||
});
|
||||
}
|
||||
|
||||
const payload = await utils.promiseParallel({
|
||||
labels: getLabels(),
|
||||
users: helpers.getUserPrivileges(cid, 'filter:privileges.list', privileges.userPrivilegeList),
|
||||
groups: helpers.getGroupPrivileges(cid, 'filter:privileges.groups.list', privileges.groupPrivilegeList),
|
||||
});
|
||||
|
||||
// This is a hack because I can't do {labels.users.length} to echo the count in templates.js
|
||||
payload.columnCountUser = payload.labels.users.length + 2;
|
||||
payload.columnCountUserOther = payload.labels.users.length - privileges.privilegeLabels.length;
|
||||
payload.columnCountGroup = payload.labels.groups.length + 2;
|
||||
payload.columnCountGroupOther = payload.labels.groups.length - privileges.privilegeLabels.length;
|
||||
next(null, payload);
|
||||
},
|
||||
], callback);
|
||||
return payload;
|
||||
};
|
||||
|
||||
privileges.categories.get = function (cid, uid, callback) {
|
||||
var privs = ['topics:create', 'topics:read', 'topics:tag', 'read'];
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
privileges: function (next) {
|
||||
helpers.isUserAllowedTo(privs, uid, cid, next);
|
||||
},
|
||||
isAdministrator: function (next) {
|
||||
user.isAdministrator(uid, next);
|
||||
},
|
||||
isModerator: function (next) {
|
||||
user.isModerator(uid, cid, next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
var privData = _.zipObject(privs, results.privileges);
|
||||
var isAdminOrMod = results.isAdministrator || results.isModerator;
|
||||
|
||||
plugins.fireHook('filter:privileges.categories.get', {
|
||||
'topics:create': privData['topics:create'] || results.isAdministrator,
|
||||
'topics:read': privData['topics:read'] || results.isAdministrator,
|
||||
'topics:tag': privData['topics:tag'] || results.isAdministrator,
|
||||
read: privData.read || results.isAdministrator,
|
||||
privileges.categories.get = async function (cid, uid) {
|
||||
const privs = ['topics:create', 'topics:read', 'topics:tag', 'read'];
|
||||
|
||||
const [userPrivileges, isAdministrator, isModerator] = await Promise.all([
|
||||
helpers.isUserAllowedTo(privs, uid, cid),
|
||||
user.isAdministrator(uid),
|
||||
user.isModerator(uid, cid),
|
||||
]);
|
||||
|
||||
const privData = _.zipObject(privs, userPrivileges);
|
||||
const isAdminOrMod = isAdministrator || isModerator;
|
||||
|
||||
return await plugins.fireHook('filter:privileges.categories.get', {
|
||||
'topics:create': privData['topics:create'] || isAdministrator,
|
||||
'topics:read': privData['topics:read'] || isAdministrator,
|
||||
'topics:tag': privData['topics:tag'] || isAdministrator,
|
||||
read: privData.read || isAdministrator,
|
||||
cid: cid,
|
||||
uid: uid,
|
||||
editable: isAdminOrMod,
|
||||
view_deleted: isAdminOrMod,
|
||||
isAdminOrMod: isAdminOrMod,
|
||||
}, next);
|
||||
},
|
||||
], callback);
|
||||
});
|
||||
};
|
||||
|
||||
privileges.categories.isAdminOrMod = function (cid, uid, callback) {
|
||||
privileges.categories.isAdminOrMod = async function (cid, uid) {
|
||||
if (parseInt(uid, 10) <= 0) {
|
||||
return setImmediate(callback, null, false);
|
||||
return false;
|
||||
}
|
||||
helpers.some([
|
||||
function (next) {
|
||||
user.isModerator(uid, cid, next);
|
||||
},
|
||||
function (next) {
|
||||
user.isAdministrator(uid, next);
|
||||
},
|
||||
], callback);
|
||||
const [isAdmin, isMod] = await Promise.all([
|
||||
user.isAdministrator(uid),
|
||||
user.isModerator(uid, cid),
|
||||
]);
|
||||
return isAdmin || isMod;
|
||||
};
|
||||
|
||||
privileges.categories.isUserAllowedTo = function (privilege, cid, uid, callback) {
|
||||
privileges.categories.isUserAllowedTo = async function (privilege, cid, uid) {
|
||||
if (!cid) {
|
||||
return setImmediate(callback, null, false);
|
||||
return false;
|
||||
}
|
||||
if (Array.isArray(cid)) {
|
||||
helpers.isUserAllowedTo(privilege, uid, cid, function (err, results) {
|
||||
callback(err, Array.isArray(results) && results.length ? results : false);
|
||||
});
|
||||
} else {
|
||||
helpers.isUserAllowedTo(privilege, uid, [cid], function (err, results) {
|
||||
callback(err, Array.isArray(results) && results.length ? results[0] : false);
|
||||
});
|
||||
const results = await helpers.isUserAllowedTo(privilege, uid, Array.isArray(cid) ? cid : [cid]);
|
||||
|
||||
if (Array.isArray(results) && results.length) {
|
||||
return Array.isArray(cid) ? results : results[0];
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
privileges.categories.can = function (privilege, cid, uid, callback) {
|
||||
privileges.categories.can = async function (privilege, cid, uid) {
|
||||
if (!cid) {
|
||||
return setImmediate(callback, null, false);
|
||||
return false;
|
||||
}
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
disabled: async.apply(categories.getCategoryField, cid, 'disabled'),
|
||||
isAdmin: async.apply(user.isAdministrator, uid),
|
||||
isAllowed: async.apply(privileges.categories.isUserAllowedTo, privilege, cid, uid),
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
next(null, !results.disabled && (results.isAllowed || results.isAdmin));
|
||||
},
|
||||
], callback);
|
||||
const [disabled, isAdmin, isAllowed] = await Promise.all([
|
||||
categories.getCategoryField(cid, 'disabled'),
|
||||
user.isAdministrator(uid),
|
||||
privileges.categories.isUserAllowedTo(privilege, cid, uid),
|
||||
]);
|
||||
return !disabled && (isAllowed || isAdmin);
|
||||
};
|
||||
|
||||
privileges.categories.filterCids = function (privilege, cids, uid, callback) {
|
||||
privileges.categories.filterCids = async function (privilege, cids, uid) {
|
||||
if (!Array.isArray(cids) || !cids.length) {
|
||||
return callback(null, []);
|
||||
return [];
|
||||
}
|
||||
|
||||
cids = _.uniq(cids);
|
||||
|
||||
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);
|
||||
const results = await privileges.categories.getBase(privilege, cids, uid);
|
||||
return cids.filter(function (cid, index) {
|
||||
return !!cid && !results.categories[index].disabled && (results.allowedTo[index] || results.isAdmin);
|
||||
});
|
||||
|
||||
next(null, cids.filter(Boolean));
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
privileges.categories.getBase = function (privilege, cids, uid, callback) {
|
||||
async.parallel({
|
||||
categories: function (next) {
|
||||
categories.getCategoriesFields(cids, ['disabled'], next);
|
||||
},
|
||||
allowedTo: function (next) {
|
||||
helpers.isUserAllowedTo(privilege, uid, cids, next);
|
||||
},
|
||||
isAdmin: function (next) {
|
||||
user.isAdministrator(uid, next);
|
||||
},
|
||||
}, callback);
|
||||
privileges.categories.getBase = async function (privilege, cids, uid) {
|
||||
return await utils.promiseParallel({
|
||||
categories: categories.getCategoriesFields(cids, ['disabled']),
|
||||
allowedTo: helpers.isUserAllowedTo(privilege, uid, cids),
|
||||
isAdmin: user.isAdministrator(uid),
|
||||
});
|
||||
};
|
||||
|
||||
privileges.categories.filterUids = function (privilege, cid, uids, callback) {
|
||||
privileges.categories.filterUids = async function (privilege, cid, uids) {
|
||||
if (!uids.length) {
|
||||
return setImmediate(callback, null, []);
|
||||
return [];
|
||||
}
|
||||
|
||||
uids = _.uniq(uids);
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
allowedTo: function (next) {
|
||||
helpers.isUsersAllowedTo(privilege, uids, cid, next);
|
||||
},
|
||||
isAdmins: function (next) {
|
||||
user.isAdministrator(uids, next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
uids = uids.filter(function (uid, index) {
|
||||
return results.allowedTo[index] || results.isAdmins[index];
|
||||
});
|
||||
next(null, uids);
|
||||
},
|
||||
], callback);
|
||||
const [allowedTo, isAdmins] = await Promise.all([
|
||||
helpers.isUsersAllowedTo(privilege, uids, cid),
|
||||
user.isAdministrator(uids),
|
||||
]);
|
||||
return uids.filter((uid, index) => allowedTo[index] || isAdmins[index]);
|
||||
};
|
||||
|
||||
privileges.categories.give = function (privileges, cid, groupName, callback) {
|
||||
helpers.giveOrRescind(groups.join, privileges, cid, groupName, callback);
|
||||
privileges.categories.give = async function (privileges, cid, groupName) {
|
||||
await helpers.giveOrRescind(groups.join, privileges, cid, groupName);
|
||||
};
|
||||
|
||||
privileges.categories.rescind = function (privileges, cid, groupName, callback) {
|
||||
helpers.giveOrRescind(groups.leave, privileges, cid, groupName, callback);
|
||||
privileges.categories.rescind = async function (privileges, cid, groupName) {
|
||||
await helpers.giveOrRescind(groups.leave, privileges, cid, groupName);
|
||||
};
|
||||
|
||||
privileges.categories.canMoveAllTopics = function (currentCid, targetCid, uid, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
isAdmin: async.apply(user.isAdministrator, uid),
|
||||
isModerators: async.apply(user.isModerator, uid, [currentCid, targetCid]),
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
next(null, results.isAdmin || !results.isModerators.includes(false));
|
||||
},
|
||||
], callback);
|
||||
privileges.categories.canMoveAllTopics = async function (currentCid, targetCid, uid) {
|
||||
const [isAdmin, isModerators] = await Promise.all([
|
||||
user.isAdministrator(uid),
|
||||
user.isModerator(uid, [currentCid, targetCid]),
|
||||
]);
|
||||
return isAdmin || !isModerators.includes(false);
|
||||
};
|
||||
|
||||
privileges.categories.userPrivileges = function (cid, uid, callback) {
|
||||
var tasks = {};
|
||||
|
||||
privileges.categories.userPrivileges = async function (cid, uid) {
|
||||
const tasks = {};
|
||||
privileges.userPrivilegeList.forEach(function (privilege) {
|
||||
tasks[privilege] = async.apply(groups.isMember, uid, 'cid:' + cid + ':privileges:' + privilege);
|
||||
tasks[privilege] = groups.isMember(uid, 'cid:' + cid + ':privileges:' + privilege);
|
||||
});
|
||||
|
||||
async.parallel(tasks, callback);
|
||||
return await utils.promiseParallel(tasks);
|
||||
};
|
||||
|
||||
privileges.categories.groupPrivileges = function (cid, groupName, callback) {
|
||||
var tasks = {};
|
||||
|
||||
privileges.categories.groupPrivileges = async function (cid, groupName) {
|
||||
const tasks = {};
|
||||
privileges.groupPrivilegeList.forEach(function (privilege) {
|
||||
tasks[privilege] = async.apply(groups.isMember, groupName, 'cid:' + cid + ':privileges:' + privilege);
|
||||
tasks[privilege] = groups.isMember(groupName, 'cid:' + cid + ':privileges:' + privilege);
|
||||
});
|
||||
|
||||
async.parallel(tasks, callback);
|
||||
return await utils.promiseParallel(tasks);
|
||||
};
|
||||
};
|
||||
|
@ -1,189 +1,118 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var _ = require('lodash');
|
||||
const _ = require('lodash');
|
||||
|
||||
var groups = require('../groups');
|
||||
var plugins = require('../plugins');
|
||||
var helpers = require('./helpers');
|
||||
const groups = require('../groups');
|
||||
const plugins = require('../plugins');
|
||||
const helpers = require('./helpers');
|
||||
|
||||
module.exports = function (privileges) {
|
||||
privileges.users = {};
|
||||
|
||||
privileges.users.isAdministrator = function (uid, callback) {
|
||||
if (Array.isArray(uid)) {
|
||||
groups.isMembers(uid, 'administrators', callback);
|
||||
} else {
|
||||
groups.isMember(uid, 'administrators', callback);
|
||||
}
|
||||
privileges.users.isAdministrator = async function (uid) {
|
||||
return await isGroupMember(uid, 'administrators');
|
||||
};
|
||||
|
||||
privileges.users.isGlobalModerator = function (uid, callback) {
|
||||
if (Array.isArray(uid)) {
|
||||
groups.isMembers(uid, 'Global Moderators', callback);
|
||||
} else {
|
||||
groups.isMember(uid, 'Global Moderators', callback);
|
||||
}
|
||||
privileges.users.isGlobalModerator = async function (uid) {
|
||||
return await isGroupMember(uid, 'Global Moderators');
|
||||
};
|
||||
|
||||
privileges.users.isModerator = function (uid, cid, callback) {
|
||||
async function isGroupMember(uid, groupName) {
|
||||
return await groups[Array.isArray(uid) ? 'isMembers' : 'isMember'](uid, groupName);
|
||||
}
|
||||
|
||||
privileges.users.isModerator = async function (uid, cid) {
|
||||
if (Array.isArray(cid)) {
|
||||
isModeratorOfCategories(cid, uid, callback);
|
||||
return await isModeratorOfCategories(cid, uid);
|
||||
} else if (Array.isArray(uid)) {
|
||||
isModeratorsOfCategory(cid, uid, callback);
|
||||
} else {
|
||||
isModeratorOfCategory(cid, uid, callback);
|
||||
return await isModeratorsOfCategory(cid, uid);
|
||||
}
|
||||
return await isModeratorOfCategory(cid, uid);
|
||||
};
|
||||
|
||||
function isModeratorOfCategories(cids, uid, callback) {
|
||||
async function isModeratorOfCategories(cids, uid) {
|
||||
if (parseInt(uid, 10) <= 0) {
|
||||
return filterIsModerator(cids, uid, cids.map(() => false), callback);
|
||||
return await filterIsModerator(cids, uid, cids.map(() => false));
|
||||
}
|
||||
var uniqueCids;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
privileges.users.isGlobalModerator(uid, next);
|
||||
},
|
||||
function (isGlobalModerator, next) {
|
||||
|
||||
const isGlobalModerator = await privileges.users.isGlobalModerator(uid);
|
||||
if (isGlobalModerator) {
|
||||
return filterIsModerator(cids, uid, cids.map(() => true), callback);
|
||||
return await filterIsModerator(cids, uid, cids.map(() => true));
|
||||
}
|
||||
const uniqueCids = _.uniq(cids);
|
||||
const isAllowed = await helpers.isUserAllowedTo('moderate', uid, uniqueCids);
|
||||
|
||||
uniqueCids = _.uniq(cids);
|
||||
|
||||
helpers.isUserAllowedTo('moderate', uid, uniqueCids, next);
|
||||
},
|
||||
function (isAllowed, next) {
|
||||
const map = _.zipObject(uniqueCids, isAllowed);
|
||||
const isModerator = cids.map(cid => map[cid]);
|
||||
filterIsModerator(cids, uid, isModerator, next);
|
||||
},
|
||||
], callback);
|
||||
const cidToIsAllowed = _.zipObject(uniqueCids, isAllowed);
|
||||
const isModerator = cids.map(cid => cidToIsAllowed[cid]);
|
||||
return await filterIsModerator(cids, uid, isModerator);
|
||||
}
|
||||
|
||||
function isModeratorsOfCategory(cid, uids, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel([
|
||||
async.apply(privileges.users.isGlobalModerator, uids),
|
||||
async.apply(groups.isMembers, uids, 'cid:' + cid + ':privileges:moderate'),
|
||||
async.apply(groups.isMembersOfGroupList, uids, 'cid:' + cid + ':privileges:groups:moderate'),
|
||||
], next);
|
||||
},
|
||||
function (checks, next) {
|
||||
var isModerator = checks[0].map(function (isMember, idx) {
|
||||
return isMember || checks[1][idx] || checks[2][idx];
|
||||
});
|
||||
|
||||
filterIsModerator(cid, uids, isModerator, next);
|
||||
},
|
||||
], callback);
|
||||
async function isModeratorsOfCategory(cid, uids) {
|
||||
const [check1, check2, check3] = await Promise.all([
|
||||
privileges.users.isGlobalModerator(uids),
|
||||
groups.isMembers(uids, 'cid:' + cid + ':privileges:moderate'),
|
||||
groups.isMembersOfGroupList(uids, 'cid:' + cid + ':privileges:groups:moderate'),
|
||||
]);
|
||||
const isModerator = uids.map((uid, idx) => check1[idx] || check2[idx] || check3[idx]);
|
||||
return await filterIsModerator(cid, uids, isModerator);
|
||||
}
|
||||
|
||||
function isModeratorOfCategory(cid, uid, callback) {
|
||||
if (parseInt(uid, 10) <= 0) {
|
||||
return filterIsModerator(cid, uid, false, callback);
|
||||
}
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel([
|
||||
async.apply(privileges.users.isGlobalModerator, uid),
|
||||
async.apply(groups.isMember, uid, 'cid:' + cid + ':privileges:moderate'),
|
||||
async.apply(groups.isMemberOfGroupList, uid, 'cid:' + cid + ':privileges:groups:moderate'),
|
||||
], next);
|
||||
},
|
||||
function (checks, next) {
|
||||
var isModerator = checks[0] || checks[1] || checks[2];
|
||||
filterIsModerator(cid, uid, isModerator, next);
|
||||
},
|
||||
], callback);
|
||||
async function isModeratorOfCategory(cid, uid) {
|
||||
const result = await isModeratorOfCategories([cid], uid);
|
||||
return result ? result[0] : false;
|
||||
}
|
||||
|
||||
function filterIsModerator(cid, uid, isModerator, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
plugins.fireHook('filter:user.isModerator', { uid: uid, cid: cid, isModerator: isModerator }, next);
|
||||
},
|
||||
function (data, next) {
|
||||
async function filterIsModerator(cid, uid, isModerator) {
|
||||
const data = await plugins.fireHook('filter:user.isModerator', { uid: uid, cid: cid, isModerator: isModerator });
|
||||
if ((Array.isArray(uid) || Array.isArray(cid)) && !Array.isArray(data.isModerator)) {
|
||||
return callback(new Error('filter:user.isModerator - i/o mismatch'));
|
||||
throw new Error('filter:user.isModerator - i/o mismatch');
|
||||
}
|
||||
|
||||
next(null, data.isModerator);
|
||||
},
|
||||
], callback);
|
||||
return data.isModerator;
|
||||
}
|
||||
|
||||
privileges.users.canEdit = function (callerUid, uid, callback) {
|
||||
privileges.users.canEdit = async function (callerUid, uid) {
|
||||
if (parseInt(callerUid, 10) === parseInt(uid, 10)) {
|
||||
return process.nextTick(callback, null, true);
|
||||
return true;
|
||||
}
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
isAdmin: function (next) {
|
||||
privileges.users.isAdministrator(callerUid, next);
|
||||
},
|
||||
isGlobalMod: function (next) {
|
||||
privileges.users.isGlobalModerator(callerUid, next);
|
||||
},
|
||||
isTargetAdmin: function (next) {
|
||||
privileges.users.isAdministrator(uid, next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
results.canEdit = results.isAdmin || (results.isGlobalMod && !results.isTargetAdmin);
|
||||
results.callerUid = callerUid;
|
||||
results.uid = uid;
|
||||
plugins.fireHook('filter:user.canEdit', results, next);
|
||||
},
|
||||
function (data, next) {
|
||||
next(null, data.canEdit);
|
||||
},
|
||||
], callback);
|
||||
const [isAdmin, isGlobalMod, isTargetAdmin] = await Promise.all([
|
||||
privileges.users.isAdministrator(callerUid),
|
||||
privileges.users.isGlobalModerator(callerUid),
|
||||
privileges.users.isAdministrator(uid),
|
||||
]);
|
||||
|
||||
const data = await plugins.fireHook('filter:user.canEdit', {
|
||||
isAdmin: isAdmin,
|
||||
isGlobalMod: isGlobalMod,
|
||||
isTargetAdmin: isTargetAdmin,
|
||||
canEdit: isAdmin || (isGlobalMod && !isTargetAdmin),
|
||||
callerUid: callerUid,
|
||||
uid: uid,
|
||||
});
|
||||
return data.canEdit;
|
||||
};
|
||||
|
||||
privileges.users.canBanUser = function (callerUid, uid, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
canBan: function (next) {
|
||||
privileges.global.can('ban', callerUid, next);
|
||||
},
|
||||
isTargetAdmin: function (next) {
|
||||
privileges.users.isAdministrator(uid, next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
results.canBan = !results.isTargetAdmin && results.canBan;
|
||||
results.callerUid = callerUid;
|
||||
results.uid = uid;
|
||||
plugins.fireHook('filter:user.canBanUser', results, next);
|
||||
},
|
||||
function (data, next) {
|
||||
next(null, data.canBan);
|
||||
},
|
||||
], callback);
|
||||
privileges.users.canBanUser = async function (callerUid, uid) {
|
||||
const [canBan, isTargetAdmin] = await Promise.all([
|
||||
privileges.global.can('ban', callerUid),
|
||||
privileges.users.isAdministrator(uid),
|
||||
]);
|
||||
|
||||
const data = await plugins.fireHook('filter:user.canBanUser', {
|
||||
canBan: canBan && !isTargetAdmin,
|
||||
callerUid: callerUid,
|
||||
uid: uid,
|
||||
});
|
||||
return data.canBan;
|
||||
};
|
||||
|
||||
privileges.users.hasBanPrivilege = function (uid, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
privileges.global.can('ban', uid, next);
|
||||
},
|
||||
function (canBan, next) {
|
||||
plugins.fireHook('filter:user.hasBanPrivilege', {
|
||||
privileges.users.hasBanPrivilege = async function (uid) {
|
||||
const canBan = await privileges.global.can('ban', uid);
|
||||
const data = await plugins.fireHook('filter:user.hasBanPrivilege', {
|
||||
uid: uid,
|
||||
canBan: canBan,
|
||||
}, next);
|
||||
},
|
||||
function (data, next) {
|
||||
next(null, data.canBan);
|
||||
},
|
||||
], callback);
|
||||
});
|
||||
return data.canBan;
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue