#!/usr/bonsaitools/bin/perl -w # -*- Mode: perl; indent-tabs-mode: nil -*- # # The contents of this file are subject to the Mozilla Public # License Version 1.1 (the "License"); you may not use this file # except in compliance with the License. You may obtain a copy of # the License at http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or # implied. See the License for the specific language governing # rights and limitations under the License. # # The Original Code is the Bugzilla Bug Tracking System. # # The Initial Developer of the Original Code is Netscape Communications # Corporation. Portions created by Netscape are # Copyright (C) 1998 Netscape Communications Corporation. All # Rights Reserved. # # Contributor(s): Dave Miller # Jake Steenhagen # Code derived from editowners.cgi and editusers.cgi use diagnostics; use strict; use lib "."; require "CGI.pl"; ConnectToDatabase(); confirm_login(); print "Content-type: text/html\n\n"; if (!UserInGroup("creategroups")) { PutHeader("Not Authorized","Edit Groups","","Not Authorized for this function!"); print "

Sorry, you aren't a member of the 'creategroups' group.

\n"; print "And so, you aren't allowed to edit the groups.\n"; print "

\n"; PutFooter(); exit; } my $action = trim($::FORM{action} || ''); # TestGroup: check if the group name exists sub TestGroup ($) { my $group = shift; # does the group exist? SendSQL("SELECT name FROM groups WHERE name=" . SqlQuote($group)); return FetchOneColumn(); } sub ShowError ($) { my $msgtext = shift; print "
"; print "$msgtext"; print "

"; return 1; } # # Displays a text like "a.", "a or b.", "a, b or c.", "a, b, c or d." # sub PutTrailer (@) { my (@links) = ("Back to the Main Bugs Page", @_); my $count = $#links; my $num = 0; print "

\n"; foreach (@links) { print $_; if ($num == $count) { print ".\n"; } elsif ($num == $count-1) { print " or "; } else { print ", "; } $num++; } PutFooter(); } # # action='' -> No action specified, get a list. # unless ($action) { PutHeader("Edit Groups","Edit Groups","This lets you edit the groups available to put users in."); print "

\n"; print "\n"; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print "\n"; SendSQL("SELECT group_id,name,description,userregexp,isactive,group_type " . "FROM groups " . "ORDER BY group_id"); while (MoreSQLData()) { my ($groupid, $name, $desc, $regexp, $isactive, $group_type) = FetchSQLData(); print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; } print "\n"; print "\n"; print "\n"; print "\n"; print "
IdNameDescriptionUser RegExpActiveTypeAction
$groupid\n"; print "\n"; print "\n"; print "\n"; print ""; if ($group_type == $::Tgroup_type->{'system'} ) { print "system"; } else { print "\n"; } print " Edit"; print " | Delete" if ($group_type != $::Tgroup_type->{'system'} ); print "
Add Group
\n"; print ""; print "\n"; print "

"; print "Name is what is used with the UserInGroup() function in any customized cgi files you write that use a given group. It can also be used by people submitting bugs by email to limit a bug to a certain set of groups.

"; print "Description is what will be shown in the bug reports to members of the group where they can choose whether the bug will be restricted to others in the same group.

"; print "User RegExp is optional, and if filled in, will automatically grant membership to this group to anyone creating a new account with an email address that matches this regular expression.

"; print "The Active flag determines whether or not the group is active. If you deactivate a group it will no longer be possible for users to add bugs to that group, although bugs already in the group will remain in the group. Deactivating a group is a much less drastic way to stop a group from growing than deleting the group would be.

"; print "The Type field identifies system groups and determines whether or not the group should generate a checkbox on bug entry/edit pages for group restrictions. If type is 'buggroup,' the checkbox will be offerred. If type is 'user,' the group is not used for bugs but can be used to organize groups of users

"; print "

\n"; PutFooter(); exit; } # # # action='changeform' -> present form for altering an existing group # # (next action will be 'postchanges') # if ($action eq 'changeform') { PutHeader("Change Group"); my $gid = trim($::FORM{group} || ''); unless ($gid) { ShowError("No group specified.
" . "Click the Back button and try again."); PutFooter(); exit; } SendSQL("SELECT group_id, name, description, userregexp FROM groups WHERE group_id=" . SqlQuote($gid)); my ($group_id, $name, $description, $rexp) = FetchSQLData(); print "

Group: $name

Description: $description

User Regexp: \"$rexp\"


In addition to the users explicitly included in this group and users matching the regular expression listed above, users who are members members of other groups can be included by including the other groups in this group.

\n"; print "

