From 38726243feea12afdd4a85c468bd00efb502ae7a Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 20 Mar 2015 16:13:34 -0400 Subject: [PATCH] closes #2879 --- public/src/client/topic/postTools.js | 20 ++++++++++++-------- src/topics/create.js | 22 +++++++--------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/public/src/client/topic/postTools.js b/public/src/client/topic/postTools.js index a54f3f894f..4e561b036c 100644 --- a/public/src/client/topic/postTools.js +++ b/public/src/client/topic/postTools.js @@ -72,16 +72,26 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com } function addPostHandlers(tid, threadState) { + function canPost() { + return !threadState.locked || app.user.isAdmin; + } + var postContainer = components.get('topic'); postContainer.on('click', '[component="post/quote"]', function() { - if (!threadState.locked) { + if (canPost()) { onQuoteClicked($(this), tid, topicName); } }); postContainer.on('click', '[component="post/reply"]', function() { - if (!threadState.locked) { + if (canPost()) { + onReplyClicked($(this), tid, topicName); + } + }); + + components.get('topic/reply').on('click', function() { + if (canPost()) { onReplyClicked($(this), tid, topicName); } }); @@ -125,12 +135,6 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com postContainer.on('click', '[component="user/chat"]', function(e) { openChat($(this)); }); - - components.get('topic/reply').on('click', function() { - if (!threadState.locked) { - onReplyClicked($(this), tid, topicName); - } - }); } function onReplyClicked(button, tid, topicName) { diff --git a/src/topics/create.js b/src/topics/create.js index 36a73948d7..5988f637e2 100644 --- a/src/topics/create.js +++ b/src/topics/create.js @@ -93,7 +93,6 @@ module.exports = function(Topics) { Topics.post = function(data, callback) { var uid = data.uid, - handle = data.handle, title = data.title, content = data.content, cid = data.cid; @@ -135,7 +134,7 @@ module.exports = function(Topics) { Topics.create({uid: uid, title: title, cid: cid, thumb: data.thumb, tags: data.tags}, next); }, function(tid, next) { - Topics.reply({uid:uid, tid:tid, handle: handle, content:content, req: data.req}, next); + Topics.reply({uid:uid, tid:tid, handle: data.handle, content:content, req: data.req}, next); }, function(postData, next) { async.parallel({ @@ -185,30 +184,23 @@ module.exports = function(Topics) { Topics.reply = function(data, callback) { var tid = data.tid, uid = data.uid, - toPid = data.toPid, - handle = data.handle, content = data.content, postData; async.waterfall([ function(next) { async.parallel({ - exists: function(next) { - Topics.exists(tid, next); - }, - locked: function(next) { - Topics.isLocked(tid, next); - }, - canReply: function(next) { - privileges.topics.can('topics:reply', tid, uid, next); - } + exists: async.apply(Topics.exists, tid), + locked: async.apply(Topics.isLocked, tid), + canReply: async.apply(privileges.topics.can, 'topics:reply', tid, uid), + isAdmin: async.apply(user.isAdministrator, uid) }, next); }, function(results, next) { if (!results.exists) { return next(new Error('[[error:no-topic]]')); } - if (results.locked) { + if (results.locked && !results.isAdmin) { return next(new Error('[[error:topic-locked]]')); } if (!results.canReply) { @@ -229,7 +221,7 @@ module.exports = function(Topics) { checkContentLength(content, next); }, function(next) { - posts.create({uid: uid, tid: tid, handle: handle, content: content, toPid: toPid, ip: data.req ? data.req.ip : null}, next); + posts.create({uid: uid, tid: tid, handle: data.handle, content: content, toPid: data.toPid, ip: data.req ? data.req.ip : null}, next); }, function(data, next) { postData = data;