Skip to content

Node.js based forum software built for the modern web

removed bans from downvotes and flags

barisusaklicc2ab12f299b
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<tids.length; ++i) {
- getTopicEl(tids[i]).remove();
- }
+ function onTopicPurged(data) {
+ getTopicEl(data.tid).remove();
}
return CategoryTools;
diff --git a/public/src/client/topic/events.js b/public/src/client/topic/events.js
index 90f54ec064..24961295b9 100644
--- a/public/src/client/topic/events.js
+++ b/public/src/client/topic/events.js
@@ -85,7 +85,7 @@ define('forum/topic/events', [
threadTools.setDeleteState(data);
}
- function onTopicPurged(tid) {
+ function onTopicPurged(data) {
ajaxify.go('category/' + ajaxify.variables.get('category_id'));
}
diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js
index 590b10da0f..d9f673067c 100644
--- a/src/socket.io/posts.js
+++ b/src/socket.io/posts.js
@@ -139,38 +139,7 @@ SocketPosts.upvote = function(socket, data, callback) {
};
SocketPosts.downvote = function(socket, data, callback) {
- function banUserForLowReputation(uid, callback) {
- if (parseInt(meta.config['autoban:downvote'], 10) === 1) {
- user.getUserFields(uid, ['reputation', 'banned'], function(err, userData) {
- if (err || parseInt(userData.banned, 10) === 1 || parseInt(userData.reputation) >= 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 @@
</div>
</div>
-<div class="panel panel-default">
- <div class="panel-heading">User Bans</div>
- <div class="panel-body">
- <form>
- <div class="form-group">
- <label>Number of flags to ban user</label>
- <input type="text" class="form-control" value="3" placeholder="" data-field="flagsForBan" />
- </div>
- <hr />
- <div class="checkbox">
- <label>
- <input type="checkbox" data-field="autoban:downvote"> <strong>Enable automatic banning for reaching below a reputation threshold</strong>
- </label>
- </div>
- <label>Reputation threshold before receiving an automatic ban</label>
- <input type="text" class="form-control" value="" placeholder="-50" data-field="autoban:downvote:threshold" />
- </form>
- </div>
-</div>
-
<div class="panel panel-default">
<div class="panel-heading">User Registration</div>
<div class="panel-body">