Skip to content

Node.js based forum software built for the modern web

fix: replace logic in isPrivilegedOrSelfAndPasswordMatch to use privileges.users.canEdit

Julian Lam856ba78a5f0c
diff --git a/src/api/users.js b/src/api/users.js
index 71d3a0c8f4..cbd64e7fd5 100644
--- a/src/api/users.js
+++ b/src/api/users.js
@@ -227,14 +227,9 @@ usersAPI.unban = async function (caller, data) {
async function isPrivilegedOrSelfAndPasswordMatch(caller, data) {
const { uid } = caller;
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([
- user.isAdministrator(uid),
- user.isAdministrator(data.uid),
- user.isGlobalModerator(uid),
- ]);
-
- if ((isTargetAdmin && !isAdmin) || (!isSelf && !(isAdmin || isGlobalMod))) {
+ if (!canEdit) {
throw new Error('[[error:no-privileges]]');
}
const [hasPassword, passwordMatch] = await Promise.all([