From eaf39d3032d72a327fd5d6f09879d3dde4629e2b Mon Sep 17 00:00:00 2001 From: fatchan Date: Sat, 31 Aug 2019 18:41:11 +0000 Subject: [PATCH] preserve multiple posts to show in ban, dont have multiple bans on same IP from a single action --- models/forms/banposter.js | 24 ++++++++++++++++-------- views/includes/captcha.pug | 3 +-- views/mixins/ban.pug | 7 ++++--- views/pages/ban.pug | 3 +-- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/models/forms/banposter.js b/models/forms/banposter.js index 3592b9fe..f01a799d 100644 --- a/models/forms/banposter.js +++ b/models/forms/banposter.js @@ -13,19 +13,27 @@ module.exports = async (req, res, next) => { if (req.body.ban || req.body.global_ban) { const banBoard = req.body.global_ban ? null : req.params.board; - res.locals.posts.forEach(post => { + const ipPosts = res.locals.posts.reduce((acc, post) => { + if (!acc[post.ip]) { + acc[post.ip] = []; + } + acc[post.ip].push(post); + return acc; + }, {}); + for (let ip in ipPosts) { + const thisIpPosts = ipPosts[ip]; bans.push({ - 'ip': post.ip, + ip, 'reason': banReason, 'board': banBoard, - 'post': req.body.preserve_post ? post : null, + 'posts': req.body.preserve_post ? thisIpPosts : null, 'issuer': req.session.user.username, 'date': banDate, 'expireAt': banExpiry, allowAppeal, 'appeal': null }); - }); + } } if (req.body.report_ban || req.body.global_report_ban){ const banBoard = req.body.global_report_ban ? null : req.params.board; @@ -47,19 +55,19 @@ module.exports = async (req, res, next) => { }); ips = ips.concat(matches); } - ips.forEach(ip => { + [...new Set(ips)].forEach(ip => { bans.push({ 'ip': ip, 'reason': banReason, 'board': banBoard, - 'post': null, + 'posts': null, 'issuer': req.session.user.username, 'date': banDate, 'expireAt': banExpiry, allowAppeal, 'appeal': null }); - }) + }); }); } @@ -69,7 +77,7 @@ module.exports = async (req, res, next) => { message: `Added ${numBans} bans`, }; - if ((req.body.ban || req.body.global_ban ) && ban_reason) { + if ((req.body.ban || req.body.global_ban ) && req.body.ban_reason) { query['action'] = '$set'; query['query'] = { 'banmessage': req.body.ban_reason diff --git a/views/includes/captcha.pug b/views/includes/captcha.pug index a5e742fc..4cfdf2de 100644 --- a/views/includes/captcha.pug +++ b/views/includes/captcha.pug @@ -1,4 +1,3 @@ iframe.captcha(src='/captcha.html' 'width=200' height='80' scrolling='no') input(type='text' name='captcha' autocomplete='off' placeholder='captcha text' pattern=".{6}" required title='6 characters') - - +//todo: make this an iframe in noscript tag, and use javascript to lazy load captcha only when user has clicked in the box, for users with javascript enabled diff --git a/views/mixins/ban.pug b/views/mixins/ban.pug index a3f8ee5e..46361e1b 100644 --- a/views/mixins/ban.pug +++ b/views/mixins/ban.pug @@ -15,10 +15,11 @@ mixin ban(ban, banpage) div Issued against: ...#{ban.ip.slice(-10)} div Banned: #{ban.date.toLocaleString()} div Expires: #{ban.expireAt.toLocaleString()} - if ban.post - span Banned for the following post: + if ban.posts && ban.posts.length > 0 + span Banned for the following post#{ban.posts.length > 1 ? 's' : ''}: section.thread - +post(ban.post, false, false, false, true) + each p in ban.posts + +post(p, false, false, false, true) if ban.appeal != null div Submitted appeal: textarea(disabled='true') #{ban.appeal} diff --git a/views/pages/ban.pug b/views/pages/ban.pug index 9ecd41b4..b76e9f3a 100644 --- a/views/pages/ban.pug +++ b/views/pages/ban.pug @@ -28,6 +28,5 @@ block content section.row .label Captcha span.col - iframe.captcha(src='/captcha.html' width=200 height=110 scrolling='no') - input(type='text', name='captcha', autocomplete='off' placeholder='captcha text' pattern=".{6}" required title='6 characters') + include ../includes/captcha.pug input(type='submit', value='submit')