Skip to content

Commit

Permalink
Bug 1825961: set approval flags as the revision changer instead of au…
Browse files Browse the repository at this point in the history
…thor

Add a new positional argument to `set_attachment_approval_flags` that represents the
Bugzilla user making a change to the approval flag status. Use the Bugzilla user of
the revision changer instead of deriving the flag setter from the author of the
revision.
  • Loading branch information
cgsheeh committed Dec 11, 2023
1 parent 0bb2da9 commit e1ba93b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 8 additions & 1 deletion extensions/PhabBugz/lib/Feed.pm
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,14 @@ sub process_revision_change {
INFO('If uplift repository we may need to set approval flags');
if ($revision->repository && $revision->repository->is_uplift_repo()) {
INFO('Uplift repository detected. Setting attachment approval flags');
set_attachment_approval_flags($attachment, $revision);

# The Bugzilla user for the user who initiated the change should be used to
# set the approval flags. This ensures that users who create revisions will
# set the flag to `?`, and only approvals from `mozilla-next-drivers` group
# members will set the flag to `+` or `-`.
my $flag_setter = $changer->bugzilla_user;

set_attachment_approval_flags($attachment, $revision, $flag_setter);
}

$attachment->update($timestamp);
Expand Down
10 changes: 5 additions & 5 deletions extensions/PhabBugz/lib/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ our @EXPORT = qw(

# Set approval flags on Phabricator revision bug attachments.
sub set_attachment_approval_flags {
my ($attachment, $revision) = @_;
my $submitter = $revision->author->bugzilla_user;
my ($attachment, $revision, $flag_setter) = @_;
my $flag_setter = $revision->author->bugzilla_user;

my $revision_status_flag_map = {
'abandoned' => '-',
Expand Down Expand Up @@ -90,7 +90,7 @@ sub set_attachment_approval_flags {
# Set the flag to it's new status. If it already has that status,
# it will be a non-change. We also need to check to make sure the
# flag change is allowed.
if ($submitter->can_change_flag($flag->type, $flag->status, $status)) {
if ($flag_setter->can_change_flag($flag->type, $flag->status, $status)) {
INFO("Set existing `$approval_flag_name` flag to `$status`.");
push @old_flags, {id => $flag->id, status => $status};
}
Expand All @@ -108,10 +108,10 @@ sub set_attachment_approval_flags {
if (!@old_flags && $status ne 'X') {
my $approval_flag = Bugzilla::FlagType->new({name => $approval_flag_name});
if ($approval_flag) {
if ($submitter->can_change_flag($approval_flag, 'X', $status)) {
if ($flag_setter->can_change_flag($approval_flag, 'X', $status)) {
INFO("Creating new `$approval_flag_name` flag with status `$status`");
push @new_flags,
{setter => $submitter, status => $status, type_id => $approval_flag->id,};
{setter => $flag_setter, status => $status, type_id => $approval_flag->id,};
}
else {
INFO(
Expand Down

0 comments on commit e1ba93b

Please sign in to comment.