mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 02:25:55 +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'),
|
||||
|
||||
user = require('../user'),
|
||||
posts = require('../posts'),
|
||||
privileges = require('../privileges'),
|
||||
postTools = require('../postTools'),
|
||||
@@ -32,37 +33,33 @@ module.exports = function(Topics) {
|
||||
return a - b;
|
||||
});
|
||||
var mainPid = pids[0];
|
||||
|
||||
async.parallel({
|
||||
postData: function(callback) {
|
||||
posts.getPostData(mainPid, callback);
|
||||
var cid;
|
||||
var tid;
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
posts.getCidByPid(mainPid, next);
|
||||
},
|
||||
cid: function(callback) {
|
||||
posts.getCidByPid(mainPid, callback);
|
||||
function(_cid, next) {
|
||||
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) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}, next);
|
||||
},
|
||||
function(results, next) {
|
||||
if (!results.isAdmin && !results.isModerator) {
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
|
||||
Topics.create({uid: results.postData.uid, title: title, cid: results.cid}, function(err, tid) {
|
||||
if (err) {
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
Topics.create({uid: results.postData.uid, title: title, cid: cid}, next);
|
||||
},
|
||||
function(_tid, next) {
|
||||
function move(pid, next) {
|
||||
privileges.posts.canEdit(pid, uid, function(err, canEdit) {
|
||||
if(err || !canEdit) {
|
||||
@@ -72,8 +69,16 @@ module.exports = function(Topics) {
|
||||
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) {
|
||||
|
||||
@@ -47,7 +47,9 @@ module.exports = function(Topics) {
|
||||
function(next) {
|
||||
Topics.setTopicField(tid, 'lastposttime', timestamp, next);
|
||||
}
|
||||
], callback);
|
||||
], function(err, results) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
Topics.updateRecent = function(tid, timestamp, callback) {
|
||||
|
||||
Reference in New Issue
Block a user