\n"; print ""; print ""; print ""; print ""; SendSQL("SELECT groups.group_id, groups.name, groups.description, ISNULL(member_group_map.member_id) = 0, ISNULL(B.member_id) = 0 FROM groups LEFT JOIN member_group_map ON member_group_map.member_id = groups.group_id AND member_group_map.group_id = $group_id AND member_group_map.maptype = $::Tmaptype->{'g2gm'} LEFT JOIN member_group_map as B ON B.member_id = groups.group_id AND B.group_id = $group_id AND B.maptype = $::Tmaptype->{'gBg'} WHERE groups.group_id != $group_id ORDER by name"); while (MoreSQLData()) { my ($grpid, $grpnam, $grpdesc, $grpmember, $blessmember) = FetchSQLData(); my $grpchecked = $grpmember ? "CHECKED" : ""; my $blesschecked = $blessmember ? "CHECKED" : ""; print ""; print ""; print ""; print ""; print ""; print "\n"; } print "
Members of these groups can grant membership to this group
|Members of these groups are included in this group
||
"; print ""; print "$grpnam$grpdesc

"; print "\n"; print "\n"; print "\n"; print "
"; PutTrailer("Back to group list"); exit; } # # action='add' -> present form for parameters for new group # # (next action will be 'new') # if ($action eq 'add') { PutHeader("Add group"); print "
\n"; print "\n"; print ""; print ""; print ""; print ""; print ""; print ""; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
New NameNew DescriptionNew User RegExpActiveType
\n
\n"; print "\n"; print "\n"; print "
"; print "

"; print "Name is what is used with the UserInGroup() function in any customized cgi files you write that use a given group. It can also be used by people submitting bugs by email to limit a bug to a certain set of groups. It may not contain any spaces.

"; print "Description is what will be shown in the bug reports to members of the group where they can choose whether the bug will be restricted to others in the same group.

"; print "The Active flag determines whether or not the group is active. If you deactivate a group it will no longer be possible for users to add bugs to that group, although bugs already in the group will remain in the group. Deactivating a group is a much less drastic way to stop a group from growing than deleting the group would be. Note: If you are creating a group, you probably want it to be active, in which case you should leave this checked.

"; print "User RegExp is optional, and if filled in, will automatically grant membership to this group to anyone creating a new account with an email address that matches this regular expression.

"; PutTrailer("Back to the group list"); exit; } # # action='new' -> add group entered in the 'action=add' screen # if ($action eq 'new') { PutHeader("Adding new group"); # Cleanups and valididy checks my $name = trim($::FORM{name} || ''); my $desc = trim($::FORM{desc} || ''); my $regexp = trim($::FORM{regexp} || ''); # convert an undefined value in the inactive field to zero # (this occurs when the inactive checkbox is not checked # and the browser does not send the field to the server) my $isactive = $::FORM{isactive} || 0; my $group_type = $::FORM{group_type} || $::Tgroup_type->{'buggroup'}; unless ($name) { ShowError("You must enter a name for the new group.
" . "Please click the Back button and try again."); PutFooter(); exit; } unless ($desc) { ShowError("You must enter a description for the new group.
" . "Please click the Back button and try again."); PutFooter(); exit; } if (TestGroup($name)) { ShowError("The group '" . $name . "' already exists.
" . "Please click the Back button and try again."); PutFooter(); exit; } if ($isactive != 0 && $isactive != 1) { ShowError("The active flag was improperly set. There may be " . "a problem with Bugzilla or a bug in your browser.
" . "Please click the Back button and try again."); PutFooter(); exit; } # Add the new group SendSQL("INSERT INTO groups ( " . "name, description, group_type, userregexp, isactive, group_when " . " ) VALUES ( " . SqlQuote($name) . "," . SqlQuote($desc) . "," . "$group_type," . SqlQuote($regexp) . "," . $isactive . ", NOW())" ); SendSQL("SELECT last_insert_id()"); my $gid = FetchOneColumn(); my $admin = GroupNameToId('admin'); SendSQL("INSERT INTO member_group_map (member_id, group_id, maptype) VALUES ($admin, $gid, $::Tmaptype->{'gBg'})"); print "OK, done.

\n"; PutTrailer("Add another group", "Back to the group list"); exit; } # # action='del' -> ask if user really wants to delete # # (next action would be 'delete') # if ($action eq 'del') { PutHeader("Delete group"); my $gid = trim($::FORM{group} || ''); unless ($gid) { ShowError("No group specified.
" . "Click the Back button and try again."); PutFooter(); exit; } SendSQL("SELECT group_id FROM groups WHERE group_id=" . SqlQuote($gid)); if (!FetchOneColumn()) { ShowError("That group doesn't exist.
" . "Click the Back button and try again."); PutFooter(); exit; } SendSQL("SELECT name,description " . "FROM groups " . "WHERE group_id = " . SqlQuote($gid)); my ($name, $desc) = FetchSQLData(); print "\n"; print ""; print ""; print ""; print ""; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
IdNameDescription
$gid$name$desc
\n"; print "

