Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1825961: set approval flags as the revision changer instead of author #2147

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 4 additions & 5 deletions extensions/PhabBugz/lib/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ 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 $revision_status_flag_map = {
'abandoned' => '-',
Expand Down Expand Up @@ -90,7 +89,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 +107,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