From 6869920e06e0f92b3a1a662be400f79d377d331d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 3 Sep 2021 11:22:42 -0400 Subject: [PATCH] fix: #9773, fire hooks properly for priv changes (#9774) --- src/api/categories.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/api/categories.js b/src/api/categories.js index 3486df1ad5..f2b3a830b6 100644 --- a/src/api/categories.js +++ b/src/api/categories.js @@ -65,10 +65,20 @@ categoriesAPI.setPrivilege = async (caller, data) => { if (!userExists && !groupExists) { throw new Error('[[error:no-user-or-group]]'); } - - await privileges.categories[data.set ? 'give' : 'rescind']( - Array.isArray(data.privilege) ? data.privilege : [data.privilege], data.cid, data.member - ); + const privs = Array.isArray(data.privilege) ? data.privilege : [data.privilege]; + const type = data.set ? 'give' : 'rescind'; + if (!privs.length) { + throw new Error('[[error:invalid-data]]'); + } + let privMethod = privileges.categories[type]; + if (parseInt(data.cid, 10) === 0) { + if (privs[0].startsWith('admin:')) { + privMethod = privileges.admin[type]; + } else { + privMethod = privileges.global[type]; + } + } + await privMethod(privs, data.cid, data.member); await events.log({ uid: caller.uid,