diff options
author | Dylan William Hardison <dylan@hardison.net> | 2016-11-07 20:06:45 +0100 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2016-11-07 20:06:45 +0100 |
commit | b15c80df9de4b5d2b72639bbcf84aa4b3c208fa6 (patch) | |
tree | b83ad6db8befe92b422309e3048effb9d4ebc920 /scripts/eject-users-from-groups.pl | |
parent | 66e083aca965ebd654c3d1a70df2b5e1326b8d20 (diff) | |
download | bugzilla-b15c80df9de4b5d2b72639bbcf84aa4b3c208fa6.tar.gz bugzilla-b15c80df9de4b5d2b72639bbcf84aa4b3c208fa6.tar.xz |
Bug 1315701 - Re-purpose nightly cleaner to be eject-user-from-groups script
Diffstat (limited to 'scripts/eject-users-from-groups.pl')
-rw-r--r-- | scripts/eject-users-from-groups.pl | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/scripts/eject-users-from-groups.pl b/scripts/eject-users-from-groups.pl new file mode 100644 index 000000000..c67238705 --- /dev/null +++ b/scripts/eject-users-from-groups.pl @@ -0,0 +1,55 @@ +#!/usr/bin/perl -w +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. +use 5.10.1; +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/..", "$FindBin::Bin/../lib", "$FindBin::Bin/../local/lib/perl5"; +use Getopt::Long; + +use Bugzilla; +use Bugzilla::Constants; + +BEGIN { Bugzilla->extensions } + +Bugzilla->usage_mode(USAGE_MODE_CMDLINE); + +my $dbh = Bugzilla->dbh; +my @remove_group_names; +my $nobody_name = 'nobody@mozilla.org'; +my $admin_name = 'automation@bmo.tld'; + +GetOptions( + 'nobody=s' => \$nobody_name, + 'admin=s' => \$admin_name, + 'group|G=s@' => \@remove_group_names, +); +my @user_names = @ARGV; + +unless (@remove_group_names) { + die "usage: $0 [--admin=$admin_name] [--nobody=$nobody_name] ", + "-G legal -G finance dylan\@mozilla.com bob\@example.net\n"; +} + +$dbh->bz_start_transaction(); +my ($timestamp) = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); +my $admin_user = Bugzilla::User->check({ name => $admin_name }); +my $nobody_user = Bugzilla::User->check({ name => $nobody_name }); +Bugzilla->set_user($admin_user); + +my @remove_groups = map { Bugzilla::Group->check({name => $_}) } @remove_group_names; + +foreach my $user_name (@user_names) { + my $user = Bugzilla::User->check({name => $user_name}); + say 'Working on ', $user->identity; + + $user->force_bug_dissociation($nobody_user, \@remove_groups, $timestamp); +} + +$dbh->bz_commit_transaction(); |