\n"; my $cantdelete = 0; SendSQL("SELECT member_id FROM member_group_map WHERE group_id = $gid"); if (!FetchOneColumn()) {} else { $cantdelete = 1; print " One or more users belong to this group. You cannot delete this group while there are users in it.
Show me which users. - Remove all users from this group for me

"; } SendSQL("SELECT bug_id FROM bug_group_map WHERE group_id = $gid"); my $buglist=""; if (MoreSQLData()) { $cantdelete = 1; my $buglist = "0"; while (MoreSQLData()) { my ($bug) = FetchSQLData(); $buglist .= "," . $bug; } print " One or more bug reports are visible only to this group. You cannot delete this group while any bugs are using it.
Show me which bugs. - Remove all bugs from this group restriction for me
NOTE: It's quite possible to make confidential bugs public by checking this box. It is strongly suggested that you review the bugs in this group before checking the box.

"; } SendSQL("SELECT product FROM products WHERE product=" . SqlQuote($name)); if (MoreSQLData()) { $cantdelete = 1; print " This group is tied to the $name product. You cannot delete this group while it is tied to a product.
Delete this group anyway, and make the $name product publicly visible.
"; } print "

Confirmation

\n"; print "

Do you really want to delete this group?\n"; if ($cantdelete) { print "
You must check all of the above boxes or correct the " . "indicated problems first before you can proceed."; } print "

\n"; print "\n"; print "\n"; print "

"; PutTrailer("No, go back to the group list"); exit; } # # action='delete' -> really delete the group # if ($action eq 'delete') { PutHeader("Deleting group"); my $gid = trim($::FORM{group} || ''); unless ($gid) { ShowError("No group specified.
" . "Click the Back button and try again."); PutFooter(); exit; } SendSQL("SELECT name " . "FROM groups " . "WHERE group_id = " . SqlQuote($gid)); my ($name) = FetchSQLData(); my $cantdelete = 0; SendSQL("SELECT member_id FROM member_group_map WHERE group_id = $gid"); if (FetchOneColumn()) { if (!defined $::FORM{'removeusers'}) { $cantdelete = 1; } } SendSQL("SELECT bug_id FROM bug_group_map WHERE group_id = $gid"); if (FetchOneColumn()) { if (!defined $::FORM{'removebugs'}) { $cantdelete = 1; } } SendSQL("SELECT product FROM products WHERE product=" . SqlQuote($name)); if (FetchOneColumn()) { if (!defined $::FORM{'unbind'}) { $cantdelete = 1; } } if ($cantdelete == 1) { ShowError("This group cannot be deleted because there are child " . "records in the database which refer to it. All child records " . "must be removed or altered to remove the reference to this " . "group before the group can be deleted."); print "" . "View the list of which records are affected
"; PutTrailer("Back to group list"); exit; } SendSQL("DELETE FROM member_group_map WHERE group_id = $gid"); SendSQL("DELETE FROM bug_group_map WHERE group_id = $gid"); SendSQL("DELETE FROM groups WHERE group_id = $gid"); print "Group $gid has been deleted.
"; PutTrailer("Back to group list"); exit; } # # action='postchanges' -> update the groups # if ($action eq 'postchanges') { PutHeader("Updating group hierarchy"); my $gid = trim($::FORM{group} || ''); unless ($gid) { ShowError("No group specified.
" . "Click the Back button and try again."); PutFooter(); exit; } my $chgs = 0; print "Checking...."; foreach my $b (grep(/^oldgrp-\d*$/, keys %::FORM)) { if (defined($::FORM{$b})) { my $v = substr($b, 7); print "checking $v

\n"; my $grp = $::FORM{"grp-$v"} || 0; if ($::FORM{"oldgrp-$v"} != $grp) { $chgs = 1; print "changed"; if ($grp != 0) { print " set "; SendSQL("INSERT INTO member_group_map (member_id, group_id, maptype, isderived) VALUES ($v, $gid, $::Tmaptype->{'g2gm'}, 0)"); } else { print " cleared "; SendSQL("DELETE FROM member_group_map WHERE member_id = $v AND group_id = $gid AND maptype = $::Tmaptype->{'g2gm'}"); } } my $bless = $::FORM{"bless-$v"} || 0; if ($::FORM{"oldbless-$v"} != $bless) { $chgs = 1; print "changed"; if ($bless != 0) { print " set "; SendSQL("INSERT INTO member_group_map (member_id, group_id, maptype, isderived) VALUES ($v, $gid, $::Tmaptype->{'gBg'}, 0)"); } else { print " cleared "; SendSQL("DELETE FROM member_group_map WHERE member_id = $v AND group_id = $gid AND maptype = $::Tmaptype->{'gBg'}"); } } } } if (!$chgs) { print "You didn't change anything!
\n"; print "If you really meant it, hit the Back button and try again.

