mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-05 17:48:50 +02:00
fix: #7901, handle group names that are translation keys
This commit is contained in:
@@ -2,10 +2,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
const validator = require('validator');
|
||||||
|
|
||||||
const groups = require('../groups');
|
const groups = require('../groups');
|
||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
|
const translator = require('../translator');
|
||||||
|
|
||||||
const helpers = module.exports;
|
const helpers = module.exports;
|
||||||
|
|
||||||
@@ -126,7 +128,8 @@ helpers.getGroupPrivileges = async function (cid, hookName, groupPrivilegeList)
|
|||||||
memberPrivs[groupPrivileges[x]] = memberSets[x].includes(member);
|
memberPrivs[groupPrivileges[x]] = memberSets[x].includes(member);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
name: member,
|
name: validator.escape(member),
|
||||||
|
nameEscaped: translator.escape(validator.escape(member)),
|
||||||
privileges: memberPrivs,
|
privileges: memberPrivs,
|
||||||
isPrivate: groupData[index] && !!groupData[index].private,
|
isPrivate: groupData[index] && !!groupData[index].private,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const groups = require('../../groups');
|
const groups = require('../../groups');
|
||||||
|
const user = require('../../user');
|
||||||
const categories = require('../../categories');
|
const categories = require('../../categories');
|
||||||
const privileges = require('../../privileges');
|
const privileges = require('../../privileges');
|
||||||
const plugins = require('../../plugins');
|
const plugins = require('../../plugins');
|
||||||
@@ -51,6 +52,14 @@ Categories.setPrivilege = async function (socket, data) {
|
|||||||
if (!data) {
|
if (!data) {
|
||||||
throw new Error('[[error:invalid-data]]');
|
throw new Error('[[error:invalid-data]]');
|
||||||
}
|
}
|
||||||
|
const [userExists, groupExists] = await Promise.all([
|
||||||
|
user.exists(data.member),
|
||||||
|
groups.exists(data.member),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!userExists && !groupExists) {
|
||||||
|
throw new Error('[[error:no-user-or-group]]');
|
||||||
|
}
|
||||||
|
|
||||||
if (Array.isArray(data.privilege)) {
|
if (Array.isArray(data.privilege)) {
|
||||||
await Promise.all(data.privilege.map(privilege => groups[data.set ? 'join' : 'leave']('cid:' + data.cid + ':privileges:' + privilege, data.member)));
|
await Promise.all(data.privilege.map(privilege => groups[data.set ? 'join' : 'leave']('cid:' + data.cid + ':privileges:' + privilege, data.member)));
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<!-- BEGIN privileges.groups -->
|
<!-- BEGIN privileges.groups -->
|
||||||
<tr data-group-name="{privileges.groups.name}" data-private="<!-- IF privileges.groups.isPrivate -->1<!-- ELSE -->0<!-- ENDIF privileges.groups.isPrivate -->">
|
<tr data-group-name="{privileges.groups.nameEscaped}" data-private="<!-- IF privileges.groups.isPrivate -->1<!-- ELSE -->0<!-- ENDIF privileges.groups.isPrivate -->">
|
||||||
<td>
|
<td>
|
||||||
<!-- IF privileges.groups.isPrivate -->
|
<!-- IF privileges.groups.isPrivate -->
|
||||||
<i class="fa fa-lock text-muted" title="[[admin/manage/categories:privileges.group-private]]"></i>
|
<i class="fa fa-lock text-muted" title="[[admin/manage/categories:privileges.group-private]]"></i>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<!-- BEGIN privileges.groups -->
|
<!-- BEGIN privileges.groups -->
|
||||||
<tr data-group-name="{privileges.groups.name}" data-private="<!-- IF privileges.groups.isPrivate -->1<!-- ELSE -->0<!-- ENDIF privileges.groups.isPrivate -->">
|
<tr data-group-name="{privileges.groups.nameEscaped}" data-private="<!-- IF privileges.groups.isPrivate -->1<!-- ELSE -->0<!-- ENDIF privileges.groups.isPrivate -->">
|
||||||
<td>
|
<td>
|
||||||
<!-- IF privileges.groups.isPrivate -->
|
<!-- IF privileges.groups.isPrivate -->
|
||||||
<i class="fa fa-lock text-muted" title="[[admin/manage/categories:privileges.group-private]]"></i>
|
<i class="fa fa-lock text-muted" title="[[admin/manage/categories:privileges.group-private]]"></i>
|
||||||
|
|||||||
Reference in New Issue
Block a user