diff options
author | Yorhel <git@yorhel.nl> | 2020-09-27 09:46:36 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2020-09-27 09:56:44 +0200 |
commit | a9f83aea65f6657eeffd07d41cda5bcea4b61cd1 (patch) | |
tree | aad0ea7d0b1ad848b7303ab4218abc8095452152 /lib | |
parent | fc1a584b3253892eb563eb204c9a510ef71d04de (diff) |
v2rw/TagEdit: Add vote wiping/merging and audit logging
Only feature missing from the new form is to recursively edit the tag
category, but that's rarely used and going to be a pain when we get edit
histories for tags, so let's not.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VNWeb/Tags/Edit.pm | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/VNWeb/Tags/Edit.pm b/lib/VNWeb/Tags/Edit.pm index 57e963c0..a337192c 100644 --- a/lib/VNWeb/Tags/Edit.pm +++ b/lib/VNWeb/Tags/Edit.pm @@ -18,7 +18,8 @@ my $FORM = { id => { id => 1 }, name => { _when => 'out' }, } }, - # TODO: delete/merge/wipevotes + wipevotes => { _when => 'in', anybool => 1 }, + merge => { _when => 'in', aoh => { id => { id => 1 } } }, addedby => { _when => 'out' }, can_mod => { _when => 'out', anybool => 1 }, @@ -112,6 +113,29 @@ elm_api TagEdit => $FORM_OUT, $FORM_IN, sub { tuwf->dbExeci('DELETE FROM tags_parents WHERE tag =', \$id); tuwf->dbExeci('INSERT INTO tags_parents (tag,parent) VALUES(', \$id, ',', \$_->{id}, ')') for $data->{parents}->@*; + auth->audit(undef, 'tag edit', "g$id") if $id; # Since we don't have edit histories for tags yet. + + if(auth->permTagmod && $data->{wipevotes}) { + my $num = tuwf->dbExeci('DELETE FROM tags_vn WHERE tag =', \$id); + auth->audit(undef, 'tag wipe', "Wiped $num votes on g$id"); + } + + if(auth->permTagmod && $data->{merge}->@*) { + my @merge = map $_->{id}, $data->{merge}->@*; + # Bugs: + # - Arbitrarily takes one vote if there are duplicates, should ideally try to merge them instead. + # - The 'ignore' flag will be inconsistent if set and the same VN has been voted on for multiple tags. + my $mov = tuwf->dbExeci(' + INSERT INTO tags_vn (tag,vid,uid,vote,spoiler,date,ignore,notes) + SELECT ', \$id, ',vid,uid,vote,spoiler,date,ignore,notes + FROM tags_vn WHERE tag IN', \@merge, ' + ON CONFLICT (tag,vid,uid) DO NOTHING' + ); + my $del = tuwf->dbExeci('DELETE FROM tags_vn tv WHERE tag IN', \@merge); + my $lst = join ',', map "g$_", @merge; + auth->audit(undef, 'tag merge', "Moved $mov/$del votes from $lst to g$id"); + } + elm_Redirect "/g$id"; }; |