From 2185d8eb9997746d3659bc440eece1627d65c15d Mon Sep 17 00:00:00 2001 From: Ben Lubar Date: Wed, 2 Nov 2016 11:59:01 -0500 Subject: [PATCH] Ban UI fixes (#5169) - Permanent bans assigned by global moderators no longer expire immediately (does not apply retroactively) - Bans with no reason given no longer have "undefined" as their reason (applies retroactively) - 0 is now a selectable value for "ban duration, select 0 for permanent" --- public/src/client/account/header.js | 2 +- src/user/info.js | 4 +-- src/views/admin/partials/temporary-ban.tpl | 4 +-- test/user.js | 32 ++++++++++++++++++++-- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/public/src/client/account/header.js b/public/src/client/account/header.js index d29b58c05b..1b16aec4b1 100644 --- a/public/src/client/account/header.js +++ b/public/src/client/account/header.js @@ -120,7 +120,7 @@ define('forum/account/header', [ data[cur.name] = cur.value; return data; }, {}); - var until = formData.length ? (Date.now() + formData.length * 1000 * 60 * 60 * (parseInt(formData.unit, 10) ? 24 : 1)) : 0; + var until = parseInt(formData.length, 10) ? (Date.now() + formData.length * 1000 * 60 * 60 * (parseInt(formData.unit, 10) ? 24 : 1)) : 0; socket.emit('user.banUsers', { uids: [ajaxify.data.theirid], until: until, reason: formData.reason || '' }, function (err) { if (err) { diff --git a/src/user/info.js b/src/user/info.js index 46b4024e32..1ed9cdef14 100644 --- a/src/user/info.js +++ b/src/user/info.js @@ -123,7 +123,7 @@ module.exports = function (User) { banObj.timestamp = parseInt(banObj.score, 10); banObj.timestampReadable = new Date(banObj.score).toString(); banObj.timestampISO = new Date(banObj.score).toISOString(); - banObj.reason = validator.escape(String(reasons[banObj.score])) || '[[user:info.banned-no-reason]]'; + banObj.reason = validator.escape(String(reasons[banObj.score] || '')) || '[[user:info.banned-no-reason]]'; delete banObj.value; delete banObj.score; @@ -132,4 +132,4 @@ module.exports = function (User) { return banObj; }); } -}; \ No newline at end of file +}; diff --git a/src/views/admin/partials/temporary-ban.tpl b/src/views/admin/partials/temporary-ban.tpl index da8d02c79f..4527e4a739 100644 --- a/src/views/admin/partials/temporary-ban.tpl +++ b/src/views/admin/partials/temporary-ban.tpl @@ -3,7 +3,7 @@
- +
@@ -29,4 +29,4 @@

- \ No newline at end of file + diff --git a/test/user.js b/test/user.js index 7ac9fe8b08..bb834a0cb3 100644 --- a/test/user.js +++ b/test/user.js @@ -1,6 +1,6 @@ 'use strict'; -var assert = require('assert'); +var assert = require('assert'); var async = require('async'); var db = require('./mocks/databasemock'); @@ -430,7 +430,35 @@ describe('User', function () { }); }); + describe('.getModerationHistory', function () { + it('should return the correct ban reason', function (done) { + async.series([ + function (next) { + User.ban(testUid, 0, '', function (err) { + assert.ifError(err); + next(err); + }); + }, + function (next) { + User.getModerationHistory(testUid, function (err, data) { + assert.ifError(err); + assert.equal(data.bans.length, 1, 'one ban'); + assert.equal(data.bans[0].reason, '[[user:info.banned-no-reason]]', 'no ban reason'); + + next(err); + }); + } + ], function (err) { + assert.ifError(err); + User.unban(testUid, function (err) { + assert.ifError(err); + done(); + }); + }); + }); + }); + after(function (done) { db.emptydb(done); }); -}); \ No newline at end of file +});