mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-30 18:46:01 +01:00 
			
		
		
		
	refactor: remove usage of middlewares
Specifically, middleware.isAdmin|exposePrivilegeSet|exposePrivileges
This commit is contained in:
		| @@ -1,5 +1,6 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| const privileges = require('../../privileges'); | ||||
| const categories = require('../../categories'); | ||||
| const api = require('../../api'); | ||||
|  | ||||
| @@ -7,12 +8,23 @@ const helpers = require('../helpers'); | ||||
|  | ||||
| const Categories = module.exports; | ||||
|  | ||||
| const hasAdminPrivilege = async (uid) => { | ||||
| 	const ok = await privileges.admin.can(`admin:categories`, uid); | ||||
| 	if (!ok) { | ||||
| 		throw new Error('[[error:no-privileges]]'); | ||||
| 	} | ||||
| }; | ||||
|  | ||||
| Categories.create = async (req, res) => { | ||||
| 	await hasAdminPrivilege(req.uid); | ||||
|  | ||||
| 	const response = await api.categories.create(req, req.body); | ||||
| 	helpers.formatApiResponse(200, res, response); | ||||
| }; | ||||
|  | ||||
| Categories.update = async (req, res) => { | ||||
| 	await hasAdminPrivilege(req.uid); | ||||
|  | ||||
| 	const payload = {}; | ||||
| 	payload[req.params.cid] = req.body; | ||||
| 	await api.categories.update(req, payload); | ||||
| @@ -21,6 +33,8 @@ Categories.update = async (req, res) => { | ||||
| }; | ||||
|  | ||||
| Categories.delete = async (req, res) => { | ||||
| 	await hasAdminPrivilege(req.uid); | ||||
|  | ||||
| 	await api.categories.delete(req, { cid: req.params.cid }); | ||||
| 	helpers.formatApiResponse(200, res); | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user