Commit 3e7162e6 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 307524: Templatise the updategroupcontrols bit of editproducts.cgi (and tidy…

Bug 307524: Templatise the updategroupcontrols bit of editproducts.cgi (and tidy up templatisation) - Original patch by André Batosti <batosti@async.com.br> r=LpSolit a=justdave
parent 2f308492
...@@ -63,28 +63,6 @@ sub CheckProduct ...@@ -63,28 +63,6 @@ sub CheckProduct
# do we have a product? # do we have a product?
unless ($prod) { unless ($prod) {
print "Sorry, you haven't specified a product.";
PutTrailer();
exit;
}
unless (TestProduct($prod)) {
print "Sorry, product '$prod' does not exist.";
PutTrailer();
exit;
}
}
# For the transition period, as this file is templatised bit by bit,
# we need this routine, which does things properly, and will
# eventually be the only version. (The older versions assume a
# $template->put_header() call has been made)
sub CheckProductNew
{
my $prod = shift;
# do we have a product?
unless ($prod) {
ThrowUserError('product_not_specified'); ThrowUserError('product_not_specified');
} }
...@@ -115,28 +93,6 @@ sub CheckClassification ...@@ -115,28 +93,6 @@ sub CheckClassification
# do we have a classification? # do we have a classification?
unless ($cl) { unless ($cl) {
print "Sorry, you haven't specified a classification.";
PutTrailer();
exit;
}
unless (TestClassification $cl) {
print "Sorry, classification '$cl' does not exist.";
PutTrailer();
exit;
}
}
# For the transition period, as this file is templatised bit by bit,
# we need this routine, which does things properly, and will
# eventually be the only version. (The older versions assume a
# $template->put_header() call has been made)
sub CheckClassificationNew
{
my $cl = shift;
# do we have a classification?
unless ($cl) {
ThrowUserError('classification_not_specified'); ThrowUserError('classification_not_specified');
} }
...@@ -146,40 +102,12 @@ sub CheckClassificationNew ...@@ -146,40 +102,12 @@ sub CheckClassificationNew
} }
} }
sub CheckClassificationProduct sub CheckClassificationProduct
{ {
my $cl = shift;
my $prod = shift;
my $dbh = Bugzilla->dbh;
CheckClassification($cl);
CheckProduct($prod);
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.";
PutTrailer();
exit;
}
}
sub CheckClassificationProductNew
{
my ($cl, $prod) = @_; my ($cl, $prod) = @_;
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
CheckClassificationNew($cl); CheckClassification($cl);
trick_taint($prod); trick_taint($prod);
trick_taint($cl); trick_taint($cl);
...@@ -199,39 +127,6 @@ sub CheckClassificationProductNew ...@@ -199,39 +127,6 @@ sub CheckClassificationProductNew
} }
# #
# Displays a text like "a.", "a or b.", "a, b or c.", "a, b, c or d."
#
sub PutTrailer
{
my (@links) = ("Back to the <A HREF=\"query.cgi\">query page</A>", @_);
my $count = $#links;
my $num = 0;
print "<P>\n";
foreach (@links) {
print $_;
if ($num == $count) {
print ".\n";
}
elsif ($num == $count-1) {
print " or ";
}
else {
print ", ";
}
$num++;
}
$template->put_footer();
}
#
# Preliminary checks: # Preliminary checks:
# #
...@@ -252,10 +147,6 @@ $user->in_group('editcomponents') ...@@ -252,10 +147,6 @@ $user->in_group('editcomponents')
my $classification = trim($cgi->param('classification') || ''); my $classification = trim($cgi->param('classification') || '');
my $product = trim($cgi->param('product') || ''); my $product = trim($cgi->param('product') || '');
my $action = trim($cgi->param('action') || ''); my $action = trim($cgi->param('action') || '');
my $headerdone = 0;
my $localtrailer = "<A HREF=\"editproducts.cgi\">edit</A> more products";
my $classhtmlvarstart = "";
my $classhtmlvar = "";
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
# #
...@@ -263,13 +154,10 @@ my $dbh = Bugzilla->dbh; ...@@ -263,13 +154,10 @@ my $dbh = Bugzilla->dbh;
# classifications enabled) # classifications enabled)
# #
if (Param('useclassification')) { if (Param('useclassification')
if ($classification) { && !$classification
$classhtmlvar = "&classification=" . url_quote($classification); && !$product)
$classhtmlvarstart = "?classification=" . url_quote($classification); {
$localtrailer .= ", <A HREF=\"editproducts.cgi" . $classhtmlvarstart . "\">edit</A> in this classification";
}
elsif (!$product) {
my $query = my $query =
"SELECT classifications.name, classifications.description, "SELECT classifications.name, classifications.description,
COUNT(classification_id) AS product_count COUNT(classification_id) AS product_count
...@@ -289,7 +177,6 @@ if (Param('useclassification')) { ...@@ -289,7 +177,6 @@ if (Param('useclassification')) {
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
exit; exit;
}
} }
...@@ -301,7 +188,7 @@ if (Param('useclassification')) { ...@@ -301,7 +188,7 @@ if (Param('useclassification')) {
if (!$action && !$product) { if (!$action && !$product) {
if (Param('useclassification')) { if (Param('useclassification')) {
CheckClassificationNew($classification); CheckClassification($classification);
} }
my @execute_params = (); my @execute_params = ();
...@@ -361,7 +248,7 @@ if (!$action && !$product) { ...@@ -361,7 +248,7 @@ if (!$action && !$product) {
if ($action eq 'add') { if ($action eq 'add') {
if (Param('useclassification')) { if (Param('useclassification')) {
CheckClassificationNew($classification); CheckClassification($classification);
} }
$vars->{'classification'} = $classification; $vars->{'classification'} = $classification;
$template->process("admin/products/create.html.tmpl", $vars) $template->process("admin/products/create.html.tmpl", $vars)
...@@ -381,7 +268,7 @@ if ($action eq 'new') { ...@@ -381,7 +268,7 @@ if ($action eq 'new') {
my $classification_id = 1; my $classification_id = 1;
if (Param('useclassification')) { if (Param('useclassification')) {
CheckClassificationNew($classification); CheckClassification($classification);
$classification_id = get_classification_id($classification); $classification_id = get_classification_id($classification);
$vars->{'classification'} = $classification; $vars->{'classification'} = $classification;
} }
...@@ -557,7 +444,7 @@ if ($action eq 'del') { ...@@ -557,7 +444,7 @@ if ($action eq 'del') {
my $classification_id = 1; my $classification_id = 1;
if (Param('useclassification')) { if (Param('useclassification')) {
CheckClassificationProductNew($classification, $product); CheckClassificationProduct($classification, $product);
$classification_id = get_classification_id($classification); $classification_id = get_classification_id($classification);
$vars->{'classification'} = $classification; $vars->{'classification'} = $classification;
} }
...@@ -691,7 +578,7 @@ if ($action eq 'delete') { ...@@ -691,7 +578,7 @@ if ($action eq 'delete') {
# #
if ($action eq 'edit' || (!$action && $product)) { if ($action eq 'edit' || (!$action && $product)) {
CheckProductNew($product); CheckProduct($product);
trick_taint($product); trick_taint($product);
my $product_id = get_product_id($product); my $product_id = get_product_id($product);
my $classification_id=1; my $classification_id=1;
...@@ -699,7 +586,7 @@ if ($action eq 'edit' || (!$action && $product)) { ...@@ -699,7 +586,7 @@ if ($action eq 'edit' || (!$action && $product)) {
# If a product has been given with no classification associated # If a product has been given with no classification associated
# with it, take this information from the DB # with it, take this information from the DB
if ($classification) { if ($classification) {
CheckClassificationProductNew($classification, $product); CheckClassificationProduct($classification, $product);
} else { } else {
$classification = $classification =
$dbh->selectrow_array("SELECT classifications.name $dbh->selectrow_array("SELECT classifications.name
...@@ -852,8 +739,6 @@ if ($action eq 'updategroupcontrols') { ...@@ -852,8 +739,6 @@ if ($action eq 'updategroupcontrols') {
exit; exit;
} }
} }
$template->put_header("Update group access controls for product \"$product\"");
$headerdone = 1;
SendSQL("SELECT id, name FROM groups " . SendSQL("SELECT id, name FROM groups " .
"WHERE isbuggroup != 0 AND isactive != 0"); "WHERE isbuggroup != 0 AND isactive != 0");
while (MoreSQLData()){ while (MoreSQLData()){
...@@ -872,8 +757,7 @@ if ($action eq 'updategroupcontrols') { ...@@ -872,8 +757,7 @@ if ($action eq 'updategroupcontrols') {
|| (($newmembercontrol == CONTROLMAPDEFAULT) || (($newmembercontrol == CONTROLMAPDEFAULT)
&& ($newothercontrol != CONTROLMAPSHOWN))) { && ($newothercontrol != CONTROLMAPSHOWN))) {
ThrowUserError('illegal_group_control_combination', ThrowUserError('illegal_group_control_combination',
{groupname => $groupname, {groupname => $groupname});
header_done => 1});
} }
} }
$dbh->bz_lock_tables('groups READ', $dbh->bz_lock_tables('groups READ',
...@@ -938,9 +822,8 @@ if ($action eq 'updategroupcontrols') { ...@@ -938,9 +822,8 @@ if ($action eq 'updategroupcontrols') {
} }
} }
my @removed_na;
foreach my $groupid (@now_na) { foreach my $groupid (@now_na) {
print "Removing bugs from NA group "
. html_quote(GroupIdToName($groupid)) . "<P>\n";
my $count = 0; my $count = 0;
SendSQL("SELECT bugs.bug_id, SendSQL("SELECT bugs.bug_id,
(lastdiffed >= delta_ts) (lastdiffed >= delta_ts)
...@@ -967,12 +850,14 @@ if ($action eq 'updategroupcontrols') { ...@@ -967,12 +850,14 @@ if ($action eq 'updategroupcontrols') {
PopGlobalSQLState(); PopGlobalSQLState();
$count++; $count++;
} }
print "dropped $count bugs<p>\n"; my %group = (name => GroupIdToName($groupid),
bug_count => $count);
push(@removed_na, \%group);
} }
my @added_mandatory;
foreach my $groupid (@now_mandatory) { foreach my $groupid (@now_mandatory) {
print "Adding bugs to Mandatory group "
. html_quote(GroupIdToName($groupid)) . "<P>\n";
my $count = 0; my $count = 0;
SendSQL("SELECT bugs.bug_id, SendSQL("SELECT bugs.bug_id,
(lastdiffed >= delta_ts) (lastdiffed >= delta_ts)
...@@ -1001,13 +886,23 @@ if ($action eq 'updategroupcontrols') { ...@@ -1001,13 +886,23 @@ if ($action eq 'updategroupcontrols') {
PopGlobalSQLState(); PopGlobalSQLState();
$count++; $count++;
} }
print "added $count bugs<p>\n"; my %group = (name => GroupIdToName($groupid),
bug_count => $count);
push(@added_mandatory, \%group);
} }
$dbh->bz_unlock_tables(); $dbh->bz_unlock_tables();
print "Group control updates done<P>\n"; $vars->{'removed_na'} = \@removed_na;
PutTrailer($localtrailer); $vars->{'added_mandatory'} = \@added_mandatory;
$vars->{'classification'} = $classification;
$vars->{'product'} = $product;
$template->process("admin/products/groupcontrol/updated.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
exit; exit;
} }
...@@ -1036,7 +931,7 @@ if ($action eq 'update') { ...@@ -1036,7 +931,7 @@ if ($action eq 'update') {
my $checkvotes = 0; my $checkvotes = 0;
CheckProductNew($productold); CheckProduct($productold);
my $product_id = get_product_id($productold); my $product_id = get_product_id($productold);
my $stored_maxvotesperbug = $maxvotesperbug; my $stored_maxvotesperbug = $maxvotesperbug;
...@@ -1316,7 +1211,6 @@ if ($action eq 'editgroupcontrols') { ...@@ -1316,7 +1211,6 @@ if ($action eq 'editgroupcontrols') {
$group{'bugcount'} = $bugcount; $group{'bugcount'} = $bugcount;
push @groups,\%group; push @groups,\%group;
} }
$vars->{'header_done'} = $headerdone;
$vars->{'product'} = $product; $vars->{'product'} = $product;
$vars->{'classification'} = $classification; $vars->{'classification'} = $classification;
$vars->{'groups'} = \@groups; $vars->{'groups'} = \@groups;
...@@ -1337,5 +1231,4 @@ if ($action eq 'editgroupcontrols') { ...@@ -1337,5 +1231,4 @@ if ($action eq 'editgroupcontrols') {
# No valid action found # No valid action found
# #
$template->put_header("Error"); ThrowUserError('no_valid_action', {field => "product"});
print "I don't have a clue what you want.<BR>\n";
...@@ -96,7 +96,8 @@ versions:</a> ...@@ -96,7 +96,8 @@ versions:</a>
<tr> <tr>
<th align="right" valign="top"> <th align="right" valign="top">
<a href="editproducts.cgi?action=editgroupcontrols&product= <a href="editproducts.cgi?action=editgroupcontrols&product=
[%- product.name FILTER url_quote %]"> [%- product.name FILTER url_quote %]&classification=
[%- classification FILTER url_quote %]">
Edit Group Access Controls: Edit Group Access Controls:
</a> </a>
</th> </th>
......
[%# 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): André Batosti <batosti@async.com.br>
#
#%]
[%# INTERFACE:
# removed_na: array of hashes; groups not applicable for the product.
# added_mandatory: array of hashes; groups mandatory for the product.
# classification: string; product classification name.
# product: string; name of the product.
#%]
[% title = BLOCK %]
Update group access controls for [% product FILTER html %]
[% END %]
[% PROCESS global/header.html.tmpl
title = title
%]
<p>
[% IF removed_na.size > 0 %]
[% FOREACH g = removed_na %]
Removing [% terms.bugs %] from group '[% g.name FILTER html %]' which
no longer applies to this product<p>
[% g.bug_count FILTER html %] [%+ terms.bugs %] removed<p>
[% END %]
[% END %]
[% IF added_mandatory.size > 0 %]
[% FOREACH g = added_mandatory %]
Adding [% terms.bugs %] to group '[% g.name FILTER html %]' which is
mandatory for this product<p>
[% g.bug_count FILTER html %] [%+ terms.bugs %] added<p>
[% END %]
[% END %]
Group control updates done<p>
[% PROCESS admin/products/footer.html.tmpl name = product %]
[% PROCESS global/footer.html.tmpl %]
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