From 6e29c7cd06afac55962dac20421bddbf17954906 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Fri, 8 Jul 2005 04:03:03 +0000 Subject: Bug 289580: Templatize the 'confirm delete' bit of editproducts.cgi - Patch by Tiago R. Mello r=LpSolit a=justdave --- editproducts.cgi | 289 ++++++++------------- .../admin/products/confirm-delete.html.tmpl | 282 ++++++++++++++++++++ .../en/default/admin/products/deleted.html.tmpl | 41 +++ template/en/default/filterexceptions.pl | 5 + template/en/default/global/user-error.html.tmpl | 5 + 5 files changed, 445 insertions(+), 177 deletions(-) create mode 100644 template/en/default/admin/products/confirm-delete.html.tmpl create mode 100644 template/en/default/admin/products/deleted.html.tmpl diff --git a/editproducts.cgi b/editproducts.cgi index 229aa64d2..9d81f176c 100755 --- a/editproducts.cgi +++ b/editproducts.cgi @@ -139,16 +139,21 @@ sub CheckClassificationProduct ($$) { my $cl = shift; my $prod = shift; + my $dbh = Bugzilla->dbh; CheckClassification($cl); CheckProduct($prod); - # does the classification exist? - SendSQL("SELECT products.name - FROM products,classifications - WHERE products.name=" . SqlQuote($prod) . - " AND classifications.name=" . SqlQuote($cl)); - my $res = FetchOneColumn(); + trick_taint($prod); + trick_taint($cl); + + my $query = q{SELECT products.name + FROM products + INNER JOIN classifications + ON products.classification_id = classifications.id + WHERE products.name = ? + AND classifications.name = ?}; + my $res = $dbh->selectrow_array($query, undef, ($prod, $cl)); unless ($res) { print "Sorry, classification->product '$cl'->'$prod' does not exist."; @@ -157,6 +162,26 @@ sub CheckClassificationProduct ($$) } } +sub CheckClassificationProductNew ($$) +{ + my ($cl, $prod) = @_; + my $dbh = Bugzilla->dbh; + + CheckClassificationNew($cl); + + my ($res) = $dbh->selectrow_array(q{ + SELECT products.name + FROM products + INNER JOIN classifications + ON products.classification_id = classifications.id + WHERE products.name = ? AND classifications.name = ?}, + undef, ($prod, $cl)); + + unless ($res) { + ThrowUserError('classification_doesnt_exist_for_product', + { product => $prod, classification => $cl }); + } +} # # Displays the form to edit a products parameters @@ -604,180 +629,93 @@ if ($action eq 'new') { # if ($action eq 'del') { - PutHeader("Delete product"); - CheckProduct($product); - my $classification_id=1; - if (Param('useclassification')) { - CheckClassificationProduct($classification,$product); - $classification_id = get_classification_id($classification); - } - - # display some data about the product - SendSQL("SELECT classifications.description, - products.id, products.description, milestoneurl, disallownew - FROM products,classifications - WHERE products.name=" . SqlQuote($product) . - " AND classifications.id=" . SqlQuote($classification_id)); - my ($class_description, $product_id, $prod_description, $milestoneurl, $disallownew) = FetchSQLData(); - my $milestonelink = $milestoneurl ? "$milestoneurl" - : "missing"; - $prod_description ||= "description missing"; - $class_description ||= "description missing"; - $disallownew = $disallownew ? 'closed' : 'open'; - print "\n"; - print "\n"; - print " \n"; - print " \n"; - - if (Param('useclassification')) { - print "\n"; - print " \n"; - print " \n"; - - print "\n"; - print " \n"; - print " \n"; + if (!$product) { + ThrowUserError('product_not_specified'); } - print "\n"; - print " \n"; - print " \n"; - - print "\n"; - print " \n"; - print " \n"; - - if (Param('usetargetmilestone')) { - print "\n"; - print " \n"; - print " \n"; - } - - - print "\n"; - print " \n"; - print " \n"; + my $product_id = get_product_id($product); + $product_id || ThrowUserError('product_doesnt_exist', + {product => $product}); - print "\n"; - print " \n"; - print " \n\n"; - print " \n"; - print " \n\n"; - print " \n"; - print " \n\n"; - print " \n"; - print " \n
PartValue
Classification:$classification
Description:$class_description
Product:$product
Description:$prod_description
Milestone URL:$milestonelink
Closed for bugs:$disallownew
Components:"; - SendSQL("SELECT name,description - FROM components - WHERE product_id=$product_id"); - if (MoreSQLData()) { - print ""; - while ( MoreSQLData() ) { - my ($component, $description) = FetchSQLData(); - $description ||= "description missing"; - print ""; - print "\n"; - } - print "
$component:$description
\n"; - } else { - print "missing"; - } + my $classification_id = 1; - print "
Versions:"; - SendSQL("SELECT value - FROM versions - WHERE product_id=$product_id - ORDER BY value"); - if (MoreSQLData()) { - my $br = 0; - while ( MoreSQLData() ) { - my ($version) = FetchSQLData(); - print "
" if $br; - print $version; - $br = 1; - } - } else { - print "missing"; + if (Param('useclassification')) { + CheckClassificationProductNew($classification, $product); + $classification_id = get_classification_id($classification); + $vars->{'classification'} = $classification; } - # - # Adding listing for associated target milestones - matthew@zeroknowledge.com - # + # Extract some data about the product + my $query = q{SELECT classifications.description, + products.description, + products.milestoneurl, + products.disallownew + FROM products + INNER JOIN classifications + ON products.classification_id = classifications.id + WHERE products.id = ?}; + + my ($class_description, + $prod_description, + $milestoneurl, + $disallownew) = $dbh->selectrow_array($query, undef, + $product_id); + + $vars->{'class_description'} = $class_description; + $vars->{'product_id'} = $product_id; + $vars->{'prod_description'} = $prod_description; + $vars->{'milestoneurl'} = $milestoneurl; + $vars->{'disallownew'} = $disallownew; + $vars->{'product_name'} = $product; + + $vars->{'components'} = $dbh->selectall_arrayref(q{ + SELECT name, description FROM components + WHERE product_id = ? ORDER BY name}, {'Slice' => {}}, + $product_id); + + $vars->{'versions'} = $dbh->selectcol_arrayref(q{ + SELECT value FROM versions + WHERE product_id = ? ORDER BY value}, undef, + $product_id); + + # Adding listing for associated target milestones - + # matthew@zeroknowledge.com if (Param('usetargetmilestone')) { - print "
Edit milestones:"; - SendSQL("SELECT value - FROM milestones - WHERE product_id=$product_id - ORDER BY sortkey,value"); - if(MoreSQLData()) { - my $br = 0; - while ( MoreSQLData() ) { - my ($milestone) = FetchSQLData(); - print "
" if $br; - print $milestone; - $br = 1; - } - } else { - print "missing"; - } - } - - print "
Bugs:"; - SendSQL("SELECT count(bug_id), product_id - FROM bugs " . - $dbh->sql_group_by('product_id') . " - HAVING product_id = $product_id"); - my $bugs = FetchOneColumn(); - print $bugs || 'none'; - - - print "
"; - - print "

Confirmation

\n"; - - if ($bugs) { - if (!Param("allowbugdeletion")) { - print "Sorry, there are $bugs bugs outstanding for this product. -You must reassign those bugs to another product before you can delete this -one."; - PutTrailer($localtrailer); - exit; - } - print "
\n", - "There are bugs entered for this product! When you delete this ", - "product, ALL stored bugs and their history will be ", - "deleted too.\n", - "
\n"; + $vars->{'milestones'} = $dbh->selectcol_arrayref(q{ + SELECT value FROM milestones + WHERE product_id = ? + ORDER BY sortkey, value}, undef, $product_id); } - print "

Do you really want to delete this product?

\n"; - print "

\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "
"; - - PutTrailer($localtrailer); + ($vars->{'bug_count'}) = $dbh->selectrow_array(q{ + SELECT COUNT(*) FROM bugs WHERE product_id = ?}, + undef, $product_id) || 0; + + $template->process("admin/products/confirm-delete.html.tmpl", $vars) + || ThrowTemplateError($template->error()); exit; } - - # # action='delete' -> really delete the product # if ($action eq 'delete') { - CheckProduct($product); + + if (!$product) { + ThrowUserError('product_not_specified'); + } + my $product_id = get_product_id($product); + $product_id || ThrowUserError('product_doesnt_exist', + {product => $product}); + + $vars->{'product'} = $product; - my $bug_ids = - $dbh->selectcol_arrayref("SELECT bug_id FROM bugs WHERE product_id = ?", - undef, $product_id); + my $bug_ids = $dbh->selectcol_arrayref(q{ + SELECT bug_id FROM bugs + WHERE product_id = ?}, undef, $product_id); my $nb_bugs = scalar(@$bug_ids); if ($nb_bugs) { @@ -790,47 +728,44 @@ if ($action eq 'delete') { else { ThrowUserError("product_has_bugs", { nb => $nb_bugs }); } + $vars->{'nb_bugs'} = $nb_bugs; } - PutHeader("Deleting product"); - print "All references to deleted bugs removed.

\n" if $nb_bugs; - $dbh->bz_lock_tables('products WRITE', 'components WRITE', 'versions WRITE', 'milestones WRITE', 'group_control_map WRITE', 'flaginclusions WRITE', 'flagexclusions WRITE'); - $dbh->do("DELETE FROM components WHERE product_id = ?", undef, $product_id); - print "Components deleted.
\n"; + $dbh->do("DELETE FROM components WHERE product_id = ?", + undef, $product_id); - $dbh->do("DELETE FROM versions WHERE product_id = ?", undef, $product_id); - print "Versions deleted.
\n"; + $dbh->do("DELETE FROM versions WHERE product_id = ?", + undef, $product_id); - $dbh->do("DELETE FROM milestones WHERE product_id = ?", undef, $product_id); - print "Milestones deleted.

\n"; + $dbh->do("DELETE FROM milestones WHERE product_id = ?", + undef, $product_id); $dbh->do("DELETE FROM group_control_map WHERE product_id = ?", undef, $product_id); - print "Group controls deleted.
\n"; $dbh->do("DELETE FROM flaginclusions WHERE product_id = ?", undef, $product_id); + $dbh->do("DELETE FROM flagexclusions WHERE product_id = ?", undef, $product_id); - print "Flag inclusions and exclusions deleted.

\n"; - - $dbh->do("DELETE FROM products WHERE id = ?", undef, $product_id); - print "Product '$product' deleted.

\n"; + + $dbh->do("DELETE FROM products WHERE id = ?", + undef, $product_id); $dbh->bz_unlock_tables(); unlink "$datadir/versioncache"; - PutTrailer($localtrailer); + + $template->process("admin/products/deleted.html.tmpl", $vars) + || ThrowTemplateError($template->error()); exit; } - - # # action='edit' -> present the 'edit product' form # If a product is given with no action associated with it, then edit it. diff --git a/template/en/default/admin/products/confirm-delete.html.tmpl b/template/en/default/admin/products/confirm-delete.html.tmpl new file mode 100644 index 000000000..672f345e9 --- /dev/null +++ b/template/en/default/admin/products/confirm-delete.html.tmpl @@ -0,0 +1,282 @@ +[%# 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. + # + # Contributor(s): Gavin Shelley + #%] + +[%# INTERFACE: + # product_name: string; The name of the product + # + # prod_description: string; Product description, may be empty + # + # (classification fields available if Param('useclassification') is enabled:) + # + # classification: string; The name of the classification the product is in + # + # class_description: string; Classification description, may be empty + # + # bug_count: number; The number of bugs belonging to the product + # + # milestoneurl: string; milestone url, if milestones are in use, + # may be empty + # + # disallownew: boolean; Are new bugs allowed for the product flag + # + # components: list of hashes, members are: name, description + # + # versions: list of version values. + # + # milestones: list of milestone values. + # + #%] + +[% title = BLOCK %]Delete Product '[% product_name FILTER html %]' +[% END %] + +[% PROCESS global/header.html.tmpl + title = title + style_urls = ['skins/standard/admin.css'] +%] + +[% IF classification %] + [% classification_url_part = BLOCK %]&classification= + [%- classification FILTER url_quote %] + [%- END %] +[% ELSE %] + [% classification_url_part = "" %] +[% END %] + +[% UNLESS class_description %] + [% class_description = 'missing' %] +[% END %] +[% UNLESS prod_description %] + [% prod_description = 'missing' %] +[% END %] + +[% IF disallownew %] + [% disallownew = "closed" %] +[% ELSE %] + [% disallownew = "open" %] +[% END %] + + + + + + + + [% IF Param('useclassification') %] + + + + + + + [%# descriptions are intentionally not filtered to allow html content %] + + + [% END %] + + + + + + + + [%# descriptions are intentionally not filtered to allow html content %] + + + + [% IF Param('usetargetmilestone') %] + + + + + [% END %] + + + + + + + + + + + + + + + + + + + + + + + + +
FieldValue
Classification:[% classification FILTER html %]
Classification Description:[% class_description FILTER none %]
Product: + + [% product_name FILTER html %] + +
Description:[% prod_description FILTER none %]
Milestone URL: + [% IF milestoneurl %] + + [%- milestoneurl FILTER html %] + + [% ELSE %] + none + [% END %] +
Closed for [% terms.bugs %]:[% disallownew FILTER html %]
+ [% IF components.size > 0 %] + + Components: + + [% ELSE %] + Components: + [% END %] + + [% IF components.size > 0 %] + + [% FOREACH c = components %] + + + [%# descriptions are intentionally not filtered to allow html content %] + + + [% END %] +
[% c.name FILTER html %]: + [% IF c.description %] + [% c.description FILTER none %] + [% ELSE %] + missing + [% END %] +
+ [% ELSE %] + none + [% END %] +
+ [% IF versions.size > 0 %] + + Versions: + + [% ELSE %] + Versions: + [% END %] + + [% IF versions.size > 0 %] + [% FOREACH v = versions %] + [% v FILTER html %]
+ [% END %] + [% ELSE %] + none + [% END %] +
+ [% IF milestones.size > 0 %] + + Milestones: + + [% ELSE %] + Milestones: + [% END %] + + [% IF milestones.size > 0 %] + [% FOREACH m = milestones %] + [% m FILTER html %]
+ [% END %] + [% ELSE %] + none + [% END %] +
[% terms.Bugs %]: + [% IF bug_count %] + + [% bug_count %] + + [% ELSE %] + none + [% END %] +
+ +

Confirmation

+ +[% IF bug_count %] + + [% IF !Param("allowbugdeletion") %] + + Sorry, there + + [% IF bug_count > 1 %] + are [% bug_count %] [%+ terms.bugs %] + [% ELSE %] + is 1 [% terms.bug %] + [% END %] + + outstanding for this product. You must reassign + + [% IF bug_count > 1 %] + those [% terms.bugs %] + [% ELSE %] + that [% terms.bug %] + [% END %] + + to another product before you can delete this one. + + [% ELSE %] + + + + + +
+ There + [% IF bug_count > 1 %] + are [% bug_count %] [%+ terms.bugs %] + [% ELSE %] + is 1 [% terms.bug %] + [% END %] + entered for this product! When you delete this + product, ALL stored [% terms.bugs %] and + their history will be deleted, too. +
+ + [% END %] + +[% END %] + +[% IF bug_count == 0 || Param('allowbugdeletion') %] + +

Do you really want to delete this product?

+ +

+ + + + +
+ +[% END %] + +[% PROCESS admin/products/footer.html.tmpl %] + +[% PROCESS global/footer.html.tmpl %] diff --git a/template/en/default/admin/products/deleted.html.tmpl b/template/en/default/admin/products/deleted.html.tmpl new file mode 100644 index 000000000..6b31dbb09 --- /dev/null +++ b/template/en/default/admin/products/deleted.html.tmpl @@ -0,0 +1,41 @@ +[%# 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. + # + # Contributor(s): Tiago R. Mello + # + #%] + +[% PROCESS global/header.html.tmpl + title = 'Deleting product' +%] + +[% IF nb_bugs %] + All references to deleted [% terms.bugs %] removed. +[% END %] + +

+ Components deleted.
+ Versions deleted.
+ Milestones deleted. +

+ +

+ Group controls deleted.
+ Flag inclusions and exclusions deleted. +

+ +

+ Product [% product FILTER html %] deleted. +

+ +[% PROCESS global/footer.html.tmpl %] diff --git a/template/en/default/filterexceptions.pl b/template/en/default/filterexceptions.pl index 39de4fcac..bfa469481 100644 --- a/template/en/default/filterexceptions.pl +++ b/template/en/default/filterexceptions.pl @@ -535,6 +535,11 @@ 'classification_url_part', ], +'admin/products/confirm-delete.html.tmpl' => [ + 'classification_url_part', + 'bug_count', +], + 'admin/products/footer.html.tmpl' => [ 'classification_url_part', 'classification_text', diff --git a/template/en/default/global/user-error.html.tmpl b/template/en/default/global/user-error.html.tmpl index 20d8371f4..800257ad9 100644 --- a/template/en/default/global/user-error.html.tmpl +++ b/template/en/default/global/user-error.html.tmpl @@ -234,6 +234,11 @@ [% title = "Classification Does Not Exist" %] The classification '[% name FILTER html %]' does not exist. + [% ELSIF error == "classification_doesnt_exist_for_product" %] + [% title = "Classification Does Not Exist For Product" %] + The classification '[% classification FILTER html %]' does not exist + for product '[% product FILTER html %]'. + [% ELSIF error == "classification_not_deletable" %] [% title = "Default Classification Can Not Be Deleted" %] You can not delete the default classification -- cgit v1.2.3-24-g4f1b