From c40708f4ca3fe9f8633985e3009009d74fff7a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 13 Apr 2026 21:14:45 -0400 Subject: [PATCH] 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 --- src/groups/update.js | 2 +- src/privileges/helpers.js | 2 +- test/groups.js | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/groups/update.js b/src/groups/update.js index 804268c587..caaedf38e4 100644 --- a/src/groups/update.js +++ b/src/groups/update.js @@ -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(',') || ''; } diff --git a/src/privileges/helpers.js b/src/privileges/helpers.js index 6ba57cdf66..6c4e32a77e 100644 --- a/src/privileges/helpers.js +++ b/src/privileges/helpers.js @@ -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); } diff --git a/test/groups.js b/test/groups.js index 59d88abafd..9ea3106451 100644 --- a/test/groups.js +++ b/test/groups.js @@ -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()', () => {