From cc2ab12f299b0fa8ddc0833e590e07e00b455602 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sun, 1 Feb 2015 21:38:10 -0500 Subject: [PATCH] removed bans from downvotes and flags cleanup thread tools emits --- public/src/client/categoryTools.js | 9 +--- public/src/client/topic/events.js | 2 +- src/socket.io/posts.js | 51 +------------------ src/socket.io/topics.js | 73 +++++++++++++-------------- src/threadTools.js | 79 +++++++++++------------------- src/views/admin/settings/user.tpl | 20 -------- 6 files changed, 71 insertions(+), 163 deletions(-) diff --git a/public/src/client/categoryTools.js b/public/src/client/categoryTools.js index b94954626a..0e9bae608b 100644 --- a/public/src/client/categoryTools.js +++ b/public/src/client/categoryTools.js @@ -199,13 +199,8 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect'], function(move getTopicEl(data.tid).remove(); } - function onTopicPurged(tids) { - if (!tids) { - return; - } - for(var i=0; i= parseInt(meta.config['autoban:downvote:threshold'], 10)) { - return callback(err); - } - - var adminUser = require('./admin/user'); - adminUser.banUser(uid, function(err) { - if (err) { - return callback(err); - } - events.log({ - type: 'banned', - reason: 'low-reputation', - uid: socket.uid, - ip: socket.ip, - targetUid: data.uid, - reputation: userData.reputation - }); - callback(); - }); - }); - } - } - - favouriteCommand(socket, 'downvote', 'voted', '', data, function(err) { - if (err) { - return callback(err); - } - banUserForLowReputation(data.uid, callback); - }); + favouriteCommand(socket, 'downvote', 'voted', '', data, callback); }; SocketPosts.unvote = function(socket, data, callback) { @@ -480,23 +449,7 @@ SocketPosts.flag = function(socket, pid, callback) { return next(); } - db.setAdd('uid:' + post.uid + ':flagged_by', socket.uid, function(err) { - if (err) { - return next(err); - } - db.setCount('uid:' + post.uid + ':flagged_by', function(err, count) { - if (err) { - return next(err); - } - - if (count >= (meta.config.flagsForBan || 3) && parseInt(meta.config.flagsForBan, 10) !== 0) { - var adminUser = require('./admin/user'); - adminUser.banUser(post.uid, next); - return; - } - next(); - }); - }); + db.setAdd('uid:' + post.uid + ':flagged_by', socket.uid, next); } ], callback); }; diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js index 687a7361a5..5cc6cb3bad 100644 --- a/src/socket.io/topics.js +++ b/src/socket.io/topics.js @@ -21,6 +21,7 @@ var nconf = require('nconf'), SocketTopics = {}; + SocketTopics.post = function(socket, data, callback) { if(!data) { return callback(new Error('[[error:invalid-data]]')); @@ -204,44 +205,34 @@ SocketTopics.markAsUnreadForAll = function(socket, tids, callback) { }; SocketTopics.delete = function(socket, data, callback) { - doTopicAction('delete', socket, data, callback); + doTopicAction('delete', 'event:topic_deleted', socket, data, callback); }; SocketTopics.restore = function(socket, data, callback) { - doTopicAction('restore', socket, data, callback); + doTopicAction('restore', 'event:topic_restored', socket, data, callback); }; SocketTopics.purge = function(socket, data, callback) { - doTopicAction('purge', socket, data, function(err) { - if (err) { - return callback(err); - } - - websockets.in('category_' + data.cid).emit('event:topic_purged', data.tids); - async.each(data.tids, function(tid, next) { - websockets.in('topic_' + tid).emit('event:topic_purged', tid); - next(); - }, callback); - }); + doTopicAction('purge', 'event:topic_purged', socket, data, callback); }; SocketTopics.lock = function(socket, data, callback) { - doTopicAction('lock', socket, data, callback); + doTopicAction('lock', 'event:topic_locked', socket, data, callback); }; SocketTopics.unlock = function(socket, data, callback) { - doTopicAction('unlock', socket, data, callback); + doTopicAction('unlock', 'event:topic_unlocked', socket, data, callback); }; SocketTopics.pin = function(socket, data, callback) { - doTopicAction('pin', socket, data, callback); + doTopicAction('pin', 'event:topic_pinned', socket, data, callback); }; SocketTopics.unpin = function(socket, data, callback) { - doTopicAction('unpin', socket, data, callback); + doTopicAction('unpin', 'event:topic_unpinned', socket, data, callback); }; -function doTopicAction(action, socket, data, callback) { +function doTopicAction(action, event, socket, data, callback) { if (!socket.uid) { return; } @@ -251,35 +242,45 @@ function doTopicAction(action, socket, data, callback) { async.each(data.tids, function(tid, next) { privileges.topics.canEdit(tid, socket.uid, function(err, canEdit) { - if(err) { + if (err) { return next(err); } - if(!canEdit) { + if (!canEdit) { return next(new Error('[[error:no-privileges]]')); } - if(typeof threadTools[action] === 'function') { - threadTools[action](tid, socket.uid, function(err) { - if (err) { - return next(err); - } - - if (action === 'delete' || action === 'restore' || action === 'purge') { - events.log({ - type: 'topic-' + action, - uid: socket.uid, - ip: socket.ip, - tid: tid - }); - } - next(); - }); + if (typeof threadTools[action] !== 'function') { + return next(); } + + threadTools[action](tid, socket.uid, function(err, data) { + if (err) { + return next(err); + } + + emitToTopicAndCategory(event, data); + + if (action === 'delete' || action === 'restore' || action === 'purge') { + events.log({ + type: 'topic-' + action, + uid: socket.uid, + ip: socket.ip, + tid: tid + }); + } + + next(); + }); }); }, callback); } +function emitToTopicAndCategory(event, data) { + websockets.in('topic_' + data.tid).emit(event, data); + websockets.in('category_' + data.cid).emit(event, data); +} + SocketTopics.createTopicFromPosts = function(socket, data, callback) { if(!socket.uid) { return callback(new Error('[[error:not-logged-in]]')); diff --git a/src/threadTools.js b/src/threadTools.js index 077abc54e6..1a62564434 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -11,7 +11,6 @@ var winston = require('winston'), notifications = require('./notifications'), posts = require('./posts'), meta = require('./meta'), - websockets = require('./socket.io'), events = require('./events'), plugins = require('./plugins'), batch = require('./batch'); @@ -39,12 +38,6 @@ var winston = require('winston'), } topics[isDelete ? 'delete' : 'restore'](tid, function(err) { - function emitTo(room) { - websockets.in(room).emit(isDelete ? 'event:topic_deleted' : 'event:topic_restored', { - tid: tid, - isDelete: isDelete - }); - } if (err) { return callback(err); } @@ -56,17 +49,20 @@ var winston = require('winston'), plugins.fireHook('action:topic.restore', topicData); } - emitTo('topic_' + tid); - emitTo('category_' + topicData.cid); + var data = { + tid: tid, + cid: topicData.cid, + isDelete: isDelete, + uid: uid + }; - callback(null, { - tid: tid - }); + callback(null, data); }); }); } ThreadTools.purge = function(tid, uid, callback) { + var topic; async.waterfall([ function(next) { topics.exists(tid, next); @@ -80,13 +76,17 @@ var winston = require('winston'), }, {alwaysStartAt: 0}, next); }, function(next) { - topics.getTopicField(tid, 'mainPid', next); + topics.getTopicFields(tid, ['mainPid', 'cid'], next); }, - function(mainPid, next) { - posts.purge(mainPid, next); + function(_topic, next) { + topic = _topic; + posts.purge(topic.mainPid, next); }, function(next) { topics.purge(tid, next); + }, + function(next) { + next(null, {tid: tid, cid: topic.cid, uid: uid}); } ], callback); }; @@ -100,35 +100,24 @@ var winston = require('winston'), }; function toggleLock(tid, uid, lock, callback) { + callback = callback || function() {}; topics.getTopicField(tid, 'cid', function(err, cid) { - function emitTo(room) { - websockets.in(room).emit(lock ? 'event:topic_locked' : 'event:topic_unlocked', { - tid: tid, - isLocked: lock - }); - } - - if (err && typeof callback === 'function') { + if (err) { return callback(err); } topics.setTopicField(tid, 'locked', lock ? 1 : 0); - plugins.fireHook('action:topic.lock', { + var data = { tid: tid, isLocked: lock, - uid: uid - }); + uid: uid, + cid: cid + }; - emitTo('topic_' + tid); - emitTo('category_' + cid); + plugins.fireHook('action:topic.lock', data); - if (typeof callback === 'function') { - callback(null, { - tid: tid, - isLocked: lock - }); - } + callback(null, data); }); } @@ -142,13 +131,6 @@ var winston = require('winston'), function togglePin(tid, uid, pin, callback) { topics.getTopicFields(tid, ['cid', 'lastposttime'], function(err, topicData) { - function emitTo(room) { - websockets.in(room).emit(pin ? 'event:topic_pinned' : 'event:topic_unpinned', { - tid: tid, - isPinned: pin - }); - } - if (err) { return callback(err); } @@ -156,19 +138,16 @@ var winston = require('winston'), topics.setTopicField(tid, 'pinned', pin ? 1 : 0); db.sortedSetAdd('cid:' + topicData.cid + ':tids', pin ? Math.pow(2, 53) : topicData.lastposttime, tid); - plugins.fireHook('action:topic.pin', { + var data = { tid: tid, isPinned: pin, - uid: uid - }); + uid: uid, + cid: topicData.cid + }; - emitTo('topic_' + tid); - emitTo('category_' + topicData.cid); + plugins.fireHook('action:topic.pin', data); - callback(null, { - tid: tid, - isPinned: pin - }); + callback(null, data); }); } diff --git a/src/views/admin/settings/user.tpl b/src/views/admin/settings/user.tpl index 5f1bfd11f9..b44884ae81 100644 --- a/src/views/admin/settings/user.tpl +++ b/src/views/admin/settings/user.tpl @@ -97,26 +97,6 @@ -
-
User Bans
-
-
-
- - -
-
-
- -
- - -
-
-
-
User Registration