diff --git a/src/api/categories.js b/src/api/categories.js index f2b3a830b6..118dd0a258 100644 --- a/src/api/categories.js +++ b/src/api/categories.js @@ -70,15 +70,19 @@ categoriesAPI.setPrivilege = async (caller, data) => { 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]; + const adminPrivs = privs.filter(priv => privileges.admin.privilegeList.includes(priv)); + const globalPrivs = privs.filter(priv => privileges.global.privilegeList.includes(priv)); + if (adminPrivs.length) { + await privileges.admin[type](adminPrivs, data.member); } + if (globalPrivs.length) { + await privileges.global[type](globalPrivs, data.member); + } + } else { + const categoryPrivs = privs.filter(priv => privileges.categories.privilegeList.includes(priv)); + await privileges.categories[type](categoryPrivs, data.cid, data.member); } - await privMethod(privs, data.cid, data.member); await events.log({ uid: caller.uid, diff --git a/src/privileges/admin.js b/src/privileges/admin.js index ead7f6fc5e..d98e2c2bca 100644 --- a/src/privileges/admin.js +++ b/src/privileges/admin.js @@ -35,6 +35,8 @@ privsAdmin.userPrivilegeList = [ privsAdmin.groupPrivilegeList = privsAdmin.userPrivilegeList.map(privilege => `groups:${privilege}`); +privsAdmin.privilegeList = privsAdmin.userPrivilegeList.concat(privsAdmin.groupPrivilegeList); + // Mapping for a page route (via direct match or regexp) to a privilege privsAdmin.routeMap = { dashboard: 'admin:dashboard', diff --git a/src/privileges/global.js b/src/privileges/global.js index 563ae3d053..206e7769c3 100644 --- a/src/privileges/global.js +++ b/src/privileges/global.js @@ -49,6 +49,8 @@ privsGlobal.userPrivilegeList = [ privsGlobal.groupPrivilegeList = privsGlobal.userPrivilegeList.map(privilege => `groups:${privilege}`); +privsGlobal.privilegeList = privsGlobal.userPrivilegeList.concat(privsGlobal.groupPrivilegeList); + privsGlobal.list = async function () { async function getLabels() { return await utils.promiseParallel({