Skip to content

Commit

Permalink
Clean broken enter_votes code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
reosarevok committed Oct 28, 2024
1 parent 11b6eef commit 23962a0
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions lib/MusicBrainz/Server/Data/Vote.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 23962a0

Please sign in to comment.