mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-30 18:46:01 +01:00 
			
		
		
		
	Priv hook fix (#9775)
* fix: #9773, fire hooks properly for priv changes * fix: admin/global group privs dont allow invalid privs
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							4ac701d747
						
					
				
				
					commit
					1f91a31327
				
			| @@ -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]; | ||||
| 		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 { | ||||
| 			privMethod = privileges.global[type]; | ||||
| 		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({ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user