mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 00:15:46 +01:00
fix: #11136, tests, and returning the proper number of arrays
This commit is contained in:
@@ -101,7 +101,7 @@ Categories.getModerators = async function (cid) {
|
||||
Categories.getModeratorUids = async function (cids) {
|
||||
// Only check active categories
|
||||
const disabled = (await Categories.getCategoriesFields(cids, ['disabled'])).map(obj => obj.disabled);
|
||||
cids = cids.filter((_, idx) => !disabled[idx]);
|
||||
// cids = cids.filter((_, idx) => !disabled[idx]);
|
||||
|
||||
const groupNames = cids.reduce((memo, cid) => {
|
||||
memo.push(`cid:${cid}:privileges:moderate`);
|
||||
@@ -124,9 +124,14 @@ Categories.getModeratorUids = async function (cids) {
|
||||
const uniqGroups = _.uniq(_.flatten(sets.groupNames));
|
||||
const groupUids = await groups.getMembersOfGroups(uniqGroups);
|
||||
const map = _.zipObject(uniqGroups, groupUids);
|
||||
const moderatorUids = cids.map(
|
||||
(cid, index) => _.uniq(sets.uids[index].concat(_.flatten(sets.groupNames[index].map(g => map[g]))))
|
||||
);
|
||||
const moderatorUids = cids.map((cid, index) => {
|
||||
if (disabled[index]) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return _.uniq(sets.uids[index].concat(_.flatten(sets.groupNames[index].map(g => map[g]))));
|
||||
});
|
||||
console.log('what', moderatorUids);
|
||||
return moderatorUids;
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ const cache = require('../cache');
|
||||
module.exports = function (Categories) {
|
||||
Categories.update = async function (modified) {
|
||||
const cids = Object.keys(modified);
|
||||
console.log('updating', cids);
|
||||
await Promise.all(cids.map(cid => updateCategory(cid, modified[cid])));
|
||||
return cids;
|
||||
};
|
||||
|
||||
@@ -826,17 +826,18 @@ describe('Categories', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Categories.getModeratorUids', () => {
|
||||
before((done) => {
|
||||
async.series([
|
||||
async.apply(groups.create, { name: 'testGroup' }),
|
||||
async.apply(groups.join, 'cid:1:privileges:groups:moderate', 'testGroup'),
|
||||
async.apply(groups.join, 'testGroup', 1),
|
||||
], done);
|
||||
describe.only('Categories.getModeratorUids', () => {
|
||||
let cid;
|
||||
|
||||
before(async () => {
|
||||
({ cid } = await Categories.create({ name: 'foobar' }));
|
||||
await groups.create({ name: 'testGroup' });
|
||||
await groups.join(`cid:${cid}:privileges:groups:moderate`, 'testGroup');
|
||||
await groups.join('testGroup', 1);
|
||||
});
|
||||
|
||||
it('should retrieve all users with moderator bit in category privilege', (done) => {
|
||||
Categories.getModeratorUids([1, 2], (err, uids) => {
|
||||
Categories.getModeratorUids([cid, 2], (err, uids) => {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(uids.length, 2);
|
||||
assert(uids[0].includes('1'));
|
||||
@@ -851,7 +852,7 @@ describe('Categories', () => {
|
||||
async.apply(groups.join, 'cid:1:privileges:groups:moderate', 'testGroup2'),
|
||||
async.apply(groups.join, 'testGroup2', 1),
|
||||
function (next) {
|
||||
Categories.getModeratorUids([1, 2], (err, uids) => {
|
||||
Categories.getModeratorUids([cid, 2], (err, uids) => {
|
||||
assert.ifError(err);
|
||||
assert(uids[0].includes('1'));
|
||||
next();
|
||||
@@ -860,10 +861,18 @@ describe('Categories', () => {
|
||||
], done);
|
||||
});
|
||||
|
||||
it('should not return moderators of disabled categories', async () => {
|
||||
const payload = {};
|
||||
payload[cid] = { disabled: 1 };
|
||||
await Categories.update(payload);
|
||||
const uids = await Categories.getModeratorUids([1, 2]);
|
||||
assert(!uids[0].includes('1'));
|
||||
});
|
||||
|
||||
after((done) => {
|
||||
async.series([
|
||||
async.apply(groups.leave, 'cid:1:privileges:groups:moderate', 'testGroup'),
|
||||
async.apply(groups.leave, 'cid:1:privileges:groups:moderate', 'testGroup2'),
|
||||
async.apply(groups.leave, `cid:${cid}:privileges:groups:moderate`, 'testGroup'),
|
||||
async.apply(groups.leave, `cid:${cid}:privileges:groups:moderate`, 'testGroup2'),
|
||||
async.apply(groups.destroy, 'testGroup'),
|
||||
async.apply(groups.destroy, 'testGroup2'),
|
||||
], done);
|
||||
|
||||
Reference in New Issue
Block a user