mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-03 13:19:51 +01:00
upgrade script: give topics:read privs to any group that has topics:create privs
This commit is contained in:
@@ -10,7 +10,7 @@ var db = require('./database'),
|
||||
schemaDate, thisSchemaDate,
|
||||
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
||||
latestSchema = Date.UTC(2016, 3, 29);
|
||||
latestSchema = Date.UTC(2016, 4, 28);
|
||||
|
||||
Upgrade.check = function(callback) {
|
||||
db.get('schemaDate', function(err, value) {
|
||||
@@ -494,6 +494,75 @@ Upgrade.upgrade = function(callback) {
|
||||
winston.info('[2016/04/29] Dismiss flags from deleted topics skipped!');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = Date.UTC(2016, 4, 28);
|
||||
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
winston.info('[2016/05/28] Giving topics:read privs to any group that has topics:create selected');
|
||||
|
||||
var groupsAPI = require('./groups');
|
||||
var privilegesAPI = require('./privileges');
|
||||
|
||||
db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
|
||||
async.eachSeries(cids, function(cid, next) {
|
||||
privilegesAPI.categories.list(cid, function(err, data) {
|
||||
var groups = data.groups;
|
||||
var users = data.users;
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
async.each(groups, function(group, next) {
|
||||
if (group.privileges['groups:topics:create']) {
|
||||
return groupsAPI.join('cid:' + cid + ':privileges:groups:topics:read', group.name, function(err) {
|
||||
if (!err) {
|
||||
winston.info('cid:' + cid + ':privileges:groups:topics:read granted to gid: ' + group.name);
|
||||
}
|
||||
|
||||
return next(err);
|
||||
});
|
||||
}
|
||||
|
||||
next(null);
|
||||
}, next);
|
||||
},
|
||||
function(next) {
|
||||
async.each(users, function(user, next) {
|
||||
if (user.privileges['topics:create']) {
|
||||
return groupsAPI.join('cid:' + cid + ':privileges:topics:read', user.uid, function(err) {
|
||||
if (!err) {
|
||||
winston.info('cid:' + cid + ':privileges:topics:read granted to uid: ' + user.uid);
|
||||
}
|
||||
|
||||
return next(err);
|
||||
});
|
||||
}
|
||||
|
||||
next(null);
|
||||
}, next);
|
||||
}
|
||||
], function(err) {
|
||||
if (!err) {
|
||||
winston.info('-- cid ' + cid + ' upgraded');
|
||||
}
|
||||
|
||||
next(err);
|
||||
});
|
||||
});
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
winston.info('[2016/05/28] Giving topics:read privs to any group that has topics:create selected - done');
|
||||
Upgrade.update(thisSchemaDate, next);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
winston.info('[2016/05/28] Giving topics:read privs to any group that has topics:create selected - skipped!');
|
||||
next();
|
||||
}
|
||||
}
|
||||
// Add new schema updates here
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!
|
||||
|
||||
Reference in New Issue
Block a user