You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/src/upgrades/1.1.0/assign_topic_read_privilege.js

72 lines
1.7 KiB
JavaScript

'use strict';
const async = require('async');
const winston = require('winston');
const db = require('../../database');
module.exports = {
name: 'Giving topics:read privs to any group that was previously allowed to Find & Access Category',
timestamp: Date.UTC(2016, 4, 28),
method: function (callback) {
const groupsAPI = require('../../groups');
const privilegesAPI = require('../../privileges');
db.getSortedSetRange('categories:cid', 0, -1, (err, cids) => {
if (err) {
return callback(err);
}
async.eachSeries(cids, (cid, next) => {
privilegesAPI.categories.list(cid, (err, data) => {
if (err) {
return next(err);
}
const { groups } = data;
const { users } = data;
async.waterfall([
function (next) {
async.eachSeries(groups, (group, next) => {
if (group.privileges['groups:read']) {
return groupsAPI.join(`cid:${cid}:privileges:groups:topics:read`, group.name, (err) => {
if (!err) {
winston.verbose(`cid:${cid}:privileges:groups:topics:read granted to gid: ${group.name}`);
}
return next(err);
});
}
next(null);
}, next);
},
function (next) {
async.eachSeries(users, (user, next) => {
if (user.privileges.read) {
return groupsAPI.join(`cid:${cid}:privileges:topics:read`, user.uid, (err) => {
if (!err) {
winston.verbose(`cid:${cid}:privileges:topics:read granted to uid: ${user.uid}`);
}
return next(err);
});
}
next(null);
}, next);
},
], (err) => {
if (!err) {
winston.verbose(`-- cid ${cid} upgraded`);
}
next(err);
});
});
}, callback);
});
},
};