diff options
author | Yorhel <git@yorhel.nl> | 2021-08-09 11:18:35 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2021-08-09 11:18:37 +0200 |
commit | e20a25f8070c255d8daea49151378d0aca3523ff (patch) | |
tree | a6eb3ac8ac6096f6a1b3fb4701d932c3cf37b634 /lib/VNWeb | |
parent | 02448a7dd976344d29f698b84027686a6e64c673 (diff) |
VNLengthVote: Add unique vote id to handle editing deleted user's votes
I forgot that my wonderful UNIQUE index trick on (vid,uid) just doesn't
work if you want to have the ability to edit individual vote entries
after someone's account has been deleted.
And I took this opportunity to recreate the vn_length_votes table with a
saner layout.
Diffstat (limited to 'lib/VNWeb')
-rw-r--r-- | lib/VNWeb/VN/Length.pm | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/VNWeb/VN/Length.pm b/lib/VNWeb/VN/Length.pm index e64a620a..53e147f4 100644 --- a/lib/VNWeb/VN/Length.pm +++ b/lib/VNWeb/VN/Length.pm @@ -59,7 +59,7 @@ sub listing_ { }; td_ class => 'tc6', sub { lit_ bb_format $_->{notes}, inline => 1 }; td_ class => 'tc7', sub { - select_ name => "$_->{vid}-$_->{uid}", sub { + select_ name => "lv$_->{id}", sub { option_ value => '', '--'; option_ value => 's0', 'slow'; option_ value => 's1', 'normal'; @@ -123,7 +123,7 @@ TUWF::get qr{/(?:(?<thing>$RE{vid}|$RE{uid})/)?lengthvotes}, sub { my $count = tuwf->dbVali('SELECT COUNT(*) FROM vn_length_votes l WHERE', $where); my $lst = tuwf->dbPagei({results => $opt->{s}->results, page => $opt->{p}}, - 'SELECT l.uid, l.vid, l.length, l.speed, l.notes, l.rid::text[] AS rel, ' + 'SELECT l.id, l.uid, l.vid, l.length, l.speed, l.notes, l.rid::text[] AS rel, ' , sql_totime('l.date'), 'AS date, l.ignore OR u.perm_lengthvote IS NOT DISTINCT FROM false AS ignore', $mode ne 'u' ? (', ', sql_user()) : (), $mode ne 'v' ? ', v.title, v.original' : (), ' @@ -153,18 +153,22 @@ TUWF::post '/lengthvotes-edit', sub { my @actions; for my $k (tuwf->reqPosts) { - next if $k !~ /^(?<vid>$RE{vid})-(?<uid>$RE{uid})$/; - my $where = { vid => $+{vid}, uid => $+{uid} }; + next if $k !~ /^lv$RE{num}$/; + my $id = $+{num}; my $act = tuwf->reqPost($k); next if !$act; - push @actions, "$k-$act"; - tuwf->dbExeci('UPDATE vn_length_votes SET ignore = true WHERE', $where) if $act eq 'ign'; - tuwf->dbExeci('UPDATE vn_length_votes SET ignore = false WHERE', $where) if $act eq 'noign'; - tuwf->dbExeci('UPDATE vn_length_votes SET speed = 0 WHERE', $where) if $act eq 's0'; - tuwf->dbExeci('UPDATE vn_length_votes SET speed = 1 WHERE', $where) if $act eq 's1'; - tuwf->dbExeci('UPDATE vn_length_votes SET speed =', \2, 'WHERE', $where) if $act eq 's2'; + my $r = tuwf->dbRowi(' + UPDATE vn_length_votes SET', + $act eq 'ign' ? 'ignore = true' : + $act eq 'noign' ? 'ignore = false' : + $act eq 's0' ? 'speed = 0' : + $act eq 's1' ? 'speed = 1' : + $act eq 's2' ? ('speed =', \2) : die, + 'WHERE id =', \$id, 'RETURNING vid, uid' + ); + push @actions, "$r->{vid}-".($r->{uid}//'anon')."-$act"; } - auth->audit(undef, 'lengthvote-edit', join ', ', sort @actions) if @actions; + auth->audit(undef, 'lengthvote edit', join ', ', sort @actions) if @actions; tuwf->resRedirect(tuwf->reqPost('url'), 'post'); }; |