Priv hook fix (#9775)

* fix: #9773, fire hooks properly for priv changes

* fix: admin/global group privs

dont allow invalid privs
isekai-main
Barış Soner Uşaklı 3 years ago committed by GitHub
parent 4ac701d747
commit 1f91a31327
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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,

@ -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',

@ -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({

Loading…
Cancel
Save