Bug 110013 - templatize describecomponents.cgi

r=gerv, afranke
parent 9d2a3d8f
...@@ -38,6 +38,7 @@ sub bug_form_pl_sillyness { ...@@ -38,6 +38,7 @@ sub bug_form_pl_sillyness {
$zz = %::proddesc; $zz = %::proddesc;
$zz = %::prodmaxvotes; $zz = %::prodmaxvotes;
$zz = %::versions; $zz = %::versions;
$zz = @::enterable_products;
$zz = @::legal_keywords; $zz = @::legal_keywords;
$zz = @::legal_opsys; $zz = @::legal_opsys;
$zz = @::legal_platform; $zz = @::legal_platform;
...@@ -156,20 +157,17 @@ if (defined $URL && $URL ne "none" && $URL ne "NULL" && $URL ne "") { ...@@ -156,20 +157,17 @@ if (defined $URL && $URL ne "none" && $URL ne "NULL" && $URL ne "") {
# #
my (@prodlist, $product_popup); my (@prodlist, $product_popup);
foreach my $p (sort(keys %::versions)) { my $seen_currProd = 0;
foreach my $p (@::enterable_products) {
if ($p eq $bug{'product'}) { if ($p eq $bug{'product'}) {
# if it's the product the bug is already in, it's ALWAYS in # if it's the product the bug is already in, it's ALWAYS in
# the popup, period, whether the user can see it or not, and # the popup, period, whether the user can see it or not, and
# regardless of the disallownew setting. # regardless of the disallownew setting.
$seen_currProd = 1;
push(@prodlist, $p); push(@prodlist, $p);
next; next;
} }
if (defined $::proddesc{$p} && $::proddesc{$p} eq '0') {
# Special hack. If we stuffed a "0" into proddesc, that means
# that disallownew was set for this bug, and so we don't want
# to allow people to specify that product here.
next;
}
if(Param("usebuggroupsentry") if(Param("usebuggroupsentry")
&& GroupExists($p) && GroupExists($p)
&& !UserInGroup($p)) && !UserInGroup($p))
...@@ -182,6 +180,13 @@ foreach my $p (sort(keys %::versions)) { ...@@ -182,6 +180,13 @@ foreach my $p (sort(keys %::versions)) {
push(@prodlist, $p); push(@prodlist, $p);
} }
# The current product is part of the popup, even if new bugs are no longer
# allowed for that product
if (!$seen_currProd) {
push (@prodlist, $bug{'product'});
@prodlist = sort @prodlist;
}
# If the user has access to multiple products, display a popup, otherwise # If the user has access to multiple products, display a popup, otherwise
# display the current product. # display the current product.
......
...@@ -19,8 +19,12 @@ ...@@ -19,8 +19,12 @@
# Rights Reserved. # Rights Reserved.
# #
# Contributor(s): Terry Weissman <terry@mozilla.org> # Contributor(s): Terry Weissman <terry@mozilla.org>
# Bradley Baetz <bbaetz@student.usyd.edu.au>
use vars %::FORM; use vars qw(
%FORM
$userid
);
use diagnostics; use diagnostics;
use strict; use strict;
...@@ -32,120 +36,93 @@ require "CGI.pl"; ...@@ -32,120 +36,93 @@ require "CGI.pl";
ConnectToDatabase(); ConnectToDatabase();
GetVersionTable(); GetVersionTable();
quietly_check_login(); if (!defined $::FORM{'product'}) {
# Reference to a subset of %::proddesc, which the user is allowed to see
my %products;
if (Param("usebuggroups")) {
# OK, now only add products the user can see
confirm_login();
foreach my $p (@::legal_product) {
if (!GroupExists($p) || UserInGroup($p)) {
$products{$p} = $::proddesc{$p};
}
}
}
else {
%products = %::proddesc;
}
###################################################################### my $prodsize = scalar(keys %products);
# Begin Data/Security Validation if ($prodsize == 0) {
###################################################################### DisplayError("Either no products have been defined ".
"or you have not been given access to any.\n");
exit;
}
elsif ($prodsize > 1) {
$::vars->{'proddesc'} = \%products;
$::vars->{'target'} = "describecomponents.cgi";
$::vars->{'title'} = "Bugzilla component description";
$::vars->{'h2'} =
"Please specify the product whose components you want described.";
print "Content-type: text/html\n\n";
$::template->process("global/choose_product.tmpl", $::vars)
|| DisplayError("Template process failed: " . $::template->error());
exit;
}
# If this installation uses bug groups to restrict access to products, $::FORM{'product'} = (keys %::proddesc)[0];
# only show the user products that don't have their own bug group or
# those whose bug group the user is a member of. Otherwise, if this
# installation doesn't use bug groups, show the user all legal products.
my @products;
if ( Param("usebuggroups") ) {
@products = grep( !GroupExists($_) || UserInGroup($_) , @::legal_product );
} else {
@products = @::legal_product;
} }
if ( defined $::FORM{'product'} ) { my $product = $::FORM{'product'};
# Make sure the user specified a valid product name. Note that
# if the user specifies a valid product name but is not authorized # Make sure the user specified a valid product name. Note that
# to access that product, they will receive a different error message # if the user specifies a valid product name but is not authorized
# which could enable people guessing product names to determine # to access that product, they will receive a different error message
# whether or not certain products exist in Bugzilla, even if they # which could enable people guessing product names to determine
# cannot get any other information about that product. # whether or not certain products exist in Bugzilla, even if they
grep( $::FORM{'product'} eq $_ , @::legal_product ) # cannot get any other information about that product.
|| DisplayError("The product name is invalid.") grep($product eq $_ , @::legal_product)
&& exit; || DisplayError("The product name is invalid.")
&& exit;
# Make sure the user is authorized to access this product.
if ( Param("usebuggroups") && GroupExists($::FORM{'product'}) ) { # Make sure the user is authorized to access this product.
UserInGroup($::FORM{'product'}) if (Param("usebuggroups") && GroupExists($product) && !$::userid) {
confirm_login();
UserInGroup($product)
|| DisplayError("You are not authorized to access that product.") || DisplayError("You are not authorized to access that product.")
&& exit; && exit;
}
} }
###################################################################### ######################################################################
# End Data/Security Validation # End Data/Security Validation
###################################################################### ######################################################################
print "Content-type: text/html\n\n"; my @components;
SendSQL("SELECT value, initialowner, initialqacontact, description FROM " .
my $product = $::FORM{'product'}; "components WHERE program = " . SqlQuote($product) . " ORDER BY " .
if (!defined $product || lsearch(\@products, $product) < 0) { "value");
while (MoreSQLData()) {
PutHeader("Bugzilla component description"); my ($name, $initialowner, $initialqacontact, $description) =
print " FetchSQLData();
<FORM>
Please specify the product whose components you want described.
<P>
Product: <SELECT NAME=product>
";
print make_options(\@products);
print "
</SELECT>
<P>
<INPUT TYPE=\"submit\" VALUE=\"Submit\">
</FORM>
";
PutFooter();
exit;
}
PutHeader("Bugzilla component description", "Bugzilla component description",
$product);
print " my %component;
<TABLE>
<tr>
<th align=left>Component</th>
<th align=left>Default owner</th>
";
my $emailsuffix = Param("emailsuffix"); $component{'name'} = $name;
my $useqacontact = Param("useqacontact"); $component{'initialowner'} = $initialowner ?
DBID_to_name($initialowner) : '';
$component{'initialqacontact'} = $initialqacontact ?
DBID_to_name($initialqacontact) : '';
$component{'description'} = $description;
my $cols = 2; push @components, \%component;
if ($useqacontact) {
print "<th align=left>Default qa contact</th>";
$cols++;
} }
my $colbut1 = $cols - 1; $::vars->{'product'} = $product;
$::vars->{'components'} = \@components;
print "</tr>"; print "Content-type: text/html\n\n";
$::template->process("info/describe-components.tmpl", $::vars)
SendSQL("select value, initialowner, initialqacontact, description from components where program = " . SqlQuote($product) . " order by value"); || DisplayError("Template process failed: " . $::template->error());
my @data;
while (MoreSQLData()) {
push @data, [FetchSQLData()];
}
foreach (@data) {
my ($component, $initialownerid, $initialqacontactid, $description) = @$_;
my ($initialowner, $initialqacontact) = ($initialownerid ? DBID_to_name ($initialownerid) : '',
$initialqacontactid ? DBID_to_name ($initialqacontactid) : '');
print qq|
<tr><td colspan=$cols><hr></td></tr>
<tr><td rowspan=2><a name="|
.value_quote($component).
qq|">$component</a></td>
<td><a href="mailto:$initialowner$emailsuffix">$initialowner</a></td>
|;
if ($useqacontact) {
print qq|
<td><a href="mailto:$initialqacontact$emailsuffix">$initialqacontact</a></td>
|;
}
print "</tr><tr><td colspan=$colbut1>$description</td></tr>\n";
}
print "<tr><td colspan=$cols><hr></td></tr></table>\n";
PutFooter();
...@@ -44,11 +44,13 @@ use vars qw( ...@@ -44,11 +44,13 @@ use vars qw(
$template $template
$vars $vars
%COOKIE %COOKIE
@enterable_products
@legal_opsys @legal_opsys
@legal_platform @legal_platform
@legal_priority @legal_priority
@legal_severity @legal_severity
%MFORM %MFORM
%versions
); );
# If we're using bug groups to restrict bug entry, we need to know who the # If we're using bug groups to restrict bug entry, we need to know who the
...@@ -58,28 +60,25 @@ confirm_login() if (Param("usebuggroupsentry")); ...@@ -58,28 +60,25 @@ confirm_login() if (Param("usebuggroupsentry"));
if (!defined $::FORM{'product'}) { if (!defined $::FORM{'product'}) {
GetVersionTable(); GetVersionTable();
foreach my $p (sort(keys(%::versions))) { my %products;
# Special hack: "0" in proddesc means disallownew was set.
# Also, if we're using bug groups to restrict entry on products, foreach my $p (@enterable_products) {
# and this product has a bug group, and the user is not in that if (!(Param("usebuggroupsentry")
# group, we don't want to include that product in this list. && GroupExists($p)
if ((defined $::proddesc{$p} && $::proddesc{$p} eq '0') && !UserInGroup($p)))
|| (Param("usebuggroupsentry")
&& GroupExists($p)
&& !UserInGroup($p)))
{ {
delete $::proddesc{$p}; $products{$p} = $::proddesc{$p};
} }
} }
my $prodsize = scalar(keys %::proddesc); my $prodsize = scalar(keys %products);
if ($prodsize == 0) { if ($prodsize == 0) {
DisplayError("Either no products have been defined to enter bugs ". DisplayError("Either no products have been defined to enter bugs ".
"against or you have not been given access to any.\n"); "against or you have not been given access to any.\n");
exit; exit;
} }
elsif ($prodsize > 1) { elsif ($prodsize > 1) {
$vars->{'proddesc'} = \%::proddesc; $vars->{'proddesc'} = \%products;
$vars->{'target'} = "enter_bug.cgi"; $vars->{'target'} = "enter_bug.cgi";
$vars->{'title'} = "Enter Bug"; $vars->{'title'} = "Enter Bug";
...@@ -92,7 +91,7 @@ if (!defined $::FORM{'product'}) { ...@@ -92,7 +91,7 @@ if (!defined $::FORM{'product'}) {
exit; exit;
} }
$::FORM{'product'} = (keys %::proddesc)[0]; $::FORM{'product'} = (keys %products)[0];
$::MFORM{'product'} = [$::FORM{'product'}]; $::MFORM{'product'} = [$::FORM{'product'}];
} }
...@@ -229,7 +228,7 @@ if(Param("usebuggroupsentry") ...@@ -229,7 +228,7 @@ if(Param("usebuggroupsentry")
GetVersionTable(); GetVersionTable();
if (!defined($::proddesc{$product}) || $::proddesc{$product} eq "0") { if (lsearch(\@::enterable_products, $product) == -1) {
DisplayError("'" . html_quote($product) . "' is not a valid product."); DisplayError("'" . html_quote($product) . "' is not a valid product.");
exit; exit;
} }
...@@ -320,7 +319,7 @@ if ($::usergroupset ne '0') { ...@@ -320,7 +319,7 @@ if ($::usergroupset ne '0') {
my ($bit, $prodname, $description) = FetchSQLData(); my ($bit, $prodname, $description) = FetchSQLData();
# Don't want to include product groups other than this product. # Don't want to include product groups other than this product.
next unless($prodname eq $product || next unless($prodname eq $product ||
!defined($::proddesc{$prodname})); !defined($::proddesc{$prodname}));
my $check; my $check;
......
...@@ -38,6 +38,7 @@ sub globals_pl_sillyness { ...@@ -38,6 +38,7 @@ sub globals_pl_sillyness {
$zz = @main::default_column_list; $zz = @main::default_column_list;
$zz = $main::defaultqueryname; $zz = $main::defaultqueryname;
$zz = @main::dontchange; $zz = @main::dontchange;
$zz = @main::enterable_products;
$zz = %main::keywordsbyname; $zz = %main::keywordsbyname;
$zz = @main::legal_bug_status; $zz = @main::legal_bug_status;
$zz = @main::legal_components; $zz = @main::legal_components;
...@@ -50,6 +51,7 @@ sub globals_pl_sillyness { ...@@ -50,6 +51,7 @@ sub globals_pl_sillyness {
$zz = @main::legal_target_milestone; $zz = @main::legal_target_milestone;
$zz = @main::legal_versions; $zz = @main::legal_versions;
$zz = @main::milestoneurl; $zz = @main::milestoneurl;
$zz = %main::proddesc;
$zz = @main::prodmaxvotes; $zz = @main::prodmaxvotes;
$zz = $main::superusergroupset; $zz = $main::superusergroupset;
$zz = $main::userid; $zz = $main::userid;
...@@ -492,16 +494,13 @@ sub GenerateVersionTable { ...@@ -492,16 +494,13 @@ sub GenerateVersionTable {
# about them anyway. # about them anyway.
my $mpart = $dotargetmilestone ? ", milestoneurl" : ""; my $mpart = $dotargetmilestone ? ", milestoneurl" : "";
SendSQL("select product, description, votesperuser, disallownew$mpart from products"); SendSQL("select product, description, votesperuser, disallownew$mpart from products ORDER BY product");
$::anyvotesallowed = 0; $::anyvotesallowed = 0;
while (@line = FetchSQLData()) { while (@line = FetchSQLData()) {
my ($p, $d, $votesperuser, $dis, $u) = (@line); my ($p, $d, $votesperuser, $dis, $u) = (@line);
$::proddesc{$p} = $d; $::proddesc{$p} = $d;
if ($dis) { if (!$dis) {
# Special hack. Stomp on the description and make it "0" if we're push @::enterable_products, $p;
# not supposed to allow new bugs against this product. This is
# checked for in enter_bug.cgi.
$::proddesc{$p} = "0";
} }
if ($dotargetmilestone) { if ($dotargetmilestone) {
$::milestoneurl{$p} = $u; $::milestoneurl{$p} = $u;
...@@ -579,6 +578,7 @@ sub GenerateVersionTable { ...@@ -579,6 +578,7 @@ sub GenerateVersionTable {
} }
print FID GenerateCode('@::settable_resolution'); print FID GenerateCode('@::settable_resolution');
print FID GenerateCode('%::proddesc'); print FID GenerateCode('%::proddesc');
print FID GenerateCode('@::enterable_products');
print FID GenerateCode('%::prodmaxvotes'); print FID GenerateCode('%::prodmaxvotes');
print FID GenerateCode('$::anyvotesallowed'); print FID GenerateCode('$::anyvotesallowed');
...@@ -1294,8 +1294,10 @@ sub UserInGroup { ...@@ -1294,8 +1294,10 @@ sub UserInGroup {
return 0; return 0;
} }
ConnectToDatabase(); ConnectToDatabase();
PushGlobalSQLState();
SendSQL("select (bit & $::usergroupset) != 0 from groups where name = " . SqlQuote($groupname)); SendSQL("select (bit & $::usergroupset) != 0 from groups where name = " . SqlQuote($groupname));
my $bit = FetchOneColumn(); my $bit = FetchOneColumn();
PopGlobalSQLState();
if ($bit) { if ($bit) {
return 1; return 1;
} }
......
[%# 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): Bradley Baetz <bbaetz@student.usyd.edu.au>
#%]
[% INCLUDE global/header
title = "Components for $product"
h2 = product %]
[% IF Param("useqacontact") %]
[% numcols = 3 %]
[% ELSE %]
[% numcols = 2 %]
[% END %]
[% IF components.size == 0 %]
This product has no components.
[% ELSE %]
<table>
<tr>
<th align="left">Component</th>
<th align="left">Default Owner</th>
[% IF Param("useqacontact") %]
<th align="left">Default QA Contact</th>
[% END %]
</tr>
[% FOREACH comp = components.sort %]
[% INCLUDE describe_comp %]
[% END %]
<tr>
<td colspan='[% numcols %]'>
<hr>
</td>
</tr>
</table>
[% END %]
[% INCLUDE global/footer %]
[%############################################################################%]
[%# BLOCK for components %]
[%############################################################################%]
[% BLOCK describe_comp %]
<tr>
<td colspan="[% numcols %]">
<hr>
</td>
</tr>
<tr>
<td rowspan='2'>
<a name="[% comp.name FILTER html %]">[% comp.name FILTER html %]</a>
</td>
<td>
<a href="mailto:[% comp.initialowner %][% Param('emailsuffix') %]">
[% comp.initialowner %]</a>
</td>
[% IF Param("useqacontact") %]
<td>
<a href="mailto:[% comp.initialqacontact %][% Param('emailsuffix') %]">
[% comp.initialqacontact %]</a>
</td>
[% END %]
</tr>
<tr>
<td colspan="[% numcols - 1 %]">
[% comp.description %]
</td>
</tr>
[% END %]
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