mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 08:55:47 +01:00
fix: replace logic in isPrivilegedOrSelfAndPasswordMatch to use privileges.users.canEdit
This commit is contained in:
@@ -227,14 +227,9 @@ usersAPI.unban = async function (caller, data) {
|
|||||||
async function isPrivilegedOrSelfAndPasswordMatch(caller, data) {
|
async function isPrivilegedOrSelfAndPasswordMatch(caller, data) {
|
||||||
const { uid } = caller;
|
const { uid } = caller;
|
||||||
const isSelf = parseInt(uid, 10) === parseInt(data.uid, 10);
|
const isSelf = parseInt(uid, 10) === parseInt(data.uid, 10);
|
||||||
|
const canEdit = await privileges.users.canEdit(uid, data.uid);
|
||||||
|
|
||||||
const [isAdmin, isTargetAdmin, isGlobalMod] = await Promise.all([
|
if (!canEdit) {
|
||||||
user.isAdministrator(uid),
|
|
||||||
user.isAdministrator(data.uid),
|
|
||||||
user.isGlobalModerator(uid),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ((isTargetAdmin && !isAdmin) || (!isSelf && !(isAdmin || isGlobalMod))) {
|
|
||||||
throw new Error('[[error:no-privileges]]');
|
throw new Error('[[error:no-privileges]]');
|
||||||
}
|
}
|
||||||
const [hasPassword, passwordMatch] = await Promise.all([
|
const [hasPassword, passwordMatch] = await Promise.all([
|
||||||
|
|||||||
Reference in New Issue
Block a user