mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: internal helper method hasGlobalPrivilege, DRY
This commit is contained in:
@@ -243,9 +243,10 @@ async function render(req, res, data) {
|
|||||||
data['filterBy_' + validator.escape(String(filter))] = true;
|
data['filterBy_' + validator.escape(String(filter))] = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
data.showInviteButton = await privileges.users.hasInvitePrivilege(req.uid);
|
|
||||||
if (data.adminInviteOnly) {
|
if (data.adminInviteOnly) {
|
||||||
data.showInviteButton = await privileges.users.isAdministrator(req.uid);
|
data.showInviteButton = await privileges.users.isAdministrator(req.uid);
|
||||||
|
} else {
|
||||||
|
data.showInviteButton = await privileges.users.hasInvitePrivilege(req.uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.render('admin/manage/users', data);
|
res.render('admin/manage/users', data);
|
||||||
|
|||||||
@@ -107,21 +107,14 @@ module.exports = function (privileges) {
|
|||||||
return data.canBan;
|
return data.canBan;
|
||||||
};
|
};
|
||||||
|
|
||||||
privileges.users.hasBanPrivilege = async function (uid) {
|
privileges.users.hasBanPrivilege = async uid => await hasGlobalPrivilege('ban', uid);
|
||||||
const canBan = await privileges.global.can('ban', uid);
|
privileges.users.hasInvitePrivilege = async uid => await hasGlobalPrivilege('invite', uid);
|
||||||
const data = await plugins.fireHook('filter:user.hasBanPrivilege', {
|
|
||||||
uid: uid,
|
|
||||||
canBan: canBan,
|
|
||||||
});
|
|
||||||
return data.canBan;
|
|
||||||
};
|
|
||||||
|
|
||||||
privileges.users.hasInvitePrivilege = async function (uid) {
|
async function hasGlobalPrivilege(privilege, uid) {
|
||||||
const canInvite = await privileges.global.can('invite', uid);
|
const privilegeName = privilege.split('-').map(word => word.slice(0, 1).toUpperCase() + word.slice(1)).join('');
|
||||||
const data = await plugins.fireHook('filter:user.hasInvitePrivilege', {
|
let payload = { uid };
|
||||||
uid: uid,
|
payload[`can${privilegeName}`] = await privileges.global.can(privilege, uid);
|
||||||
canInvite: canInvite,
|
payload = await plugins.fireHook(`filter:user.has${privilegeName}Privilege`, payload);
|
||||||
});
|
return payload[`can${privilegeName}`];
|
||||||
return data.canInvite;
|
}
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user