From 23962a0d26a5d9629818272e2f5a2eff256aab33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Tamargo?= Date: Fri, 25 Oct 2024 11:30:57 +0200 Subject: [PATCH] Clean broken enter_votes code We seemingly were never hitting this, because as soon as we did during my testing, it died horribly. Unsurprisingly, since it was trying to access $_ outside the any call. Unsure how useful this is given we never hit it, but for now, this at least actually should do what the old code tried to. --- lib/MusicBrainz/Server/Data/Vote.pm | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/MusicBrainz/Server/Data/Vote.pm b/lib/MusicBrainz/Server/Data/Vote.pm index 0018f73bc28..a4a806d6b8d 100644 --- a/lib/MusicBrainz/Server/Data/Vote.pm +++ b/lib/MusicBrainz/Server/Data/Vote.pm @@ -2,7 +2,7 @@ package MusicBrainz::Server::Data::Vote; use Moose; use namespace::autoclean; -use List::AllUtils qw( any sum ); +use List::AllUtils qw( sum ); use Carp qw( confess ); use MusicBrainz::Server::Data::Utils qw( map_query placeholders ); use MusicBrainz::Server::Email; @@ -69,17 +69,20 @@ sub enter_votes my @edit_ids = map { $_->{edit_id} } @votes; my $edits = $self->c->model('Edit')->get_by_ids(@edit_ids); @votes = grep { defined $edits->{ $_->{edit_id} } } @votes; - if (any { $_->{vote} == $VOTE_APPROVE && !$edits->{ $_->{edit_id} }->editor_may_approve($editor) } @votes) { - # not sufficient to filter the vote because the actual approval is happening elsewhere - confess 'Unauthorized editor ' . $editor->id . ' tried to approve edit #' . $_->{edit_id}; - } - if (any { $_->{vote} == $VOTE_ADMIN_APPROVE && !$editor->is_account_admin } @votes) { - # not sufficient to filter the vote because the actual approval is happening elsewhere - confess 'Unauthorized editor ' . $editor->id . ' tried to admin-approve edit #' . $_->{edit_id}; - } - if (any { $_->{vote} == $VOTE_ADMIN_REJECT && !$editor->is_account_admin } @votes) { - # not sufficient to filter the vote because the actual rejection is happening elsewhere - confess 'Unauthorized editor ' . $editor->id . ' tried to admin-reject edit #' . $_->{edit_id}; + for my $vote (@votes) { + my $edit_id = $vote->{edit_id}; + if ($vote->{vote} == $VOTE_APPROVE && !$edits->{ $edit_id }->editor_may_approve($editor)) { + # not sufficient to filter the vote because the actual approval is happening elsewhere + confess 'Unauthorized editor ' . $editor->id . ' tried to approve edit #' . $edit_id; + } + if ($vote->{vote} == $VOTE_ADMIN_APPROVE && !$editor->is_account_admin) { + # not sufficient to filter the vote because the actual approval is happening elsewhere + confess 'Unauthorized editor ' . $editor->id . ' tried to admin-approve edit #' . $edit_id; + } + if ($vote->{vote} == $VOTE_ADMIN_REJECT && !$editor->is_account_admin) { + # not sufficient to filter the vote because the actual rejection is happening elsewhere + confess 'Unauthorized editor ' . $editor->id . ' tried to admin-reject edit #' . $edit_id; + } } unless ($opts{override_privs}) { @votes = grep {