Fix for bug 75482: adding the capability to deactivate a group without deleting…

Fix for bug 75482: adding the capability to deactivate a group without deleting it (prevent new bugs from being placed into that group, but don't remove the group restriction from bugs already in it). Patch by Myk Melez <myk@mozilla.org> r= justdave@syndicomm.com
parent 24bf6d11
...@@ -368,7 +368,14 @@ print " ...@@ -368,7 +368,14 @@ print "
if ($::usergroupset ne '0') { if ($::usergroupset ne '0') {
SendSQL("select bit, description, (bit & $bug{'groupset'} != 0) from groups where bit & $::usergroupset != 0 and isbuggroup != 0 order by bit"); SendSQL("select bit, description, (bit & $bug{'groupset'} != 0) " .
"from groups where bit & $::usergroupset != 0 " .
"and isbuggroup != 0 " .
# Include active groups as well as inactive groups to which
# the bug already belongs. This way the bug can be removed
# from an inactive group but can only be added to active ones.
"and (isactive = 1 or (bit & $bug{'groupset'} != 0)) " .
"order by bit");
while (MoreSQLData()) { while (MoreSQLData()) {
my ($bit, $description, $ison) = (FetchSQLData()); my ($bit, $description, $ison) = (FetchSQLData());
my $check0 = !$ison ? " SELECTED" : ""; my $check0 = !$ison ? " SELECTED" : "";
......
...@@ -790,6 +790,13 @@ $table{dependencies} = ...@@ -790,6 +790,13 @@ $table{dependencies} =
# User regexp is which email addresses are initially put into this group. # User regexp is which email addresses are initially put into this group.
# This is only used when an email account is created; otherwise, profiles # This is only used when an email account is created; otherwise, profiles
# may be individually tweaked to add them in and out of groups. # may be individually tweaked to add them in and out of groups.
#
# 2001-04-10 myk@mozilla.org:
# isactive determines whether or not a group is active. An inactive group
# cannot have bugs added to it. Deactivation is a much milder form of
# deleting a group that allows users to continue to work on bugs in the group
# without enabling them to extend the life of the group by adding bugs to it.
# http://bugzilla.mozilla.org/show_bug.cgi?id=75482
$table{groups} = $table{groups} =
'bit bigint not null, 'bit bigint not null,
...@@ -797,6 +804,7 @@ $table{groups} = ...@@ -797,6 +804,7 @@ $table{groups} =
description text not null, description text not null,
isbuggroup tinyint not null, isbuggroup tinyint not null,
userregexp tinytext not null, userregexp tinytext not null,
isactive tinyint not null default 1,
unique(bit), unique(bit),
unique(name)'; unique(name)';
...@@ -2157,6 +2165,16 @@ unless (-d 'data/duplicates') { ...@@ -2157,6 +2165,16 @@ unless (-d 'data/duplicates') {
} }
} }
#
# 2001-04-10 myk@mozilla.org:
# isactive determines whether or not a group is active. An inactive group
# cannot have bugs added to it. Deactivation is a much milder form of
# deleting a group that allows users to continue to work on bugs in the group
# without enabling them to extend the life of the group by adding bugs to it.
# http://bugzilla.mozilla.org/show_bug.cgi?id=75482
#
AddField('groups', 'isactive', 'tinyint not null default 1');
# 2001-04-29 jake@acutex.net - Remove oldemailtech # 2001-04-29 jake@acutex.net - Remove oldemailtech
# http://bugzilla.mozilla.org/show_bugs.cgi?id=71552 # http://bugzilla.mozilla.org/show_bugs.cgi?id=71552
if (-d 'shadow') { if (-d 'shadow') {
......
...@@ -105,16 +105,17 @@ unless ($action) { ...@@ -105,16 +105,17 @@ unless ($action) {
print "<th>Name</th>"; print "<th>Name</th>";
print "<th>Description</th>"; print "<th>Description</th>";
print "<th>User RegExp</th>"; print "<th>User RegExp</th>";
print "<th>Active</th>";
print "<th>Action</th>"; print "<th>Action</th>";
print "</tr>\n"; print "</tr>\n";
SendSQL("SELECT bit,name,description,userregexp " . SendSQL("SELECT bit,name,description,userregexp,isactive " .
"FROM groups " . "FROM groups " .
"WHERE isbuggroup != 0 " . "WHERE isbuggroup != 0 " .
"ORDER BY bit"); "ORDER BY bit");
while (MoreSQLData()) { while (MoreSQLData()) {
my ($bit, $name, $desc, $regexp) = FetchSQLData(); my ($bit, $name, $desc, $regexp, $isactive) = FetchSQLData();
print "<tr>\n"; print "<tr>\n";
print "<td valign=middle>$bit</td>\n"; print "<td valign=middle>$bit</td>\n";
print "<td><input size=20 name=\"name-$bit\" value=\"$name\">\n"; print "<td><input size=20 name=\"name-$bit\" value=\"$name\">\n";
...@@ -123,12 +124,14 @@ unless ($action) { ...@@ -123,12 +124,14 @@ unless ($action) {
print "<input type=hidden name=\"olddesc-$bit\" value=\"$desc\"></td>\n"; print "<input type=hidden name=\"olddesc-$bit\" value=\"$desc\"></td>\n";
print "<td><input size=30 name=\"regexp-$bit\" value=\"$regexp\">\n"; print "<td><input size=30 name=\"regexp-$bit\" value=\"$regexp\">\n";
print "<input type=hidden name=\"oldregexp-$bit\" value=\"$regexp\"></td>\n"; print "<input type=hidden name=\"oldregexp-$bit\" value=\"$regexp\"></td>\n";
print "<td><input type=\"checkbox\" name=\"isactive-$bit\" value=\"1\"" . ($isactive ? " checked" : "") . ">\n";
print "<input type=hidden name=\"oldisactive-$bit\" value=\"$isactive\"></td>\n";
print "<td align=center valign=middle><a href=\"editgroups.cgi?action=del&group=$bit\">Delete</a></td>\n"; print "<td align=center valign=middle><a href=\"editgroups.cgi?action=del&group=$bit\">Delete</a></td>\n";
print "</tr>\n"; print "</tr>\n";
} }
print "<tr>\n"; print "<tr>\n";
print "<td colspan=4></td>\n"; print "<td colspan=5></td>\n";
print "<td><a href=\"editgroups.cgi?action=add\">Add Group</a></td>\n"; print "<td><a href=\"editgroups.cgi?action=add\">Add Group</a></td>\n";
print "</tr>\n"; print "</tr>\n";
print "</table>\n"; print "</table>\n";
...@@ -146,6 +149,11 @@ to others in the same group.<p>"; ...@@ -146,6 +149,11 @@ to others in the same group.<p>";
print "<b>User RegExp</b> is optional, and if filled in, will automatically print "<b>User RegExp</b> is optional, and if filled in, will automatically
grant membership to this group to anyone creating a new account with an grant membership to this group to anyone creating a new account with an
email address that matches this regular expression.<p>"; email address that matches this regular expression.<p>";
print "The <b>Active</b> 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.<p>";
print "In addition, the following groups that determine user privileges print "In addition, the following groups that determine user privileges
exist. You can only edit the User rexexp on these groups. You should also take exist. You can only edit the User rexexp on these groups. You should also take
care not to duplicate the Names of any of them in your user groups.<p>"; care not to duplicate the Names of any of them in your user groups.<p>";
...@@ -201,10 +209,12 @@ if ($action eq 'add') { ...@@ -201,10 +209,12 @@ if ($action eq 'add') {
print "<th>New Name</th>"; print "<th>New Name</th>";
print "<th>New Description</th>"; print "<th>New Description</th>";
print "<th>New User RegExp</th>"; print "<th>New User RegExp</th>";
print "<th>Active</th>";
print "</tr><tr>"; print "</tr><tr>";
print "<td><input size=20 name=\"name\"></td>\n"; print "<td><input size=20 name=\"name\"></td>\n";
print "<td><input size=40 name=\"desc\"></td>\n"; print "<td><input size=40 name=\"desc\"></td>\n";
print "<td><input size=30 name=\"regexp\"></td>\n"; print "<td><input size=30 name=\"regexp\"></td>\n";
print "<td><input type=\"checkbox\" name=\"isactive\" value=\"1\" checked></td>\n";
print "</TR></TABLE>\n<HR>\n"; print "</TR></TABLE>\n<HR>\n";
print "<INPUT TYPE=SUBMIT VALUE=\"Add\">\n"; print "<INPUT TYPE=SUBMIT VALUE=\"Add\">\n";
print "<INPUT TYPE=HIDDEN NAME=\"action\" VALUE=\"new\">\n"; print "<INPUT TYPE=HIDDEN NAME=\"action\" VALUE=\"new\">\n";
...@@ -218,6 +228,12 @@ may not contain any spaces.<p>"; ...@@ -218,6 +228,12 @@ may not contain any spaces.<p>";
print "<b>Description</b> is what will be shown in the bug reports to print "<b>Description</b> is what will be shown in the bug reports to
members of the group where they can choose whether the bug will be restricted members of the group where they can choose whether the bug will be restricted
to others in the same group.<p>"; to others in the same group.<p>";
print "The <b>Active</b> 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. <b>Note: If you are creating a group, you
probably want it to be active, in which case you should leave this checked.</b><p>";
print "<b>User RegExp</b> is optional, and if filled in, will automatically print "<b>User RegExp</b> is optional, and if filled in, will automatically
grant membership to this group to anyone creating a new account with an grant membership to this group to anyone creating a new account with an
email address that matches this regular expression.<p>"; email address that matches this regular expression.<p>";
...@@ -239,6 +255,10 @@ if ($action eq 'new') { ...@@ -239,6 +255,10 @@ if ($action eq 'new') {
my $name = trim($::FORM{name} || ''); my $name = trim($::FORM{name} || '');
my $desc = trim($::FORM{desc} || ''); my $desc = trim($::FORM{desc} || '');
my $regexp = trim($::FORM{regexp} || ''); 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;
unless ($name) { unless ($name) {
ShowError("You must enter a name for the new group.<BR>" . ShowError("You must enter a name for the new group.<BR>" .
...@@ -259,6 +279,14 @@ if ($action eq 'new') { ...@@ -259,6 +279,14 @@ if ($action eq 'new') {
exit; 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.<br>" .
"Please click the <b>Back</b> button and try again.");
PutFooter();
exit;
}
# Major hack for bit values... perl can't handle 64-bit ints, so I can't # Major hack for bit values... perl can't handle 64-bit ints, so I can't
# just do the math to get the next available bit number, gotta handle # just do the math to get the next available bit number, gotta handle
# them as strings... also, we're actually only going to allow 63 bits # them as strings... also, we're actually only going to allow 63 bits
...@@ -304,13 +332,14 @@ if ($action eq 'new') { ...@@ -304,13 +332,14 @@ if ($action eq 'new') {
# Add the new group # Add the new group
SendSQL("INSERT INTO groups ( " . SendSQL("INSERT INTO groups ( " .
"bit, name, description, isbuggroup, userregexp" . "bit, name, description, isbuggroup, userregexp, isactive" .
" ) VALUES ( " . " ) VALUES ( " .
$bit . "," . $bit . "," .
SqlQuote($name) . "," . SqlQuote($name) . "," .
SqlQuote($desc) . "," . SqlQuote($desc) . "," .
"1," . "1," .
SqlQuote($regexp) . ")" ); SqlQuote($regexp) . "," .
$isactive . ")" );
print "OK, done.<p>\n"; print "OK, done.<p>\n";
print "Your new group was assigned bit #$bit.<p>"; print "Your new group was assigned bit #$bit.<p>";
...@@ -573,6 +602,23 @@ if ($action eq 'update') { ...@@ -573,6 +602,23 @@ if ($action eq 'update') {
" WHERE bit=" . SqlQuote($v)); " WHERE bit=" . SqlQuote($v));
print "Group $v user regexp updated.<br>\n"; print "Group $v user regexp updated.<br>\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" .
" WHERE bit=" . SqlQuote($v));
print "Group $v active flag updated.<br>\n";
} else {
ShowError("The value '" . $isactive .
"' is not a valid value for the active flag.<BR>" .
"There may be a problem with Bugzilla or a bug in your browser.<br>" .
"Update of active flag for group $v skipped.");
}
}
} }
} }
if (!$chgs) { if (!$chgs) {
......
...@@ -410,7 +410,7 @@ print " ...@@ -410,7 +410,7 @@ print "
if ($::usergroupset ne '0') { if ($::usergroupset ne '0') {
SendSQL("SELECT bit, description FROM groups " . SendSQL("SELECT bit, description FROM groups " .
"WHERE bit & $::usergroupset != 0 " . "WHERE bit & $::usergroupset != 0 " .
" AND isbuggroup != 0 ORDER BY description"); " AND isbuggroup != 0 AND isactive = 1 ORDER BY description");
while (MoreSQLData()) { while (MoreSQLData()) {
my ($bit, $description) = (FetchSQLData()); my ($bit, $description) = (FetchSQLData());
# Rather than waste time with another Param check and another database # Rather than waste time with another Param check and another database
......
...@@ -969,6 +969,17 @@ sub GroupExists { ...@@ -969,6 +969,17 @@ sub GroupExists {
return $count; return $count;
} }
# Determines whether or not a group is active by checking
# the "isactive" column for the group in the "groups" table.
# Note: This function selects groups by bit rather than by name.
sub GroupIsActive {
my ($groupbit) = (@_);
ConnectToDatabase();
SendSQL("select isactive from groups where bit=$groupbit");
my $isactive = FetchOneColumn();
return $isactive;
}
# Determines if the given bug_status string represents an "Opened" bug. This # Determines if the given bug_status string represents an "Opened" bug. This
# routine ought to be paramaterizable somehow, as people tend to introduce # routine ought to be paramaterizable somehow, as people tend to introduce
# new states into Bugzilla. # new states into Bugzilla.
......
...@@ -207,6 +207,17 @@ $query .= "now(), 0"; ...@@ -207,6 +207,17 @@ $query .= "now(), 0";
foreach my $b (grep(/^bit-\d*$/, keys %::FORM)) { foreach my $b (grep(/^bit-\d*$/, keys %::FORM)) {
if ($::FORM{$b}) { if ($::FORM{$b}) {
my $v = substr($b, 4); my $v = substr($b, 4);
$v =~ /^(\d+)$/
|| PuntTryAgain("One of the group bits submitted was invalid.");
if (!GroupIsActive($v)) {
# Prevent the user from adding the bug to an inactive group.
# Should only happen if there is a bug in Bugzilla or the user
# hacked the "enter bug" form since otherwise the UI
# for adding the bug to the group won't appear on that form.
PuntTryAgain("You can't add this bug to the inactive group " .
"identified by the bit '$v'. This shouldn't happen, " .
"so it may indicate a bug in Bugzilla.");
}
$query .= " + $v"; # Carefully written so that the math is $query .= " + $v"; # Carefully written so that the math is
# done by MySQL, which can handle 64-bit math, # done by MySQL, which can handle 64-bit math,
# and not by Perl, which I *think* can not. # and not by Perl, which I *think* can not.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment