diff --git a/src/postTools.js b/src/postTools.js index 3c5a9e53ca..103c82ee4b 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -18,12 +18,6 @@ var winston = require('winston'), (function(PostTools) { - PostTools.isMain = function(pid, tid, callback) { - topics.getTopicField(tid, 'mainPid', function(err, mainPid) { - callback(err, parseInt(pid, 10) === parseInt(mainPid, 10)); - }); - }; - PostTools.edit = function(uid, pid, title, content, options, callback) { options = options || {}; @@ -57,7 +51,7 @@ var winston = require('winston'), async.parallel({ topic: function(next) { var tid = postData.tid; - PostTools.isMain(pid, tid, function(err, isMainPost) { + posts.isMain(pid, function(err, isMainPost) { if (err) { return next(err); } diff --git a/src/posts.js b/src/posts.js index 1191e5f9f1..519bb5453a 100644 --- a/src/posts.js +++ b/src/posts.js @@ -476,6 +476,17 @@ var async = require('async'), }); }; + Posts.isMain = function(pid, callback) { + Posts.getPostField(pid, 'tid', function(err, tid) { + if (err) { + return callback(err); + } + topics.getTopicField(tid, 'mainPid', function(err, mainPid) { + callback(err, parseInt(pid, 10) === parseInt(mainPid, 10)); + }); + }); + }; + Posts.updatePostVoteCount = function(pid, voteCount, callback) { async.parallel([ function(next) { diff --git a/src/privileges/posts.js b/src/privileges/posts.js index 23e8740a95..e932819563 100644 --- a/src/privileges/posts.js +++ b/src/privileges/posts.js @@ -79,7 +79,12 @@ module.exports = function(privileges) { }; privileges.posts.canMove = function(pid, uid, callback) { - isAdminOrMod(pid, uid, callback); + posts.isMain(pid, function(err, isMain) { + if (err || isMain) { + return callback(err || new Error('[[error:cant-move-mainpost]]')); + } + isAdminOrMod(pid, uid, callback); + }); }; function isAdminOrMod(pid, uid, callback) { diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js index d2877a3d43..9a44ab1927 100644 --- a/src/socket.io/modules.js +++ b/src/socket.io/modules.js @@ -62,7 +62,7 @@ SocketModules.composer.push = function(socket, pid, callback) { topics.getTopicTags(postData.tid, next); }, isMain: function(next) { - postTools.isMain(pid, postData.tid, next); + posts.isMain(pid, next); } }, function(err, results) { if(err) { @@ -82,15 +82,9 @@ SocketModules.composer.push = function(socket, pid, callback) { }; SocketModules.composer.editCheck = function(socket, pid, callback) { - posts.getPostField(pid, 'tid', function(err, tid) { - if (err) { - return callback(err); - } - - postTools.isMain(pid, tid, function(err, isMain) { - callback(err, { - titleEditable: isMain - }); + posts.isMain(pid, function(err, isMain) { + callback(err, { + titleEditable: isMain }); }); }; diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js index d5d452b5b6..93cf8916c4 100644 --- a/src/socket.io/topics.js +++ b/src/socket.io/topics.js @@ -233,7 +233,7 @@ SocketTopics.movePost = function(socket, data, callback) { return callback(new Error('[[error:invalid-data]]')); } - privileges.posts.canMove(data.tid, socket.uid, function(err, canMove) { + privileges.posts.canMove(data.pid, socket.uid, function(err, canMove) { if (err || !canMove) { return callback(err || new Error('[[error:no-privileges]]')); } diff --git a/src/topics/posts.js b/src/topics/posts.js index d943ca169e..b787c3956c 100644 --- a/src/topics/posts.js +++ b/src/topics/posts.js @@ -93,7 +93,7 @@ module.exports = function(Topics) { postData[i].downvoted = results.voteData[i].downvoted; postData[i].votes = postData[i].votes || 0; postData[i].display_moderator_tools = results.privileges[i].editable; - postData[i].display_move_tools = results.privileges[i].move; + postData[i].display_move_tools = results.privileges[i].move && postData[i].index !== 0; postData[i].selfPost = parseInt(uid, 10) === parseInt(postData[i].uid, 10); if(postData[i].deleted && !results.privileges[i].view_deleted) {