From d2480ba76e111e2d8935a44543ce12909c21cc03 Mon Sep 17 00:00:00 2001 From: "bugreport%peshkin.net" <> Date: Fri, 26 Mar 2004 23:18:07 +0000 Subject: Bug 181589: Add mass-remove to editgroups r=justdave, a=justdave --- editgroups.cgi | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 178 insertions(+), 24 deletions(-) diff --git a/editgroups.cgi b/editgroups.cgi index db35a5aa8..e96545768 100755 --- a/editgroups.cgi +++ b/editgroups.cgi @@ -28,6 +28,7 @@ use strict; use lib "."; +use Bugzilla; use Bugzilla::Constants; require "CGI.pl"; @@ -191,8 +192,8 @@ if ($action eq 'changeform') { if ($isbuggroup == 0) { print html_quote($name); } else { - print " + print " "; } print "Description:"; @@ -268,6 +269,26 @@ if ($action eq 'changeform') { print "
"; print "\n"; + print < + +

Conversion of groups created with Bugzilla versions 2.16 and + prior:

+


+

+

+ + +
+EOF print "\n"; print "\n"; print ""; @@ -544,7 +565,158 @@ if ($action eq 'delete') { # if ($action eq 'postchanges') { + + # ZLL: Bug 181589: we need to have something to remove explictly listed users from + # groups in order for the conversion to 2.18 groups to work + if ($::FORM{remove_explicit_members}) { + PutHeader("Confirm: Remove All Explicit Members?"); + my ($gid, $chgs) = doGroupChanges(); + print "

\n"; + if ($chgs) { + print "Group updated, please confirm removal:

\n"; + } + confirmRemove(0,$gid); + PutFooter(); + exit; + } elsif ($::FORM{remove_explicit_members_regexp}) { + PutHeader("Confirm: Remove Explicit Members in the Regular Expression?"); + my ($gid, $chgs, $rexp) = doGroupChanges(); + print "

\n"; + if ($chgs) { + print "Group updated, please confirm removal:

\n"; + } + confirmRemove(1, $gid, $rexp); + PutFooter(); + exit; + } + + # if we got this far, the admin doesn't want to convert, so just save their changes + PutHeader("Updating group hierarchy"); + my ($gid, $chgs) = doGroupChanges(); + + if (!$chgs) { + print "You didn't change anything!
\n"; + print "If you really meant it, hit the Back button and try again.

\n"; + } else { + print "Done.

\n"; + } + PutTrailer("back to the group list"); + exit; +} + +if (($action eq 'remove_all_regexp') || ($action eq 'remove_all')) { + # remove all explicit users from the group with gid $::FORM{group} + # that match the regexp stored in the db for that group + # or all of them period + my $dbh = Bugzilla->dbh; + my $gid = $::FORM{group}; + my $sth = $dbh->prepare("SELECT name, userregexp FROM groups + WHERE id = ?"); + $sth->execute($gid); + my ($name, $regexp) = $sth->fetchrow_array(); + if ($action eq 'remove_all_regexp') { + PutHeader("Removing All Explicit Group Memberships Matching " + . "Group RegExp from \'" . html_quote($name) . "\'"); + } else { + PutHeader("Removing All Explicit Group Memberships from \'" + . html_quote($name) . "\'"); + } + $dbh->do("LOCK TABLES + groups WRITE, + profiles READ, + user_group_map WRITE"); + $sth = $dbh->prepare("SELECT user_group_map.user_id, profiles.login_name + FROM user_group_map, profiles + WHERE user_group_map.user_id = profiles.userid + AND user_group_map.group_id = ? + AND isderived = 0 + AND isbless = 0"); + $sth->execute($gid); + my $sth2 = $dbh->prepare("DELETE FROM user_group_map + WHERE user_id = ? + AND isbless = 0 + AND group_id = ?"); + if ($action eq 'remove_all_regexp') { + print "
Removing explicit memberships of users matching \'" + . html_quote($regexp) . "\'...
\n"; + } else { + print "
Removing explicit membership
\n"; + } + while ( my ($userid, $userlogin) = $sth->fetchrow_array() ) { + if ((($regexp =~ /\S/) && ($userlogin =~ m/$regexp/i)) + || ($action eq 'remove_all')) + { + $sth2->execute($userid,$gid); + print html_quote($userlogin) . " removed
\n"; + } + } + print "
Done
"; + + $sth = $dbh->prepare("UPDATE groups + SET last_changed = NOW() + WHERE id = ?"); + $sth->execute($gid); + $dbh->do("UNLOCK TABLES"); + PutTrailer("back to the group list"); + exit; +} + + + + +# +# No valid action found +# + +PutHeader("Error"); +print "I don't have a clue what you want.
\n"; + +foreach ( sort keys %::FORM) { + print "$_: $::FORM{$_}
\n"; +} + +PutTrailer("Try the group list"); + +# confirm if the user wants to remove the explicit users +sub confirmRemove { + my ($remove_regexp_only, $group, $regexp) = @_; + + if (!$remove_regexp_only) { + print "This option will remove "; + print "all explicitly defined users "; + } elsif ($regexp =~ /\S/) { + print "This option will remove "; + print "all users included in the regular expression: " . + html_quote($regexp) . " "; + } else { + print "There is no regular expression defined.\n"; + print "No users will be removed

\n"; + print "return to the Edit Groups page\n"; + return; + } + print "from group $::FORM{name}.

\n"; + print "Generally, you will only need to do this when upgrading groups "; + print "created with Bugzilla versions 2.16 and prior. Use this option "; + print "with extreme care and consult the Bugzilla Guide for "; + print "further information.

\n"; + + print "

\n"; + print "\n"; + + if ($remove_regexp_only) { + print "\n"; + } else { + print "\n"; + } + + print "\n"; + print "

Or return to the Edit Groups page\n"; + print "

"; +} + +# Helper sub to handle the making of changes to a group +sub doGroupChanges { my $gid = trim($::FORM{group} || ''); unless ($gid) { ShowError("No group specified.
" . @@ -622,28 +794,10 @@ if ($action eq 'postchanges') { } } - if (!$chgs) { - print "You didn't change anything!
\n"; - print "If you really meant it, hit the Back button and try again.

\n"; - } else { + + if ($chgs) { + # mark the changes SendSQL("UPDATE groups SET last_changed = NOW() WHERE id = $gid"); - print "Done.

\n"; } - PutTrailer("back to the group list"); - exit; -} - - - -# -# No valid action found -# - -PutHeader("Error"); -print "I don't have a clue what you want.
\n"; - -foreach ( sort keys %::FORM) { - print "$_: $::FORM{$_}
\n"; + return $gid, $chgs, $::FORM{"rexp"}; } - -PutTrailer("Try the group list"); -- cgit v1.2.3-24-g4f1b