From f37c408a8cee4bc10dbcac7b5079f6d66b863c65 Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Wed, 25 Nov 2026 15:39:38 -0500 Subject: [PATCH] Bug 2097831 - Change the hackbot_needinfo_allowed group name to hackbot-users and make it a bug group with no products so it syncs to Phabricator --- extensions/Needinfo/Extension.pm | 36 ++++++++++++++++--- .../Needinfo/t/bmo/block-needinfo-hackbot.t | 28 ++++++++++++--- .../hook/global/user-error-errors.html.tmpl | 2 +- 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/extensions/Needinfo/Extension.pm b/extensions/Needinfo/Extension.pm index efd69fbdb9..68c2bfb1aa 100644 --- a/extensions/Needinfo/Extension.pm +++ b/extensions/Needinfo/Extension.pm @@ -30,7 +30,11 @@ use constant MAX_MENTIONS => 10; # block_needinfo values that only accept needinfo requests from members of a # group (directly or through a group nested in it), keyed to that group. use constant NEEDINFO_ALLOWED_GROUPS => - {editbugs => 'editbugs', hackbot_needinfo => 'hackbot_needinfo_allowed'}; + {editbugs => 'editbugs', hackbot_needinfo => 'hackbot-users'}; + +# Name the hackbot group was first created under, renamed in place by +# _setup_hackbot_users_group so its members and nested groups carry over. +use constant OLD_HACKBOT_GROUP => 'hackbot_needinfo_allowed'; BEGIN { *Bugzilla::User::needinfo_blocked = \&_user_needinfo_blocked; @@ -83,25 +87,49 @@ sub install_update_db { # Users who set block_needinfo to 'hackbot_needinfo' only accept needinfo # requests from members of this group. Admins add groups (such as # mozilla-employee-confidential) to it rather than individual users. +# It is a bug group in no products: PhabBugz syncs every active bug group to +# a Phabricator project, so Hackbot can see the same membership there, while +# no product offers it for restricting bugs. # Called from install_before_final_checks rather than install_update_db: # other extensions (e.g. SecureMail) add group columns in their own # install_update_db, and Group->create needs those on a fresh database. -sub _create_hackbot_needinfo_group { +sub _setup_hackbot_users_group { my $name = NEEDINFO_ALLOWED_GROUPS->{hackbot_needinfo}; return if Bugzilla::Group->new({name => $name}); + if (my $group = Bugzilla::Group->new({name => OLD_HACKBOT_GROUP})) { + print 'Renaming ' . OLD_HACKBOT_GROUP . " group to $name ...\n"; + _migrate_old_hackbot_group($group, $name); + return; + } + print "Creating $name group ...\n"; Bugzilla::Group->create({ name => $name, description => 'Users who may needinfo people that only accept ' . 'needinfo requests from hackbot-permitted users', - isbuggroup => 0, + isbuggroup => 1, }); } +# Renames the group in place and makes it a bug group. isbuggroup is not +# among Bugzilla::Group's UPDATE_COLUMNS, so that flag is set directly. +sub _migrate_old_hackbot_group { + my ($group, $name) = @_; + my $dbh = Bugzilla->dbh; + my $groups = $dbh->quote_identifier('groups'); + + $dbh->bz_start_transaction(); + $group->set_name($name); + $group->update(); + $dbh->do("UPDATE $groups SET isbuggroup = 1 WHERE id = ?", undef, $group->id); + $dbh->bz_commit_transaction(); + Bugzilla->memcached->clear_config(); +} + sub install_before_final_checks { my ($self, $args) = @_; - _create_hackbot_needinfo_group(); + _setup_hackbot_users_group(); add_setting({ name => 'block_needinfo', options => ['on', 'editbugs', 'hackbot_needinfo', 'off'], diff --git a/extensions/Needinfo/t/bmo/block-needinfo-hackbot.t b/extensions/Needinfo/t/bmo/block-needinfo-hackbot.t index b9f8ddef2c..a597fc62c3 100644 --- a/extensions/Needinfo/t/bmo/block-needinfo-hackbot.t +++ b/extensions/Needinfo/t/bmo/block-needinfo-hackbot.t @@ -7,7 +7,7 @@ # defined by the Mozilla Public License, v. 2.0. # A user whose block_needinfo setting is 'hackbot_needinfo' only accepts -# needinfo requests from members of the hackbot_needinfo_allowed group, +# needinfo requests from members of the hackbot-users group, # whether they are in it directly or through a group nested in it. use strict; @@ -36,10 +36,28 @@ my $dbh = Bugzilla->dbh; Bugzilla->error_mode(ERROR_MODE_DIE); Bugzilla->set_user(Bugzilla::User->super_user); -my $hackbot_group = Bugzilla::Group->new({name => 'hackbot_needinfo_allowed'}); -ok($hackbot_group, 'checksetup created hackbot_needinfo_allowed'); +my $hackbot_group = Bugzilla::Group->new({name => 'hackbot-users'}); +ok($hackbot_group, 'checksetup created hackbot-users'); +ok($hackbot_group->is_bug_group, 'hackbot-users is a bug group'); +ok($hackbot_group->is_active, 'hackbot-users is active, so PhabBugz syncs it'); +is( + $dbh->selectrow_array( + 'SELECT COUNT(*) FROM group_control_map WHERE group_id = ?', undef, + $hackbot_group->id + ), + 0, + 'hackbot-users is in no products' +); + +# The migration renames an existing non-bug group in place, keeping its id. +my $old_group = create_group("$prefix-old", isbuggroup => 0); +Bugzilla::Extension::Needinfo::_migrate_old_hackbot_group($old_group, + "$prefix-new"); +my $migrated = Bugzilla::Group->new({name => "$prefix-new"}); +is($migrated && $migrated->id, $old_group->id, 'migration renames in place'); +ok($migrated && $migrated->is_bug_group, 'migration makes it a bug group'); -# A group nested in hackbot_needinfo_allowed, standing in for groups such as +# A group nested in hackbot-users, standing in for groups such as # mozilla-employee-confidential. my $nested_group = create_group("$prefix-staff", isbuggroup => 0); $dbh->do( @@ -85,7 +103,7 @@ ok(blocked_for($users{outsider}), 'blocked from a non-member'); Bugzilla->set_user($users{outsider}); eval { Bugzilla::Extension::Needinfo::_check_requestee($requestee) }; -like($@, qr/hackbot_needinfo_allowed/, 'non-member gets the hackbot error'); +like($@, qr/hackbot-users/, 'non-member gets the hackbot error'); Bugzilla->set_user($users{direct}); eval { Bugzilla::Extension::Needinfo::_check_requestee($requestee) }; diff --git a/extensions/Needinfo/template/en/default/hook/global/user-error-errors.html.tmpl b/extensions/Needinfo/template/en/default/hook/global/user-error-errors.html.tmpl index 43b383af40..33586250eb 100644 --- a/extensions/Needinfo/template/en/default/hook/global/user-error-errors.html.tmpl +++ b/extensions/Needinfo/template/en/default/hook/global/user-error-errors.html.tmpl @@ -23,5 +23,5 @@ [% ELSIF error == "needinfo_blocked_hackbot" %] [% title = "Needinfo Request Blocked" %] [% requestee.identity FILTER html %] only accepts "needinfo" requests from - users in the hackbot_needinfo_allowed group. + users in the hackbot-users group. [% END %]