new priv for uploads

This commit is contained in:
barisusakli
2016-07-12 19:58:59 +03:00
parent 03208807e4
commit d2cbd7e6dc
7 changed files with 119 additions and 45 deletions

View File

@@ -10,7 +10,7 @@ var db = require('./database'),
schemaDate, thisSchemaDate,
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
latestSchema = Date.UTC(2016, 5, 13);
latestSchema = Date.UTC(2016, 6, 12);
Upgrade.check = function(callback) {
db.get('schemaDate', function(err, value) {
@@ -617,6 +617,46 @@ Upgrade.upgrade = function(callback) {
winston.info('[2016/06/13] Store upvotes/downvotes separately skipped!');
next();
}
},
function(next) {
thisSchemaDate = Date.UTC(2016, 6, 12);
if (schemaDate < thisSchemaDate) {
updatesMade = true;
winston.info('[2016/07/12] Giving upload privileges');
var privilegesAPI = require('./privileges');
var meta = require('./meta');
db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
async.eachSeries(cids, function(cid, next) {
privilegesAPI.categories.list(cid, function(err, data) {
if (err) {
return next(err);
}
async.eachSeries(data.groups, function(group, next) {
if (group.name === 'guests' && parseInt(meta.config.allowGuestUploads, 10) !== 1) {
return next();
}
if (group.privileges['groups:read']) {
privilegesAPI.categories.give(['upload:post:image'], cid, group.name, next);
} else {
next();
}
}, next);
});
}, function(err) {
if (err) {
return next(err);
}
winston.info('[2016/07/12] Upload privileges done');
Upgrade.update(thisSchemaDate, next);
});
});
} else {
winston.info('[2016/07/12] Upload privileges skipped!');
next();
}
}
// Add new schema updates here
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!