fix: regression via c1b3079d93

Also refactored privilege render logic so that it no longer needs a server-side hack to render column count
v1.18.x
Julian Lam 4 years ago
parent 4cbd13fd9c
commit 2a939aad8d

@ -81,12 +81,8 @@ get:
type: boolean
isSystem:
type: boolean
columnCountUser:
type: number
columnCountUserOther:
type: number
columnCountGroup:
type: number
columnCountGroupOther:
type: number
categories:

@ -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
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"

@ -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
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"

@ -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();

@ -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;
};

@ -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;
};

@ -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;
};

@ -60,7 +60,8 @@
</tbody>
<tfoot>
<tr>
<td colspan="{privileges.columnCountGroup}">
<td colspan="3"></td>
<td colspan="{privileges.keys.groups.length}">
<div class="btn-toolbar">
<button type="button" class="btn btn-default pull-right" data-ajaxify="false" data-action="search.group">
<i class="fa fa-users"></i>
@ -138,7 +139,8 @@
</tbody>
<tfoot>
<tr>
<td colspan="{privileges.columnCountUser}">
<td colspan="3"></td>
<td colspan="{privileges.keys.users.length}">
<button type="button" class="btn btn-default pull-right" data-ajaxify="false" data-action="search.user">
<i class="fa fa-user"></i>
[[admin/manage/categories:privileges.search-user]]

@ -32,7 +32,8 @@
</tbody>
<tfoot>
<tr>
<td colspan="{privileges.columnCount}">
<td colspan="3"></td>
<td colspan="{privileges.keys.groups.length}">
<div class="btn-toolbar">
<button type="button" class="btn btn-default pull-right" data-ajaxify="false" data-action="search.group">
<i class="fa fa-users"></i>
@ -84,7 +85,8 @@
</tbody>
<tfoot>
<tr>
<td colspan="{privileges.columnCount}">
<td colspan="3"></td>
<td colspan="{privileges.keys.users.length}">
<button type="button" class="btn btn-default pull-right" data-ajaxify="false" data-action="search.user">
<i class="fa fa-user"></i>
[[admin/manage/categories:privileges.search-user]]

Loading…
Cancel
Save