From da191341e8c4b06e2c531e4cfa16f4d6715f169d Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 22 Dec 2020 15:07:37 -0500 Subject: [PATCH] feat(acp): added new admin privilege for groups management --- public/language/en-GB/admin/manage/privileges.json | 1 + src/controllers/admin.js | 2 ++ src/middleware/admin.js | 2 +- src/privileges/admin.js | 6 +++++- src/views/admin/partials/menu.tpl | 4 ++-- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/public/language/en-GB/admin/manage/privileges.json b/public/language/en-GB/admin/manage/privileges.json index d90fb7893d..92749720b0 100644 --- a/public/language/en-GB/admin/manage/privileges.json +++ b/public/language/en-GB/admin/manage/privileges.json @@ -39,6 +39,7 @@ "admin-categories": "Categories", "admin-privileges": "Privileges", "admin-users": "Users", + "admin-groups": "Groups", "admin-settings": "Settings", "alert.confirm-moderate": "Are you sure you wish to grant the moderation privilege to this user group? This group is public, and any users can join at will.", diff --git a/src/controllers/admin.js b/src/controllers/admin.js index b6412828a5..a9fcd83eb6 100644 --- a/src/controllers/admin.js +++ b/src/controllers/admin.js @@ -42,6 +42,8 @@ adminController.routeIndex = async (req, res) => { return helpers.redirect(res, 'admin/manage/privileges'); } else if (privilegeSet['admin:users']) { return helpers.redirect(res, 'admin/manage/users'); + } else if (privilegeSet['admin:groups']) { + return helpers.redirect(res, 'admin/manage/groups'); } else if (privilegeSet['admin:settings']) { return helpers.redirect(res, 'admin/settings/general'); } diff --git a/src/middleware/admin.js b/src/middleware/admin.js index c30f40765e..da97a67d18 100644 --- a/src/middleware/admin.js +++ b/src/middleware/admin.js @@ -73,7 +73,7 @@ middleware.renderHeader = async (req, res, data) => { version: version, latestVersion: results.latestVersion, upgradeAvailable: results.latestVersion && semver.gt(results.latestVersion, version), - showManageMenu: results.privileges.superadmin || ['categories', 'privileges', 'users', 'settings'].some(priv => results.privileges[`admin:${priv}`]), + showManageMenu: results.privileges.superadmin || ['categories', 'privileges', 'users', 'groups', 'settings'].some(priv => results.privileges[`admin:${priv}`]), }; templateValues.template = { name: res.locals.template }; diff --git a/src/privileges/admin.js b/src/privileges/admin.js index 31c0b3022d..dcf8f5ff28 100644 --- a/src/privileges/admin.js +++ b/src/privileges/admin.js @@ -17,6 +17,7 @@ module.exports = function (privileges) { { name: '[[admin/manage/privileges:admin-categories]]' }, { name: '[[admin/manage/privileges:admin-privileges]]' }, { name: '[[admin/manage/privileges:admin-users]]' }, + { name: '[[admin/manage/privileges:admin-groups]]' }, { name: '[[admin/manage/privileges:admin-settings]]' }, ]; @@ -25,6 +26,7 @@ module.exports = function (privileges) { 'admin:categories', 'admin:privileges', 'admin:users', + 'admin:groups', 'admin:settings', ]; @@ -36,6 +38,7 @@ module.exports = function (privileges) { 'manage/categories': 'admin:categories', 'manage/privileges': 'admin:privileges', 'manage/users': 'admin:users', + 'manage/groups': 'admin:groups', 'extend/plugins': 'admin:settings', 'extend/widgets': 'admin:settings', 'extend/rewards': 'admin:settings', @@ -43,6 +46,7 @@ module.exports = function (privileges) { privileges.admin.routeRegexpMap = { '^manage/categories/\\d+': 'admin:categories', '^manage/privileges/(\\d+|admin)': 'admin:privileges', + '^manage/groups/.+$': 'admin:groups', '^settings/[\\w\\-]+$': 'admin:settings', '^appearance/[\\w]+$': 'admin:settings', '^plugins/[\\w\\-]+$': 'admin:settings', @@ -138,7 +142,7 @@ module.exports = function (privileges) { payload.keys = keys; // This is a hack because I can't do {labels.users.length} to echo the count in templates.js - payload.columnCount = payload.labels.users.length + 2; + payload.columnCount = payload.labels.users.length + 3; return payload; }; diff --git a/src/views/admin/partials/menu.tpl b/src/views/admin/partials/menu.tpl index 7192135e87..ba84482e4a 100644 --- a/src/views/admin/partials/menu.tpl +++ b/src/views/admin/partials/menu.tpl @@ -18,8 +18,8 @@ {{{ if user.privileges.admin:categories }}}
  • [[admin/menu:manage/categories]]
  • {{{ end }}} {{{ if user.privileges.admin:privileges }}}
  • [[admin/menu:manage/privileges]]
  • {{{ end }}} {{{ if user.privileges.admin:users }}}
  • [[admin/menu:manage/users]]
  • {{{ end }}} + {{{ if user.privileges.admin:groups }}}
  • [[admin/menu:manage/groups]]
  • {{{ end }}} {{{ if user.privileges.superadmin }}} -
  • [[admin/menu:manage/groups]]
  • [[admin/menu:manage/admins-mods]]
  • [[admin/menu:manage/registration]]
  • [[admin/menu:manage/tags]]
  • @@ -189,8 +189,8 @@ {{{ if user.privileges.admin:categories }}}
  • [[admin/menu:manage/categories]]
  • {{{ end }}} {{{ if user.privileges.admin:privileges }}}
  • [[admin/menu:manage/privileges]]
  • {{{ end }}} {{{ if user.privileges.admin:users }}}
  • [[admin/menu:manage/users]]
  • {{{ end }}} + {{{ if user.privileges.admin:groups }}}
  • [[admin/menu:manage/groups]]
  • {{{ end }}} {{{ if user.privileges.superadmin }}} -
  • [[admin/menu:manage/groups]]
  • [[admin/menu:manage/admins-mods]]
  • [[admin/menu:manage/registration]]
  • [[admin/menu:manage/tags]]