Commit 577a3b35 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 311422: describecomponents.cgi and enter_bug.cgi need some cleanup - Patch…

Bug 311422: describecomponents.cgi and enter_bug.cgi need some cleanup - Patch by Frédéric Buclin <LpSolit@gmail.com> r=wicked a=myk
parent 0f3a9f4b
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
# #
# Contributor(s): Terry Weissman <terry@mozilla.org> # Contributor(s): Terry Weissman <terry@mozilla.org>
# Bradley Baetz <bbaetz@student.usyd.edu.au> # Bradley Baetz <bbaetz@student.usyd.edu.au>
# Frédéric Buclin <LpSolit@gmail.com>
use strict; use strict;
use lib qw(.); use lib qw(.);
...@@ -27,83 +28,59 @@ use lib qw(.); ...@@ -27,83 +28,59 @@ use lib qw(.);
use Bugzilla; use Bugzilla;
use Bugzilla::Constants; use Bugzilla::Constants;
require "globals.pl"; require "globals.pl";
use Bugzilla::Product;
use vars qw(@legal_product);
my $user = Bugzilla->login(); my $user = Bugzilla->login();
GetVersionTable();
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
my $template = Bugzilla->template; my $template = Bugzilla->template;
my $vars = {}; my $vars = {};
my $product = trim($cgi->param('product') || '');
my $product_id = get_product_id($product);
if (!$product_id || !$user->can_enter_product($product)) { print $cgi->header();
my $product_name = trim($cgi->param('product') || '');
my $product = new Bugzilla::Product({'name' => $product_name});
unless ($product && $user->can_enter_product($product->name)) {
# Products which the user is allowed to see. # Products which the user is allowed to see.
my @products = @{$user->get_enterable_products()}; my @products = @{$user->get_enterable_products};
if (scalar(@products) == 0) { if (scalar(@products) == 0) {
ThrowUserError("no_products"); ThrowUserError("no_products");
} }
elsif (scalar(@products) > 1) { # If there is only one product available but the user entered
# XXX - For backwards-compatibility with old template # another product name, we display a list with this single
# interfaces, we now create a proddesc hash. This can go away # product only, to not confuse the user with components of a
# once we update the templates. # product he didn't request.
my %product_desc; elsif (scalar(@products) > 1 || $product_name) {
foreach my $product (@products) { $vars->{'products'} = \@products;
$product_desc{$product->name} = $product->description;
}
$vars->{'proddesc'} = \%product_desc;
$vars->{'target'} = "describecomponents.cgi"; $vars->{'target'} = "describecomponents.cgi";
# If an invalid product name is given, or the user is not # If an invalid product name is given, or the user is not
# allowed to access that product, a message is displayed # allowed to access that product, a message is displayed
# with a list of the products the user can choose from. # with a list of the products the user can choose from.
if ($product) { if ($product_name) {
$vars->{'message'} = "product_invalid"; $vars->{'message'} = "product_invalid";
$vars->{'product'} = $product; # Do not use $product->name here, else you could use
# this way to determine whether the product exists or not.
$vars->{'product'} = $product_name;
} }
print $cgi->header();
$template->process("global/choose-product.html.tmpl", $vars) $template->process("global/choose-product.html.tmpl", $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
exit; exit;
} }
# Else, if there is only one product: # If there is only one product available and the user didn't specify
$product = $products[0]->name; # any product name, we show this product.
$product_id = $products[0]->id; $product = $products[0];
} }
###################################################################### ######################################################################
# End Data/Security Validation # End Data/Security Validation
###################################################################### ######################################################################
my @components;
my $comps = $dbh->selectall_arrayref(
q{SELECT name, initialowner, initialqacontact, description
FROM components
WHERE product_id = ?
ORDER BY name}, undef, $product_id);
foreach my $comp (@$comps) {
my ($name, $initialowner, $initialqacontact, $description) = @$comp;
my %component;
$component{'name'} = $name;
$component{'initialowner'} = $initialowner ?
DBID_to_name($initialowner) : '';
$component{'initialqacontact'} = $initialqacontact ?
DBID_to_name($initialqacontact) : '';
$component{'description'} = $description;
push @components, \%component;
}
$vars->{'product'} = $product; $vars->{'product'} = $product;
$vars->{'components'} = \@components;
print $cgi->header();
$template->process("reports/components.html.tmpl", $vars) $template->process("reports/components.html.tmpl", $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
...@@ -43,11 +43,11 @@ use Bugzilla::Bug; ...@@ -43,11 +43,11 @@ use Bugzilla::Bug;
use Bugzilla::User; use Bugzilla::User;
use Bugzilla::Hook; use Bugzilla::Hook;
use Bugzilla::Product; use Bugzilla::Product;
use Bugzilla::Classification;
use Bugzilla::Keyword; use Bugzilla::Keyword;
require "globals.pl"; require "globals.pl";
use vars qw( use vars qw(
@enterable_products
@legal_opsys @legal_opsys
@legal_platform @legal_platform
@legal_priority @legal_priority
...@@ -66,95 +66,74 @@ my $cgi = Bugzilla->cgi; ...@@ -66,95 +66,74 @@ my $cgi = Bugzilla->cgi;
my $template = Bugzilla->template; my $template = Bugzilla->template;
my $vars = {}; my $vars = {};
my $product = $cgi->param('product'); my $product = trim($cgi->param('product') || '');
if (!defined $product || $product eq "") { if ($product eq '') {
GetVersionTable(); my $user = Bugzilla->login();
Bugzilla->login();
if ( ! Param('useclassification') ) { # If the user cannot enter bugs in any product, stop here.
# Just use a fake value for the Classification. my @enterable_products = @{$user->get_enterable_products};
$cgi->param(-name => 'classification', ThrowUserError('no_products') unless scalar(@enterable_products);
-value => '__all');
}
if (!$cgi->param('classification')) { my $classification = Param('useclassification') ?
my $classifications = Bugzilla->user->get_selectable_classifications(); scalar($cgi->param('classification')) : '__all';
foreach my $classification (@$classifications) {
my $found = 0; unless ($classification) {
foreach my $p (@enterable_products) { my $class;
if (Bugzilla->user->can_enter_product($p) # Get all classifications with at least one enterable product.
&& IsInClassification($classification->{name},$p)) { foreach $product (@enterable_products) {
$found = 1; $class->{$product->classification_id} ||=
} new Bugzilla::Classification($product->classification_id);
}
if ($found == 0) {
@$classifications = grep($_->{name} ne $classification->{name},
@$classifications);
}
} }
my @classifications = sort {lc($a->name) cmp lc($b->name)} (values %$class);
if (scalar(@$classifications) == 0) { # We know there is at least one classification available,
ThrowUserError("no_products"); # else we would have stopped earlier.
} if (scalar(@classifications) > 1) {
elsif (scalar(@$classifications) > 1) { $vars->{'classifications'} = \@classifications;
$vars->{'classifications'} = $classifications;
$vars->{'target'} = "enter_bug.cgi"; $vars->{'target'} = "enter_bug.cgi";
$vars->{'format'} = $cgi->param('format'); $vars->{'format'} = $cgi->param('format');
$vars->{'cloned_bug_id'} = $cgi->param('cloned_bug_id'); $vars->{'cloned_bug_id'} = $cgi->param('cloned_bug_id');
print $cgi->header(); print $cgi->header();
$template->process("global/choose-classification.html.tmpl", $vars) $template->process("global/choose-classification.html.tmpl", $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
exit; exit;
} }
$cgi->param(-name => 'classification', -value => @$classifications[0]->name); # If we come here, then there is only one classification available.
$classification = $classifications[0]->name;
} }
my %products; # Keep only enterable products which are in the specified classification.
# XXX - This loop should work in some more sensible, efficient way. if ($classification ne "__all") {
foreach my $p (@enterable_products) { my $class = new Bugzilla::Classification({'name' => $classification});
if (Bugzilla->user->can_enter_product($p)) { # If the classification doesn't exist, then there is no product in it.
if (IsInClassification(scalar $cgi->param('classification'),$p) || if ($class) {
$cgi->param('classification') eq "__all") { @enterable_products
my $product_object = new Bugzilla::Product({name => $p}); = grep {$_->classification_id == $class->id} @enterable_products;
$products{$p} = $product_object->description;
}
}
}
my $prodsize = scalar(keys %products);
if ($prodsize == 0) {
ThrowUserError("no_products");
}
elsif ($prodsize > 1) {
my %classifications;
if ( ! Param('useclassification') ) {
@{$classifications{"all"}} = keys %products;
} }
elsif ($cgi->param('classification') eq "__all") { else {
%classifications = %::classifications; @enterable_products = ();
} else {
$classifications{$cgi->param('classification')} =
$::classifications{$cgi->param('classification')};
} }
$vars->{'proddesc'} = \%products; }
$vars->{'classifications'} = \%classifications;
if (scalar(@enterable_products) == 0) {
ThrowUserError('no_products');
}
elsif (scalar(@enterable_products) > 1) {
$vars->{'products'} = \@enterable_products;
$vars->{'target'} = "enter_bug.cgi"; $vars->{'target'} = "enter_bug.cgi";
$vars->{'format'} = $cgi->param('format'); $vars->{'format'} = $cgi->param('format');
$vars->{'cloned_bug_id'} = $cgi->param('cloned_bug_id'); $vars->{'cloned_bug_id'} = $cgi->param('cloned_bug_id');
print $cgi->header(); print $cgi->header();
$template->process("global/choose-product.html.tmpl", $vars) $template->process("global/choose-product.html.tmpl", $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
exit; exit;
} else { } else {
# Only one product exists # Only one product exists.
$product = (keys %products)[0]; $product = $enterable_products[0]->name;
} }
} }
......
...@@ -96,7 +96,6 @@ ...@@ -96,7 +96,6 @@
'reports/components.html.tmpl' => [ 'reports/components.html.tmpl' => [
'numcols', 'numcols',
'comp.description',
], ],
'reports/duplicates-table.html.tmpl' => [ 'reports/duplicates-table.html.tmpl' => [
...@@ -240,7 +239,6 @@ ...@@ -240,7 +239,6 @@
'global/choose-product.html.tmpl' => [ 'global/choose-product.html.tmpl' => [
'target', 'target',
'proddesc.$p',
], ],
# You are not permitted to add any values here. Everything in this file should # You are not permitted to add any values here. Everything in this file should
......
...@@ -20,8 +20,11 @@ ...@@ -20,8 +20,11 @@
#%] #%]
[%# INTERFACE: [%# INTERFACE:
# proddesc: hash. May be empty. The hash keys are the products, and the values # products: array of product objects. The list of products
# are their descriptions. # the user can enter bugs into.
# target: the script that displays this template.
# cloned_bug_id: ID of the bug being cloned.
# format: the desired format to display the target.
#%] #%]
[% PROCESS global/variables.none.tmpl %] [% PROCESS global/variables.none.tmpl %]
...@@ -39,18 +42,16 @@ ...@@ -39,18 +42,16 @@
<table> <table>
[% FOREACH p = proddesc.keys.sort %] [% FOREACH p = products %]
<tr> <tr>
<th align="right" valign="top"> <th align="right" valign="top">
<a href="[% target %]?product=[% p FILTER url_quote -%] <a href="[% target %]?product=[% p.name FILTER url_quote -%]
[%- IF cloned_bug_id %]&amp;cloned_bug_id=[% cloned_bug_id FILTER url_quote %][% END -%] [%- IF cloned_bug_id %]&amp;cloned_bug_id=[% cloned_bug_id FILTER url_quote %][% END -%]
[%- IF format %]&amp;format=[% format FILTER url_quote %][% END %]"> [%- IF format %]&amp;format=[% format FILTER url_quote %][% END %]">
[% p FILTER html %]</a>:&nbsp; [% p.name FILTER html %]</a>:&nbsp;
</th> </th>
[% IF proddesc.$p %] <td valign="top">[% p.description FILTER none %]</td>
<td valign="top">[% proddesc.$p %]</td>
[% END %]
</tr> </tr>
[% END %] [% END %]
......
...@@ -20,18 +20,14 @@ ...@@ -20,18 +20,14 @@
#%] #%]
[%# INTERFACE: [%# INTERFACE:
# product: string. The product this is the components list for. # product: object. The product for which we want to display component descriptions.
# components: List of hashes. May be empty. Each hash has four members:
# name: string. Name of the component.
# description: string. Description of the component. May contain HTML.
# initialowner: string. Component's default assignee.
# initialqacontact: string. Component's default QA contact.
#%] #%]
[% filtered_product = product FILTER html %] [% title = BLOCK %]
[% PROCESS global/header.html.tmpl Components for [% product.name FILTER html %]
title = "Components for $product" [% END %]
h2 = filtered_product %]
[% PROCESS global/header.html.tmpl title = title %]
[% IF Param("useqacontact") %] [% IF Param("useqacontact") %]
[% numcols = 3 %] [% numcols = 3 %]
...@@ -39,28 +35,24 @@ ...@@ -39,28 +35,24 @@
[% numcols = 2 %] [% numcols = 2 %]
[% END %] [% END %]
[% IF components.size == 0 %] <table>
This product has no components. <tr>
[% ELSE %] <th align="left">Component</th>
<table> <th align="left">Default Assignee</th>
<tr> [% IF Param("useqacontact") %]
<th align="left">Component</th> <th align="left">Default QA Contact</th>
<th align="left">Default Assignee</th>
[% IF Param("useqacontact") %]
<th align="left">Default QA Contact</th>
[% END %]
</tr>
[% FOREACH comp = components %]
[% INCLUDE describe_comp %]
[% END %] [% END %]
<tr> </tr>
<td colspan="[% numcols %]">
<hr> [% FOREACH comp = product.components %]
</td> [% INCLUDE describe_comp %]
</tr> [% END %]
</table> <tr>
[% END %] <td colspan="[% numcols %]">
<hr>
</td>
</tr>
</table>
[% PROCESS global/footer.html.tmpl %] [% PROCESS global/footer.html.tmpl %]
...@@ -79,21 +71,19 @@ ...@@ -79,21 +71,19 @@
<a name="[% comp.name FILTER html %]">[% comp.name FILTER html %]</a> <a name="[% comp.name FILTER html %]">[% comp.name FILTER html %]</a>
</td> </td>
<td> <td>
<a href="mailto:[% comp.initialowner FILTER html %] <a href="mailto:[% comp.default_assignee.email FILTER html %]">
[% Param('emailsuffix') %]"> [% comp.default_assignee.login FILTER html %]</a>
[% comp.initialowner FILTER html %]</a>
</td> </td>
[% IF Param("useqacontact") %] [% IF Param("useqacontact") %]
<td> <td>
<a href="mailto:[% comp.initialqacontact FILTER html %] <a href="mailto:[% comp.default_qa_contact.email FILTER html %]">
[% Param('emailsuffix') %]"> [% comp.default_qa_contact.login FILTER html %]</a>
[% comp.initialqacontact FILTER html %]</a>
</td> </td>
[% END %] [% END %]
</tr> </tr>
<tr> <tr>
<td colspan="[% numcols - 1 %]"> <td colspan="[% numcols - 1 %]">
[% comp.description %] [% comp.description FILTER none %]
</td> </td>
</tr> </tr>
[% END %] [% 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