Node.js based forum software built for the modern web
fix: memberPostCids saving, closes #14170
Barış Soner Uşaklıc40708f4ca3f
diff --git a/src/groups/update.js b/src/groups/update.jsindex 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.jsindex 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.jsindex 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()', () => {