mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
make sure user is admin/mod before forking
This commit is contained in:
@@ -6,6 +6,7 @@ var async = require('async'),
|
|||||||
|
|
||||||
db = require('../database'),
|
db = require('../database'),
|
||||||
|
|
||||||
|
user = require('../user'),
|
||||||
posts = require('../posts'),
|
posts = require('../posts'),
|
||||||
privileges = require('../privileges'),
|
privileges = require('../privileges'),
|
||||||
postTools = require('../postTools'),
|
postTools = require('../postTools'),
|
||||||
@@ -32,37 +33,33 @@ module.exports = function(Topics) {
|
|||||||
return a - b;
|
return a - b;
|
||||||
});
|
});
|
||||||
var mainPid = pids[0];
|
var mainPid = pids[0];
|
||||||
|
var cid;
|
||||||
async.parallel({
|
var tid;
|
||||||
postData: function(callback) {
|
async.waterfall([
|
||||||
posts.getPostData(mainPid, callback);
|
function(next) {
|
||||||
|
posts.getCidByPid(mainPid, next);
|
||||||
},
|
},
|
||||||
cid: function(callback) {
|
function(_cid, next) {
|
||||||
posts.getCidByPid(mainPid, callback);
|
cid = _cid;
|
||||||
|
async.parallel({
|
||||||
|
postData: function(next) {
|
||||||
|
posts.getPostData(mainPid, next);
|
||||||
|
},
|
||||||
|
isAdmin: function(next) {
|
||||||
|
user.isAdministrator(uid, next);
|
||||||
|
},
|
||||||
|
isModerator: function(next) {
|
||||||
|
user.isModerator(uid, cid, next);
|
||||||
}
|
}
|
||||||
}, function(err, results) {
|
}, next);
|
||||||
if (err) {
|
},
|
||||||
return callback(err);
|
function(results, next) {
|
||||||
|
if (!results.isAdmin && !results.isModerator) {
|
||||||
|
return next(new Error('[[error:no-privileges]]'));
|
||||||
}
|
}
|
||||||
|
Topics.create({uid: results.postData.uid, title: title, cid: cid}, next);
|
||||||
Topics.create({uid: results.postData.uid, title: title, cid: results.cid}, function(err, tid) {
|
},
|
||||||
if (err) {
|
function(_tid, next) {
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
async.eachSeries(pids, move, function(err) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
Topics.updateTimestamp(tid, Date.now(), function(err) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
Topics.getTopicData(tid, callback);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
function move(pid, next) {
|
function move(pid, next) {
|
||||||
privileges.posts.canEdit(pid, uid, function(err, canEdit) {
|
privileges.posts.canEdit(pid, uid, function(err, canEdit) {
|
||||||
if(err || !canEdit) {
|
if(err || !canEdit) {
|
||||||
@@ -72,8 +69,16 @@ module.exports = function(Topics) {
|
|||||||
Topics.movePostToTopic(pid, tid, next);
|
Topics.movePostToTopic(pid, tid, next);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
tid = _tid;
|
||||||
});
|
async.eachSeries(pids, move, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
Topics.updateTimestamp(tid, Date.now(), next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
Topics.getTopicData(tid, next);
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.movePostToTopic = function(pid, tid, callback) {
|
Topics.movePostToTopic = function(pid, tid, callback) {
|
||||||
|
|||||||
@@ -47,7 +47,9 @@ module.exports = function(Topics) {
|
|||||||
function(next) {
|
function(next) {
|
||||||
Topics.setTopicField(tid, 'lastposttime', timestamp, next);
|
Topics.setTopicField(tid, 'lastposttime', timestamp, next);
|
||||||
}
|
}
|
||||||
], callback);
|
], function(err, results) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.updateRecent = function(tid, timestamp, callback) {
|
Topics.updateRecent = function(tid, timestamp, callback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user