mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	feat: #8493, plugin helper for standardised link/button injection
This commit is contained in:
		| @@ -1,5 +1,6 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| const winston = require('winston'); | ||||
| const nconf = require('nconf'); | ||||
| const validator = require('validator'); | ||||
| const querystring = require('querystring'); | ||||
| @@ -218,6 +219,34 @@ helpers.buildTitle = function (pageTitle) { | ||||
| 	return title; | ||||
| }; | ||||
|  | ||||
| helpers.buildLinks = async function (event, links, states) { | ||||
| 	const filtered = await plugins.fireHook(`filter:buildLinks.${event}`, { links, states }); | ||||
|  | ||||
| 	return filtered.links.filter(function (link, index) { | ||||
| 		// "public" is the old property, if visibility is defined, discard `public` | ||||
| 		if (link.hasOwnProperty('public') && !link.hasOwnProperty('visibility')) { | ||||
| 			winston.warn('[account/profileMenu (' + link.id + ')] Use of the `.public` property is deprecated, use `visibility` now'); | ||||
| 			return link && (link.public || filtered.states.self); | ||||
| 		} | ||||
|  | ||||
| 		// Default visibility | ||||
| 		link.visibility = { self: true, | ||||
| 			other: true, | ||||
| 			moderator: true, | ||||
| 			globalMod: true, | ||||
| 			admin: true, | ||||
| 			canViewInfo: true, | ||||
| 			...link.visibility }; | ||||
|  | ||||
| 		var permit = Object.keys(filtered.states).some(function (state) { | ||||
| 			return filtered.states[state] && link.visibility[state]; | ||||
| 		}); | ||||
|  | ||||
| 		filtered.links[index].public = permit; | ||||
| 		return permit; | ||||
| 	}); | ||||
| }; | ||||
|  | ||||
| helpers.getCategories = async function (set, uid, privilege, selectedCid) { | ||||
| 	const cids = await categories.getCidsByPrivilege(set, uid, privilege); | ||||
| 	return await getCategoryData(cids, uid, selectedCid); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user