preserve multiple posts to show in ban, dont have multiple bans on same IP from a single action

merge-requests/208/head
fatchan 5 years ago
parent 17f175d977
commit eaf39d3032
  1. 24
      models/forms/banposter.js
  2. 3
      views/includes/captcha.pug
  3. 7
      views/mixins/ban.pug
  4. 3
      views/pages/ban.pug

@ -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

@ -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

@ -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}

@ -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')

Loading…
Cancel
Save