From 28e9874ba91c598313a72c543d7780543c1bc641 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Fri, 19 Jun 2015 17:22:14 -0400 Subject: [PATCH] allow moderators/admins with 0 rep to still be able to flag a post --- src/socket.io/posts.js | 50 +++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index 93886291bb..272c762a06 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -471,30 +471,50 @@ SocketPosts.flag = function(socket, pid, callback) { async.waterfall([ function(next) { - user.getUserFields(socket.uid, ['username', 'reputation'], next); + posts.getPostFields(pid, ['pid', 'tid', 'uid', 'content', 'deleted'], function(err, postData) { + if (parseInt(postData.deleted, 10) === 1) { + return next(new Error('[[error:post-deleted]]')); + } + + post = postData; + next(); + }); + }, + function(next) { + topics.getTopicFields(post.tid, ['title', 'cid'], function(err, topicData) { + post.topic = topicData; + next(); + }); }, - function(userData, next) { - if (parseInt(userData.reputation, 10) < parseInt(meta.config['privileges:flag'] || 1, 10)) { + function(next) { + async.parallel({ + isAdmin: function(next) { + user.isAdministrator(socket.uid, next); + }, + isModerator: function(next) { + user.isModerator(socket.uid, post.topic.cid, next); + }, + userData: function(next) { + user.getUserFields(socket.uid, ['username', 'reputation'], next); + } + }, next); + }, + function(user, next) { + if (!user.isAdmin && !user.isModerator && parseInt(user.userData.reputation, 10) < parseInt(meta.config['privileges:flag'] || 1, 10)) { return next(new Error('[[error:not-enough-reputation-to-flag]]')); } - flaggingUser = userData; + + flaggingUser = user.userData; flaggingUser.uid = socket.uid; - posts.getPostFields(pid, ['pid', 'tid', 'uid', 'content', 'deleted'], next); + next(); }, - function(postData, next) { - if (parseInt(postData.deleted, 10) === 1) { - return next(new Error('[[error:post-deleted]]')); - } - post = postData; + function(next) { + console.log(post); posts.flag(post, socket.uid, next); }, function(next) { - topics.getTopicFields(post.tid, ['title', 'cid'], next); - }, - function(topic, next) { - post.topic = topic; - message = '[[notifications:user_flagged_post_in, ' + flaggingUser.username + ', ' + topic.title + ']]'; + message = '[[notifications:user_flagged_post_in, ' + flaggingUser.username + ', ' + post.topic.title + ']]'; posts.parsePost(post, next); }, function(post, next) {