Allow roles from globalmanage to be fetched as json

indiachan-spamvector
Thomas Lynch 2 years ago
parent b0db6553a7
commit bc53bc1e4a
  1. 2
      controllers/pages.js
  2. 10
      models/pages/globalmanage/roles.js

@ -102,7 +102,7 @@ router.get('/globalmanage/news.html', useSession, sessionRefresh, isLoggedIn, ca
hasPerms.one(Permissions.MANAGE_GLOBAL_NEWS), csrf, globalManageNews);
router.get('/globalmanage/accounts.html', useSession, sessionRefresh, isLoggedIn, calcPerms,
hasPerms.one(Permissions.MANAGE_GLOBAL_ACCOUNTS), csrf, globalManageAccounts);
router.get('/globalmanage/roles.html', useSession, sessionRefresh, isLoggedIn, calcPerms,
router.get('/globalmanage/roles.(html|json)', useSession, sessionRefresh, isLoggedIn, calcPerms,
hasPerms.one(Permissions.MANAGE_GLOBAL_ROLES), csrf, globalManageRoles);
router.get('/globalmanage/settings.html', useSession, sessionRefresh, isLoggedIn, calcPerms,
hasPerms.one(Permissions.MANAGE_GLOBAL_SETTINGS), csrf, globalManageSettings);

@ -7,13 +7,17 @@ module.exports = async (req, res) => {
const allRoles = await Roles.find();
res
.set('Cache-Control', 'private, max-age=5')
.render('globalmanageroles', {
res.set('Cache-Control', 'private, max-age=5');
if (req.path.endsWith('.json')) {
res.json(allRoles);
} else {
res.render('globalmanageroles', {
csrf: req.csrfToken(),
permissions: res.locals.permissions,
allRoles,
roleNameMap: roleManager.roleNameMap,
});
}
};

Loading…
Cancel
Save