mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
const categories = require('../../categories');
|
|
const privileges = require('../../privileges');
|
|
const utils = require('../../utils');
|
|
|
|
const privilegesController = module.exports;
|
|
|
|
privilegesController.get = async function (req, res) {
|
|
const cid = req.params.cid ? parseInt(req.params.cid, 10) || 0 : 0;
|
|
const isAdminPriv = req.params.cid === 'admin';
|
|
|
|
let privilegesData;
|
|
if (cid === 0) {
|
|
privilegesData = await (isAdminPriv ? privileges.admin.list(req.uid) : privileges.global.list());
|
|
} else if (utils.isNumber(cid)) {
|
|
privilegesData = await privileges.categories.list(cid);
|
|
}
|
|
|
|
const categoriesData = [{
|
|
cid: 0,
|
|
name: '[[admin/manage/privileges:global]]',
|
|
icon: 'fa-list',
|
|
}, {
|
|
cid: 'admin',
|
|
name: '[[admin/manage/privileges:admin]]',
|
|
icon: 'fa-lock',
|
|
}, {
|
|
cid: -1,
|
|
name: '[[activitypub:category.name]]',
|
|
icon: 'fa-globe',
|
|
bgColor: '#0000ff',
|
|
color: '#ffffff',
|
|
}];
|
|
|
|
let selectedCategory;
|
|
categoriesData.forEach((category) => {
|
|
if (category) {
|
|
category.selected = category.cid === (!isAdminPriv ? cid : 'admin');
|
|
|
|
if (category.selected) {
|
|
selectedCategory = category;
|
|
}
|
|
}
|
|
});
|
|
if (!selectedCategory) {
|
|
selectedCategory = await categories.getCategoryFields(cid, ['cid', 'name', 'icon', 'bgColor', 'color']);
|
|
}
|
|
|
|
const group = req.query.group ? req.query.group : '';
|
|
res.render('admin/manage/privileges', {
|
|
privileges: privilegesData,
|
|
categories: categoriesData,
|
|
selectedCategory,
|
|
cid,
|
|
group,
|
|
isAdminPriv,
|
|
});
|
|
};
|