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 25, 2024
1 parent 7a19e7c commit 659f89b
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lib/MusicBrainz/Server/Data/Vote.pm
Original file line number Diff line number Diff line change
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 659f89b

Please sign in to comment.