From: jocuri%softhome.net <> Date: Tue, 13 Jul 2004 12:12:29 +0000 (+0000) Subject: Patch for bug 190222: templatize editgroups.cgi; r=joel, a=justdave. X-Git-Tag: bugzilla-2.19.1~164 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac8796ba2733be5e0e618148ee12488cc567d34e;p=thirdparty%2Fbugzilla.git Patch for bug 190222: templatize editgroups.cgi; r=joel, a=justdave. --- diff --git a/editgroups.cgi b/editgroups.cgi index 1b2f0d3df6..29e28dd9a0 100755 --- a/editgroups.cgi +++ b/editgroups.cgi @@ -32,22 +32,17 @@ use Bugzilla; use Bugzilla::Constants; require "CGI.pl"; +my $cgi = Bugzilla->cgi; + use vars qw($template $vars); Bugzilla->login(LOGIN_REQUIRED); print Bugzilla->cgi->header(); -if (!UserInGroup("creategroups")) { - PutHeader("Not Authorized","Edit Groups","","Not Authorized for this function!"); - print "
\n"; - PutFooter(); - exit; -} +ThrowUserError("auth_cant_edit_groups") unless UserInGroup("creategroups"); -my $action = trim($::FORM{action} || ''); +my $action = trim($cgi->param('action') || ''); # RederiveRegexp: update user_group_map with regexp-based grants sub RederiveRegexp ($$) @@ -85,108 +80,40 @@ sub TestGroup ($) 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 index", @_); - - 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 "
Name | "; - print "Description | "; - print "User RegExp | "; - print "Use For Bugs | "; - print "Type | "; - print "Action | "; - print "
---|---|---|---|---|---|
" . html_quote($name) . " | \n"; - print "" . html_quote($desc) . " | \n"; - print "" . html_quote($regexp) . "  | \n"; - print ""; - print "X" if (($isactive != 0) && ($isbuggroup != 0)); - print "  | \n"; - print "  "; - print (($isbuggroup == 0 ) ? "system" : "user"); - print "  | \n"; - print "- Edit"; - print " | Delete" if ($isbuggroup != 0); - print " |
\n"; - print " | Add Group | \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 with an -email address that matches this perl regular expression. Do not forget the trailing \'\$\'. Example \'\@mycompany\\.com\$\'
"; - print "The Use For Bugs flag determines whether or not the group is eligible to be used for bugs. -If you remove this flag, it will no longer be possible for users to add bugs -to this group, although bugs already in the group will remain in the group. -Doing so is a much less drastic way to stop a group from growing -than deleting the group as well as a way to maintain lists of users without cluttering the lists of groups used for bug restrictions.
"; - print "The Type field identifies system groups.
";
-
- PutFooter();
+ $vars->{'groups'} = \@groups;
+
+ print Bugzilla->cgi->header();
+ $template->process("admin/groups/list.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
+
exit;
}
-#
#
# action='changeform' -> present form for altering an existing group
#
@@ -194,75 +121,21 @@ than deleting the group as well as a way to maintain lists of users without clut
#
if ($action eq 'changeform') {
- PutHeader("Change Group");
-
- my $gid = trim($::FORM{group} || '');
+ my $gid = trim($cgi->param('group') || '');
+ ThrowUserError("group_not_specified") unless ($gid);
detaint_natural($gid);
- unless ($gid) {
- ShowError("No group specified.
" .
- "Click the Back button and try again.");
- PutFooter();
- exit;
- }
SendSQL("SELECT id, name, description, userregexp, isactive, isbuggroup
- FROM groups WHERE id=$gid");
+ FROM groups WHERE id = $gid");
my ($group_id, $name, $description, $rexp, $isactive, $isbuggroup)
= FetchSQLData();
- print "
\n";
- PutTrailer("add another group",
- "back to the group list");
+
+ print Bugzilla->cgi->header();
+ $template->process("admin/groups/created.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
exit;
}
@@ -422,96 +266,58 @@ if ($action eq 'new') {
#
if ($action eq 'del') {
- PutHeader("Delete group");
- my $gid = trim($::FORM{group} || '');
+ my $gid = trim($cgi->param('group') || '');
+ ThrowUserError("group_not_specified") unless ($gid);
detaint_natural($gid);
- unless ($gid) {
- ShowError("No group specified.
" .
- "Click the Back button and try again.");
- PutFooter();
- exit;
- }
+
SendSQL("SELECT id FROM groups WHERE id=$gid");
- if (!FetchOneColumn()) {
- ShowError("That group doesn't exist.
" .
- "Click the Back button and try again.");
- PutFooter();
- exit;
- }
+ ThrowUserError("invalid_group_ID") unless FetchOneColumn();
+
SendSQL("SELECT name,description " .
"FROM groups " .
- "WHERE id=$gid");
+ "WHERE id = $gid");
my ($name, $desc) = FetchSQLData();
- print "
Id | "; - print "Name | "; - print "Description | "; - print "
---|---|---|
$gid | \n"; - print "$name | \n"; - print "$desc | \n"; - print "
\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;
+ my $action;
+
+ if ($cgi->param('remove_explicit_members')) {
+ $action = 1;
+ } elsif ($cgi->param('remove_explicit_members_regexp')) {
+ $action = 2;
+ } else {
+ $action = 3;
}
- # 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";
+ $vars->{'action'} = $action;
+ $vars->{'changes'} = $chgs;
+ $vars->{'gid'} = $gid;
+ $vars->{'name'} = $cgi->param('name');
+ if ($action == 2) {
+ $vars->{'regexp'} = $cgi->param("rexp");
}
- PutTrailer("back to the group list");
+
+ print Bugzilla->cgi->header();
+ $template->process("admin/groups/change.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
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
+ # remove all explicit users from the group with gid $cgi->param('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 $gid = $cgi->param('group');
+ ThrowUserError("group_not_specified") unless ($gid);
detaint_natural($gid);
+
+ my $dbh = Bugzilla->dbh;
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,
@@ -653,157 +432,115 @@ if (($action eq 'remove_all_regexp') || ($action eq 'remove_all')) {
AND grant_type = ?
AND isbless = 0");
$sth->execute($gid, GRANT_DIRECT);
+
+ my @users;
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";
+
+ my $user = {};
+ $user->{'login'} = $userlogin;
+ push(@users, $user);
}
}
- 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;
-}
+ $vars->{'users'} = \@users;
+ $vars->{'name'} = $name;
+ $vars->{'regexp'} = $regexp;
+ $vars->{'remove_all'} = ($action eq 'remove_all');
+ $vars->{'gid'} = $gid;
+
+ print Bugzilla->cgi->header();
+ $template->process("admin/groups/remove.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
+ exit;
+}
#
# No valid action found
#
-PutHeader("Error");
-print "I don't have a clue what you want.
\n";
+ThrowCodeError("action_unrecognized", $vars);
-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 "
"; -} # Helper sub to handle the making of changes to a group sub doGroupChanges { - my $gid = trim($::FORM{group} || ''); + my $cgi = Bugzilla->cgi; + + my $gid = trim($cgi->param('group') || ''); + ThrowUserError("group_not_specified") unless ($gid); detaint_natural($gid); - unless ($gid) { - ShowError("No group specified.+ Checking.... + + [% IF changes %] + changed. + [% END %] +
+ +[% IF (action == 1) || (action == 2) %] + [% IF changes %] +Group updated, please confirm removal:
+ [% END %] + + [% IF (action == 1) %] +This option will remove all explicitly defined users + [% ELSIF regexp %] +
This option will remove all users included in the regular expression: + [% regexp FILTER html %] + [% ELSE %] +
+ There is no regular expression defined. + No users will be removed. +
+ [% END %] + + [% IF ((action == 1) || regexp) %] + from group [% name FILTER html %]. + ++ Generally, you will only need to do this when upgrading groups + created with [% terms.Bugzilla %] versions 2.16 and prior. Use + this option with extreme care and consult the documentation + for further information. +
+ + + [% END %] +[% ELSE %] + [%# if we got this far, the admin doesn't want to convert, so just save + # their changes %] + + [% IF changes %] +Done.
+ [% ELSE %] ++ You didn't change anything! If you really meant it, hit the Back + button and try again. +
+ [% END %] + +Back to the group list.
+[% END %] + +[% PROCESS global/footer.html.tmpl %] diff --git a/template/en/default/admin/groups/create.html.tmpl b/template/en/default/admin/groups/create.html.tmpl index 239d7f9840..8da00a7994 100644 --- a/template/en/default/admin/groups/create.html.tmpl +++ b/template/en/default/admin/groups/create.html.tmpl @@ -20,7 +20,10 @@ # Joel PeshkinOK, done.
+ +Add another group or +go back to the group list.
+ +[% PROCESS global/footer.html.tmpl %] diff --git a/template/en/default/admin/groups/delete.html.tmpl b/template/en/default/admin/groups/delete.html.tmpl new file mode 100644 index 0000000000..0e17cbb1cc --- /dev/null +++ b/template/en/default/admin/groups/delete.html.tmpl @@ -0,0 +1,100 @@ +[%# 1.0@bugzilla.org %] +[%# 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 MillerId | +Name | +Description | +
---|---|---|
[% gid FILTER html %] | +[% name FILTER html %] | +[% desc FILTER html %] | +
+ This group cannot be deleted because there are records + in the database which refer to it. All such records + must be removed or altered to remove the reference to this + group before the group can be deleted. +
+ ++ View + the list of which records are affected. +
+[% ELSE %] +The group [% name FILTER html %] has been deleted.
+[% END %] + +Go back to the group list.
+
+[% PROCESS global/footer.html.tmpl %]
diff --git a/template/en/default/admin/groups/edit.html.tmpl b/template/en/default/admin/groups/edit.html.tmpl
new file mode 100644
index 0000000000..619db777c3
--- /dev/null
+++ b/template/en/default/admin/groups/edit.html.tmpl
@@ -0,0 +1,159 @@
+[%# 1.0@bugzilla.org %]
+[%# 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
Members of these groups can grant membership to this group | +|||
| | +Members of these groups are included in this group | +||
| | +| | ++ | |
+ + + | ++ + + | +[% group.grpnam FILTER html %] | +[% group.grpdesc FILTER html %] | +
+
+ Conversion of groups created with [% terms.Bugzilla %] + versions 2.16 and prior: + +
|
+
Name | +Description | +User RegExp | +Use For [% terms.Bugs %] | +Type | +Action | +
---|---|---|---|---|---|
[% group.name FILTER html %] | +[% group.description FILTER html %] | +[% group.regexp FILTER html %]  | + ++ [% IF (group.isactive != 0) && (group.isbuggroup) %] + X + [% ELSE %] +   + [% END %] + | + ++ [% (group.isbuggroup) ? "user" : "system" %] + | + ++ Edit + [% IF (group.isbuggroup) %] + | Delete + [% END %] + | +
+ | Add Group | +
+ 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 [% terms.bugs %] by email to limit [% terms.abug %] +to a certain set of groups. +
+ ++ Description is what will be shown in the [% terms.bug %] reports +to members of the group where they can choose whether the [% terms.bug %] +will be restricted to others in the same group. +
+ ++ User RegExp is optional, and if filled in, will automatically +grant membership to this group to anyone with an email address +that matches this perl regular expression. Do not forget +the trailing '$'. Example '@mycompany\.com$' +
+ ++ The Use For [% terms.Bugs %] flag determines whether or not +the group is eligible to be used for [% terms.bugs %]. If you remove +this flag, it will no longer be possible for users to add [% terms.bugs %] +to this group, although [% terms.bugs %] already in the group will remain +in the group. Doing so is a much less drastic way to stop a group +from growing than deleting the group as well as a way to maintain +lists of users without cluttering the lists of groups used +for [% terms.bug %] restrictions. +
+ ++ The Type field identifies system groups. +
+ +[% PROCESS global/footer.html.tmpl %] diff --git a/template/en/default/admin/groups/remove.html.tmpl b/template/en/default/admin/groups/remove.html.tmpl new file mode 100644 index 0000000000..0eed2d9fbe --- /dev/null +++ b/template/en/default/admin/groups/remove.html.tmpl @@ -0,0 +1,60 @@ +[%# 1.0@bugzilla.org %] +[%# 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 MillerRemoving explicit membership
+[% ELSE %] +Removing explicit memberships of users matching + '[% regexp FILTER html %]'...
+[% END %] + +[% FOREACH user = users %] + [% user.login FILTER html %] removedDone.
+ +Back to the group list.
+ +[% PROCESS global/footer.html.tmpl %] diff --git a/template/en/default/global/code-error.html.tmpl b/template/en/default/global/code-error.html.tmpl index c5233b8e88..ae47ed3495 100644 --- a/template/en/default/global/code-error.html.tmpl +++ b/template/en/default/global/code-error.html.tmpl @@ -61,6 +61,10 @@ The ID[% page_id FILTER html %]
is not a
valid page identifier.
+ [% ELSIF error == "bad_arg" %]
+ Bad argument [% argument FILTER html %]
sent to
+ [% function FILTER html %]
function.
+
[% ELSIF error == "bug_error" %]
Trying to retrieve [% terms.bug %] [%+ bug.bug_id FILTER html %] returned
the error [% bug.error FILTER html %].
@@ -104,10 +108,6 @@
Attempted to add [% terms.bug %] to an inactive group, identified by the bit
'[% bit FILTER html %]'.
- [% ELSIF error == "bad_arg" %]
- Bad argument [% argument FILTER html %]
sent to
- [% function FILTER html %]
function.
-
[% ELSIF error == "invalid_attach_id_to_obsolete" %]
The attachment number of one of the attachments you wanted to obsolete,
[% attach_id FILTER html %], is invalid.
@@ -131,7 +131,12 @@
[% ELSIF error == "invalid_dimensions" %]
[% title = "Invalid Dimensions" %]
The width or height specified is not a positive integer.
-
+
+ [% ELSIF error == "invalid_isactive_flag" %]
+ [% title = "Invalid isactive flag" %]
+ The active flag was improperly set. There may be
+ a problem with [% terms.Bugzilla %] or [% terms.abug %] in your browser.
+
[% ELSIF error == "invalid_series_id" %]
[% title = "Invalid Series" %]
The series_id [% series_id FILTER html %] is not valid. It may be that
diff --git a/template/en/default/global/user-error.html.tmpl b/template/en/default/global/user-error.html.tmpl
index e4c9863df7..97987b786b 100644
--- a/template/en/default/global/user-error.html.tmpl
+++ b/template/en/default/global/user-error.html.tmpl
@@ -96,6 +96,11 @@
account creation. Please contact an administrator to get a new account
created.
+ [% ELSIF error == "auth_cant_edit_groups" %]
+ [% title = "Not authorized to edit groups" %]
+ Sorry, you aren't a member of the 'creategroups' group. And so,
+ you aren't allowed to edit the groups.
+
[% ELSIF error == "authorization_failure" %]
[% title = "Authorization Failed" %]
You are not allowed to [% action FILTER html %].
@@ -169,6 +174,14 @@
[% title = "Email Address Confirmation Failed" %]
Email address confirmation failed.
+ [% ELSIF error == "empty_group_description" %]
+ [% title = "The group description can not be empty" %]
+ You must enter a description for the new group.
+
+ [% ELSIF error == "empty_group_name" %]
+ [% title = "The group name can not be empty" %]
+ You must enter a name for the new group.
+
[% ELSIF error == "entry_access_denied" %]
[% title = "Permission Denied" %]
Sorry; you do not have the permissions necessary to enter [% terms.abug %]
@@ -235,7 +248,15 @@
[% title = "Flag Type Sort Key Invalid" %]
The sort key must be an integer between 0 and 32767 inclusive.
It cannot be [% sortkey FILTER html %].
-
+
+ [% ELSIF error == "group_exists" %]
+ [% title = "The group already exists" %]
+ The group [% name FILTER html %] already exists.
+
+ [% ELSIF error == "group_not_specified" %]
+ [% title = "Group not specified" %]
+ No group was specified.
+
[% ELSIF error == "illegal_at_least_x_votes" %]
[% title = "Your Search Makes No Sense" %]
The At least ___ votes field must be a simple number.
@@ -370,6 +391,10 @@
[% END %]
).
+ [% ELSIF error == "invalid_group_ID" %]
+ [% title = "Invalid group ID" %]
+ The group you specified doesn't exist.
+
[% ELSIF error == "invalid_maxrows" %]
[% title = "Invalid Max Rows" %]
The maximum number of rows, '[% maxrows FILTER html %]', must be
@@ -378,7 +403,11 @@
[% ELSIF error == "invalid_product_name" %]
[% title = "Invalid Product Name" %]
The product name '[% product FILTER html %]' is invalid or does not exist.
-
+
+ [% ELSIF error == "invalid_regexp" %]
+ [% title = "Invalid regular expression" %]
+ The regular expression you entered is invalid.
+
[% ELSIF error == "invalid_username" %]
[% title = "Invalid Username" %]
The name [% name FILTER html %] is not a valid username.