\n"; } else { SendSQL("UPDATE groups SET group_when = NOW() WHERE group_id = $gid"); print "Done.

\n"; } PutTrailer("Back to the group list"); exit; } # # action='update' -> update the groups # if ($action eq 'update') { PutHeader("Updating groups"); my $chgs = 0; foreach my $b (grep(/^name-\d*$/, keys %::FORM)) { if ($::FORM{$b}) { my $v = substr($b, 5); # print "Old: '" . $::FORM{"oldname-$v"} . "', '" . $::FORM{"olddesc-$v"} . # "', '" . $::FORM{"oldregexp-$v"} . "'
"; # print "New: '" . $::FORM{"name-$v"} . "', '" . $::FORM{"desc-$v"} . # "', '" . $::FORM{"regexp-$v"} . "'
"; if ($::FORM{"oldname-$v"} ne $::FORM{"name-$v"}) { $chgs = 1; SendSQL("SELECT name FROM groups WHERE name=" . SqlQuote($::FORM{"name-$v"})); if (!FetchOneColumn()) { SendSQL("SELECT name FROM groups WHERE name=" . SqlQuote($::FORM{"oldname-$v"}) . " && group_type = $::Tgroup_type->{'system'}"); if (FetchOneColumn()) { ShowError("You cannot update the name of a " . "system group. Skipping $v"); } else { SendSQL("UPDATE groups SET name=" . SqlQuote($::FORM{"name-$v"}) . " WHERE group_id=" . SqlQuote($v)); print "Group $v name updated.
\n"; } } else { ShowError("Duplicate name '" . $::FORM{"name-$v"} . "' specified for group $v.
" . "Update of group $v name skipped."); } } if ($::FORM{"olddesc-$v"} ne $::FORM{"desc-$v"}) { $chgs = 1; SendSQL("SELECT description FROM groups WHERE description=" . SqlQuote($::FORM{"desc-$v"})); if (!FetchOneColumn()) { SendSQL("UPDATE groups SET description=" . SqlQuote($::FORM{"desc-$v"}) . " WHERE group_id=" . SqlQuote($v)); print "Group $v description updated.
\n"; } else { ShowError("Duplicate description '" . $::FORM{"desc-$v"} . "' specified for group $v.
" . "Update of group $v description skipped."); } } if ($::FORM{"oldregexp-$v"} ne $::FORM{"regexp-$v"}) { $chgs = 1; SendSQL("UPDATE groups SET userregexp=" . SqlQuote($::FORM{"regexp-$v"}) . " , group_when = NOW() " . " WHERE group_id=" . SqlQuote($v)); print "Group $v user regexp updated.
\n"; } # convert an undefined value in the inactive field to zero # (this occurs when the inactive checkbox is not checked # and the browser does not send the field to the server) my $isactive = $::FORM{"isactive-$v"} || 0; if ($::FORM{"oldisactive-$v"} != $isactive) { $chgs = 1; if ($isactive == 0 || $isactive == 1) { SendSQL("UPDATE groups SET isactive=$isactive, " . " group_when = NOW() " . " WHERE group_id=" . SqlQuote($v)); print "Group $v active flag updated.
\n"; } else { ShowError("The value '" . $isactive . "' is not a valid value for the active flag.
" . "There may be a problem with Bugzilla or a bug in your browser.
" . "Update of active flag for group $v skipped."); } } # convert an undefined value in the group_type field to zero # (this occurs when the inactive checkbox is not checked # and the browser does not send the field to the server) my $group_type = $::FORM{"group_type-$v"} || 0; if ($::FORM{"oldgroup_type-$v"} != $group_type) { $chgs = 1; if (GetTypeNameByVal($group_type)) { SendSQL("UPDATE groups SET group_type=$group_type, " . " group_when = NOW() " . " WHERE group_id=" . SqlQuote($v)); print "Group $v group_type updated.
\n"; } else { ShowError("The value '" . $group_type . "' is not a valid value for the group_type.
" . "There may be a problem with Bugzilla or a bug in your browser.
" . "Update of group_type for group $v skipped."); } } SendSQL("UPDATE groups SET group_when = NOW() WHERE group_id=" . SqlQuote($v)); } } 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; } # # 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");