mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 04:06:17 +02:00
fix: memberPostCids saving, closes #14170
validCids is an array of strings if a group was named 3rd party devs, then the isNaN(parseInt()) check was failing
This commit is contained in:
@@ -77,7 +77,7 @@ module.exports = function (Groups) {
|
||||
|
||||
if (values.hasOwnProperty('memberPostCids')) {
|
||||
const validCids = await categories.getCidsByPrivilege('categories:cid', groupName, 'topics:read');
|
||||
const cidsArray = values.memberPostCids.split(',').map(cid => parseInt(cid.trim(), 10)).filter(Boolean);
|
||||
const cidsArray = values.memberPostCids.split(',').map(cid => (cid || '').trim()).filter(Boolean);
|
||||
payload.memberPostCids = cidsArray.filter(cid => validCids.includes(cid)).join(',') || '';
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ async function isAllowedToCids(privilege, uidOrGroupName, cids) {
|
||||
const groupKeys = cids.map(cid => `cid:${cid}:privileges:groups:${privilege}`);
|
||||
|
||||
// Group handling
|
||||
if (isNaN(parseInt(uidOrGroupName, 10)) && (uidOrGroupName || '').length) {
|
||||
if (!utils.isNumber(uidOrGroupName) && (uidOrGroupName || '').length) {
|
||||
return await checkIfAllowedGroup(uidOrGroupName, groupKeys);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ const nconf = require('nconf');
|
||||
|
||||
const db = require('./mocks/databasemock');
|
||||
const helpers = require('./helpers');
|
||||
const Categories = require('../src/categories');
|
||||
const Groups = require('../src/groups');
|
||||
const User = require('../src/user');
|
||||
const plugins = require('../src/plugins');
|
||||
@@ -566,6 +567,20 @@ describe('Groups', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should properly set memberPostCids', async () => {
|
||||
const c1 = await Categories.create({ name: 'Test Category' });
|
||||
const c2 = await Categories.create({ name: 'Test Category' });
|
||||
const c3 = await Categories.create({ name: 'Test Category' });
|
||||
await Groups.create({
|
||||
name: '3rd party devs',
|
||||
});
|
||||
await Groups.update('3rd party devs', {
|
||||
memberPostCids: `${c1.cid},${c2.cid},${c3.cid}`,
|
||||
});
|
||||
const groupData = await Groups.get('3rd party devs', {});
|
||||
assert.strictEqual(groupData.memberPostCids, '1,2,3');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.destroy()', () => {
|
||||
|
||||
Reference in New Issue
Block a user