summaryrefslogtreecommitdiff
path: root/lib/VNWeb/Discussions
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-03-21 09:59:25 +0100
committerYorhel <git@yorhel.nl>2020-03-21 10:01:33 +0100
commit45a4cc5efc3ca1f7cb174cfa30205e36a40d2420 (patch)
tree702565b1b54b9f82a51402008977f2de90b4b0fa /lib/VNWeb/Discussions
parent8837061d105aa44e6df294523b8295ea8f66daa6 (diff)
boardmod feature: Full deletion of threads/posts
Intended to prevent unecessary "deleted" posts, bumping of old threads and stray notifications when a spammer hits the boards. To make that easier, there should also be a "delete all posts by this user" function, but that'll be even trickier.
Diffstat (limited to 'lib/VNWeb/Discussions')
-rw-r--r--lib/VNWeb/Discussions/Edit.pm22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/VNWeb/Discussions/Edit.pm b/lib/VNWeb/Discussions/Edit.pm
index 15e5c198..a0627448 100644
--- a/lib/VNWeb/Discussions/Edit.pm
+++ b/lib/VNWeb/Discussions/Edit.pm
@@ -27,6 +27,7 @@ my $FORM = {
hidden => { anybool => 1 }, # When can_mod
private => { anybool => 1 }, # When can_private && (num = 1 || tid = undef)
nolastmod => { anybool => 1, _when => 'in' }, # When can_mod
+ delete => { anybool => 1 }, # When can_mod
msg => { maxlength => 32768 },
};
@@ -49,6 +50,26 @@ elm_api DiscussionsEdit => $FORM_OUT, $FORM_IN, sub {
return tuwf->resNotFound if $tid && !$t->{id};
return elm_Unauth if !can_edit t => $t;
+ if($data->{delete} && auth->permBoardmod) {
+ warn "AUDIT: Delete t$tid.$num\n";
+ # BUG: Doesn't cause stats_cache to be updated. But who cares about that.
+ if($num == 1) {
+ # (This could be a single query if there were proper ON DELETE CASCADE in the DB, though that's hard for notifications...)
+ tuwf->dbExeci('DELETE FROM threads_posts WHERE tid =', \$tid);
+ tuwf->dbExeci('DELETE FROM threads_boards WHERE tid =', \$tid);
+ tuwf->dbExeci('DELETE FROM threads WHERE id =', \$tid);
+ tuwf->dbExeci(q{DELETE FROM notifications WHERE ltype = 't' AND iid =}, \$tid);
+ return elm_Redirect '/t';
+ } else {
+ tuwf->dbExeci('DELETE FROM threads_posts WHERE tid =', \$tid, 'AND num =', \$num);
+ tuwf->dbExeci('UPDATE threads_posts SET num = num - 1 WHERE tid =', \$tid, 'AND num >', \$num);
+ tuwf->dbExeci('UPDATE threads SET count = count - 1 WHERE id =', \$tid);
+ tuwf->dbExeci(q{DELETE FROM notifications WHERE ltype = 't' AND iid =}, \$tid, 'AND subid =', \$num);
+ tuwf->dbExeci(q{UPDATE notifications SET subid = subid - 1 WHERE ltype = 't' AND iid =}, \$tid, 'AND subid >', \$num);
+ return elm_Redirect "/t$tid";
+ }
+ }
+
my $pollchanged = !$data->{tid} && $data->{poll};
if($num == 1) {
die "Invalid title" if !length $data->{title};
@@ -152,6 +173,7 @@ TUWF::get qr{(?:/t/(?<board>$BOARD_RE)/new|/$RE{postid}/edit)}, sub {
$t->{num} //= undef;
$t->{private} //= 0;
$t->{locked} //= 0;
+ $t->{delete} = 0;
framework_ title => $tid ? 'Edit post' : 'Create new thread', sub {
elm_ 'Discussions.Edit' => $FORM_OUT, $t;