diff --git a/public/openapi/read/admin/manage/privileges/cid.yaml b/public/openapi/read/admin/manage/privileges/cid.yaml index 73dd899610..2625f3abef 100644 --- a/public/openapi/read/admin/manage/privileges/cid.yaml +++ b/public/openapi/read/admin/manage/privileges/cid.yaml @@ -81,12 +81,8 @@ get: type: boolean isSystem: type: boolean - columnCountUser: - type: number columnCountUserOther: type: number - columnCountGroup: - type: number columnCountGroupOther: type: number categories: diff --git a/public/openapi/write/categories/cid/privileges.yaml b/public/openapi/write/categories/cid/privileges.yaml index 1215622871..9cf239cbac 100644 --- a/public/openapi/write/categories/cid/privileges.yaml +++ b/public/openapi/write/categories/cid/privileges.yaml @@ -24,6 +24,25 @@ get: response: type: object properties: + labels: + type: object + properties: + users: + type: array + items: + type: object + properties: + name: + type: string + description: Language key of the privilege name's user-friendly name + groups: + type: array + items: + type: object + properties: + name: + type: string + description: Language key of the privilege name's user-friendly name users: type: array items: @@ -59,4 +78,23 @@ get: isPrivate: type: boolean isSystem: - type: boolean \ No newline at end of file + type: boolean + keys: + type: object + properties: + users: + type: array + items: + type: string + description: "Privilege name" + groups: + type: array + items: + type: string + description: "Privilege name" + columnCountUserOther: + type: number + description: "The number of additional user privileges added by plugins" + columnCountGroupOther: + type: number + description: "The number of additional group privileges added by plugins" \ No newline at end of file diff --git a/public/openapi/write/categories/cid/privileges/privilege.yaml b/public/openapi/write/categories/cid/privileges/privilege.yaml index 62d723bb78..9b00cc8573 100644 --- a/public/openapi/write/categories/cid/privileges/privilege.yaml +++ b/public/openapi/write/categories/cid/privileges/privilege.yaml @@ -41,6 +41,25 @@ put: response: type: object properties: + labels: + type: object + properties: + users: + type: array + items: + type: object + properties: + name: + type: string + description: Language key of the privilege name's user-friendly name + groups: + type: array + items: + type: object + properties: + name: + type: string + description: Language key of the privilege name's user-friendly name users: type: array items: @@ -77,6 +96,25 @@ put: type: boolean isSystem: type: boolean + keys: + type: object + properties: + users: + type: array + items: + type: string + description: "Privilege name" + groups: + type: array + items: + type: string + description: "Privilege name" + columnCountUserOther: + type: number + description: "The number of additional user privileges added by plugins" + columnCountGroupOther: + type: number + description: "The number of additional user privileges added by plugins" delete: tags: - categories @@ -120,6 +158,25 @@ delete: response: type: object properties: + labels: + type: object + properties: + users: + type: array + items: + type: object + properties: + name: + type: string + description: Language key of the privilege name's user-friendly name + groups: + type: array + items: + type: object + properties: + name: + type: string + description: Language key of the privilege name's user-friendly name users: type: array items: @@ -155,4 +212,23 @@ delete: isPrivate: type: boolean isSystem: - type: boolean \ No newline at end of file + type: boolean + keys: + type: object + properties: + users: + type: array + items: + type: string + description: "Privilege name" + groups: + type: array + items: + type: string + description: "Privilege name" + columnCountUserOther: + type: number + description: "The number of additional user privileges added by plugins" + columnCountGroupOther: + type: number + description: "The number of additional user privileges added by plugins" \ No newline at end of file diff --git a/public/src/admin/manage/privileges.js b/public/src/admin/manage/privileges.js index d24888cb8a..a8040af1ef 100644 --- a/public/src/admin/manage/privileges.js +++ b/public/src/admin/manage/privileges.js @@ -174,12 +174,8 @@ define('admin/manage/privileges', [ api.get(`/categories/${cid}/privileges`, {}).then((privileges) => { ajaxify.data.privileges = { ...ajaxify.data.privileges, ...privileges }; var tpl = parseInt(cid, 10) ? 'admin/partials/privileges/category' : 'admin/partials/privileges/global'; - Promise.all([ - app.parseAndTranslate(tpl, 'privileges.groups', { privileges }), - app.parseAndTranslate(tpl, 'privileges.users', { privileges }), - ]).then((html) => { - $('.privilege-table-container tbody').first().html(html[0]); - $('.privilege-table-container tbody').last().html(html[1]); + app.parseAndTranslate(tpl, { privileges }).then((html) => { + $('.privilege-table-container').html(html); Privileges.exposeAssumedPrivileges(); checkboxRowSelector.updateAll(); diff --git a/src/api/categories.js b/src/api/categories.js index d5d9a5e4e1..3486df1ad5 100644 --- a/src/api/categories.js +++ b/src/api/categories.js @@ -53,14 +53,6 @@ categoriesAPI.getPrivileges = async (caller, cid) => { responsePayload = await privileges.categories.list(cid); } - // The various privilege .list() methods return superfluous data for the template, return only a minimal set - const validKeys = ['users', 'groups']; - Object.keys(responsePayload).forEach((key) => { - if (!validKeys.includes(key)) { - delete responsePayload[key]; - } - }); - return responsePayload; }; diff --git a/src/privileges/admin.js b/src/privileges/admin.js index 5b0f6c440d..4a908e37bd 100644 --- a/src/privileges/admin.js +++ b/src/privileges/admin.js @@ -137,12 +137,10 @@ privsAdmin.list = async function (uid) { groupPrivilegeList.splice(idx, 1); } - async function getLabels() { - return await utils.promiseParallel({ - users: plugins.hooks.fire('filter:privileges.admin.list_human', privilegeLabels.slice()), - groups: plugins.hooks.fire('filter:privileges.admin.groups.list_human', privilegeLabels.slice()), - }); - } + const labels = await utils.promiseParallel({ + users: plugins.hooks.fire('filter:privileges.admin.list_human', privilegeLabels.slice()), + groups: plugins.hooks.fire('filter:privileges.admin.groups.list_human', privilegeLabels.slice()), + }); const keys = await utils.promiseParallel({ users: plugins.hooks.fire('filter:privileges.admin.list', userPrivilegeList.slice()), @@ -150,14 +148,12 @@ privsAdmin.list = async function (uid) { }); const payload = await utils.promiseParallel({ - labels: getLabels(), + labels, users: helpers.getUserPrivileges(0, keys.users), groups: helpers.getGroupPrivileges(0, keys.groups), }); 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 + 3; return payload; }; diff --git a/src/privileges/categories.js b/src/privileges/categories.js index e8cc21d489..0dbe715071 100644 --- a/src/privileges/categories.js +++ b/src/privileges/categories.js @@ -54,12 +54,10 @@ privsCategories.privilegeList = privsCategories.userPrivilegeList.concat(privsCa // Method used in admin/category controller to show all users/groups with privs in that given cid privsCategories.list = async function (cid) { - async function getLabels() { - return await utils.promiseParallel({ - users: plugins.hooks.fire('filter:privileges.list_human', privsCategories.privilegeLabels.slice()), - groups: plugins.hooks.fire('filter:privileges.groups.list_human', privsCategories.privilegeLabels.slice()), - }); - } + const labels = await utils.promiseParallel({ + users: plugins.hooks.fire('filter:privileges.list_human', privsCategories.privilegeLabels.slice()), + groups: plugins.hooks.fire('filter:privileges.groups.list_human', privsCategories.privilegeLabels.slice()), + }); const keys = await utils.promiseParallel({ users: plugins.hooks.fire('filter:privileges.list', privsCategories.userPrivilegeList.slice()), @@ -67,17 +65,15 @@ privsCategories.list = async function (cid) { }); const payload = await utils.promiseParallel({ - labels: getLabels(), + labels, users: helpers.getUserPrivileges(cid, keys.users), groups: helpers.getGroupPrivileges(cid, keys.groups), }); payload.keys = keys; - // This is a hack because I can't do {labels.users.length} to echo the count in templates.js - payload.columnCountUser = payload.labels.users.length + 3; payload.columnCountUserOther = payload.labels.users.length - privsCategories.privilegeLabels.length; - payload.columnCountGroup = payload.labels.groups.length + 3; payload.columnCountGroupOther = payload.labels.groups.length - privsCategories.privilegeLabels.length; + return payload; }; diff --git a/src/views/admin/partials/privileges/category.tpl b/src/views/admin/partials/privileges/category.tpl index 1282120306..a10a3f848f 100644 --- a/src/views/admin/partials/privileges/category.tpl +++ b/src/views/admin/partials/privileges/category.tpl @@ -60,7 +60,8 @@