summaryrefslogtreecommitdiffstats
path: root/editproducts.cgi
diff options
context:
space:
mode:
authorPerl Tidy <perltidy@bugzilla.org>2018-12-05 21:38:52 +0100
committerDylan William Hardison <dylan@hardison.net>2018-12-05 23:49:08 +0100
commit8ec8da0491ad89604700b3e29a227966f6d84ba1 (patch)
tree9d270f173330ca19700e0ba9f2ee931300646de1 /editproducts.cgi
parenta7bb5a65b71644d9efce5fed783ed545b9336548 (diff)
downloadbugzilla-8ec8da0491ad89604700b3e29a227966f6d84ba1.tar.gz
bugzilla-8ec8da0491ad89604700b3e29a227966f6d84ba1.tar.xz
no bug - reformat all the code using the new perltidy rules
Diffstat (limited to 'editproducts.cgi')
-rwxr-xr-xeditproducts.cgi497
1 files changed, 255 insertions, 242 deletions
diff --git a/editproducts.cgi b/editproducts.cgi
index a989e4bc1..7deab1d2d 100755
--- a/editproducts.cgi
+++ b/editproducts.cgi
@@ -25,13 +25,14 @@ use Bugzilla::Token;
# Preliminary checks:
#
-my $user = Bugzilla->login(LOGIN_REQUIRED);
+my $user = Bugzilla->login(LOGIN_REQUIRED);
my $whoid = $user->id;
-my $dbh = Bugzilla->dbh;
-my $cgi = Bugzilla->cgi;
+my $dbh = Bugzilla->dbh;
+my $cgi = Bugzilla->cgi;
my $template = Bugzilla->template;
-my $vars = {};
+my $vars = {};
+
# Remove this as soon as the documentation about products has been
# improved and each action has its own section.
$vars->{'doc_section'} = 'products.html';
@@ -40,43 +41,42 @@ print $cgi->header();
$user->in_group('editcomponents')
|| scalar(@{$user->get_products_by_permission('editcomponents')})
- || ThrowUserError("auth_failure", {group => "editcomponents",
- action => "edit",
- object => "products"});
+ || ThrowUserError("auth_failure",
+ {group => "editcomponents", action => "edit", object => "products"});
#
# often used variables
#
my $classification_name = trim($cgi->param('classification') || '');
-my $product_name = trim($cgi->param('product') || '');
-my $action = trim($cgi->param('action') || '');
-my $token = $cgi->param('token');
+my $product_name = trim($cgi->param('product') || '');
+my $action = trim($cgi->param('action') || '');
+my $token = $cgi->param('token');
#
# product = '' -> Show nice list of classifications (if
# classifications enabled)
#
-if (Bugzilla->params->{'useclassification'}
- && !$classification_name
- && !$product_name)
+if ( Bugzilla->params->{'useclassification'}
+ && !$classification_name
+ && !$product_name)
{
- my $class;
- if ($user->in_group('editcomponents')) {
- $class = [Bugzilla::Classification->get_all];
- }
- else {
- # Only keep classifications containing at least one product
- # which you can administer.
- my $products = $user->get_products_by_permission('editcomponents');
- my %class_ids = map { $_->classification_id => 1 } @$products;
- $class = Bugzilla::Classification->new_from_list([keys %class_ids]);
- }
- $vars->{'classifications'} = $class;
-
- $template->process("admin/products/list-classifications.html.tmpl", $vars)
- || ThrowTemplateError($template->error());
- exit;
+ my $class;
+ if ($user->in_group('editcomponents')) {
+ $class = [Bugzilla::Classification->get_all];
+ }
+ else {
+ # Only keep classifications containing at least one product
+ # which you can administer.
+ my $products = $user->get_products_by_permission('editcomponents');
+ my %class_ids = map { $_->classification_id => 1 } @$products;
+ $class = Bugzilla::Classification->new_from_list([keys %class_ids]);
+ }
+ $vars->{'classifications'} = $class;
+
+ $template->process("admin/products/list-classifications.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
+ exit;
}
@@ -86,36 +86,35 @@ if (Bugzilla->params->{'useclassification'}
#
if (!$action && !$product_name) {
- my $classification;
- my $products;
-
+ my $classification;
+ my $products;
+
+ if (Bugzilla->params->{'useclassification'}) {
+ $classification = Bugzilla::Classification->check($classification_name);
+ $products = $user->get_selectable_products($classification->id);
+ $vars->{'classification'} = $classification;
+ }
+ else {
+ $products = $user->get_selectable_products;
+ }
+
+ # If the user has editcomponents privs for some products only,
+ # we have to restrict the list of products to display.
+ unless ($user->in_group('editcomponents')) {
+ $products = $user->get_products_by_permission('editcomponents');
if (Bugzilla->params->{'useclassification'}) {
- $classification = Bugzilla::Classification->check($classification_name);
- $products = $user->get_selectable_products($classification->id);
- $vars->{'classification'} = $classification;
- } else {
- $products = $user->get_selectable_products;
+ @$products = grep { $_->classification_id == $classification->id } @$products;
}
+ }
+ $vars->{'products'} = $products;
+ $vars->{'showbugcounts'} = $cgi->param('showbugcounts') ? 1 : 0;
- # If the user has editcomponents privs for some products only,
- # we have to restrict the list of products to display.
- unless ($user->in_group('editcomponents')) {
- $products = $user->get_products_by_permission('editcomponents');
- if (Bugzilla->params->{'useclassification'}) {
- @$products = grep {$_->classification_id == $classification->id} @$products;
- }
- }
- $vars->{'products'} = $products;
- $vars->{'showbugcounts'} = $cgi->param('showbugcounts') ? 1 : 0;
-
- $template->process("admin/products/list.html.tmpl", $vars)
- || ThrowTemplateError($template->error());
- exit;
+ $template->process("admin/products/list.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
+ exit;
}
-
-
#
# action='add' -> present form for parameters for new product
#
@@ -123,23 +122,23 @@ if (!$action && !$product_name) {
#
if ($action eq 'add') {
- # The user must have the global editcomponents privs to add
- # new products.
- $user->in_group('editcomponents')
- || ThrowUserError("auth_failure", {group => "editcomponents",
- action => "add",
- object => "products"});
- if (Bugzilla->params->{'useclassification'}) {
- my $classification = Bugzilla::Classification->check($classification_name);
- $vars->{'classification'} = $classification;
- }
- $vars->{'token'} = issue_session_token('add_product');
+ # The user must have the global editcomponents privs to add
+ # new products.
+ $user->in_group('editcomponents')
+ || ThrowUserError("auth_failure",
+ {group => "editcomponents", action => "add", object => "products"});
- $template->process("admin/products/create.html.tmpl", $vars)
- || ThrowTemplateError($template->error());
+ if (Bugzilla->params->{'useclassification'}) {
+ my $classification = Bugzilla::Classification->check($classification_name);
+ $vars->{'classification'} = $classification;
+ }
+ $vars->{'token'} = issue_session_token('add_product');
+
+ $template->process("admin/products/create.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
- exit;
+ exit;
}
@@ -148,39 +147,40 @@ if ($action eq 'add') {
#
if ($action eq 'new') {
- # The user must have the global editcomponents privs to add
- # new products.
- $user->in_group('editcomponents')
- || ThrowUserError("auth_failure", {group => "editcomponents",
- action => "add",
- object => "products"});
-
- check_token_data($token, 'add_product');
-
- my %create_params = (
- classification => $classification_name,
- name => $product_name,
- description => scalar $cgi->param('description'),
- version => scalar $cgi->param('version'),
- defaultmilestone => scalar $cgi->param('defaultmilestone'),
- isactive => scalar $cgi->param('is_active'),
- create_series => scalar $cgi->param('createseries'),
- allows_unconfirmed => scalar $cgi->param('allows_unconfirmed'),
- );
- my $product = Bugzilla::Product->create(\%create_params);
-
- delete_token($token);
-
- $vars->{'message'} = 'product_created';
- $vars->{'product'} = $product;
- if (Bugzilla->params->{'useclassification'}) {
- $vars->{'classification'} = new Bugzilla::Classification($product->classification_id);
- }
- $vars->{'token'} = issue_session_token('edit_product');
- $template->process("admin/products/edit.html.tmpl", $vars)
- || ThrowTemplateError($template->error());
- exit;
+ # The user must have the global editcomponents privs to add
+ # new products.
+ $user->in_group('editcomponents')
+ || ThrowUserError("auth_failure",
+ {group => "editcomponents", action => "add", object => "products"});
+
+ check_token_data($token, 'add_product');
+
+ my %create_params = (
+ classification => $classification_name,
+ name => $product_name,
+ description => scalar $cgi->param('description'),
+ version => scalar $cgi->param('version'),
+ defaultmilestone => scalar $cgi->param('defaultmilestone'),
+ isactive => scalar $cgi->param('is_active'),
+ create_series => scalar $cgi->param('createseries'),
+ allows_unconfirmed => scalar $cgi->param('allows_unconfirmed'),
+ );
+ my $product = Bugzilla::Product->create(\%create_params);
+
+ delete_token($token);
+
+ $vars->{'message'} = 'product_created';
+ $vars->{'product'} = $product;
+ if (Bugzilla->params->{'useclassification'}) {
+ $vars->{'classification'}
+ = new Bugzilla::Classification($product->classification_id);
+ }
+ $vars->{'token'} = issue_session_token('edit_product');
+
+ $template->process("admin/products/edit.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
+ exit;
}
#
@@ -190,19 +190,20 @@ if ($action eq 'new') {
#
if ($action eq 'del') {
- my $product = $user->check_can_admin_product($product_name);
+ my $product = $user->check_can_admin_product($product_name);
- if (Bugzilla->params->{'useclassification'}) {
- $vars->{'classification'} = new Bugzilla::Classification($product->classification_id);
- }
- $vars->{'product'} = $product;
- $vars->{'token'} = issue_session_token('delete_product');
+ if (Bugzilla->params->{'useclassification'}) {
+ $vars->{'classification'}
+ = new Bugzilla::Classification($product->classification_id);
+ }
+ $vars->{'product'} = $product;
+ $vars->{'token'} = issue_session_token('delete_product');
- Bugzilla::Hook::process('product_confirm_delete', { vars => $vars });
+ Bugzilla::Hook::process('product_confirm_delete', {vars => $vars});
- $template->process("admin/products/confirm-delete.html.tmpl", $vars)
- || ThrowTemplateError($template->error());
- exit;
+ $template->process("admin/products/confirm-delete.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
+ exit;
}
#
@@ -210,36 +211,40 @@ if ($action eq 'del') {
#
if ($action eq 'delete') {
- my $product = $user->check_can_admin_product($product_name);
- check_token_data($token, 'delete_product');
+ my $product = $user->check_can_admin_product($product_name);
+ check_token_data($token, 'delete_product');
- $product->remove_from_db({ delete_series => scalar $cgi->param('delete_series')});
- delete_token($token);
+ $product->remove_from_db(
+ {delete_series => scalar $cgi->param('delete_series')});
+ delete_token($token);
- $vars->{'message'} = 'product_deleted';
- $vars->{'product'} = $product;
- $vars->{'no_edit_product_link'} = 1;
+ $vars->{'message'} = 'product_deleted';
+ $vars->{'product'} = $product;
+ $vars->{'no_edit_product_link'} = 1;
- if (Bugzilla->params->{'useclassification'}) {
- $vars->{'classifications'} = $user->in_group('editcomponents') ?
- [Bugzilla::Classification->get_all] : $user->get_selectable_classifications;
+ if (Bugzilla->params->{'useclassification'}) {
+ $vars->{'classifications'}
+ = $user->in_group('editcomponents')
+ ? [Bugzilla::Classification->get_all]
+ : $user->get_selectable_classifications;
- $template->process("admin/products/list-classifications.html.tmpl", $vars)
- || ThrowTemplateError($template->error());
- }
- else {
- my $products = $user->get_selectable_products;
- # If the user has editcomponents privs for some products only,
- # we have to restrict the list of products to display.
- unless ($user->in_group('editcomponents')) {
- $products = $user->get_products_by_permission('editcomponents');
- }
- $vars->{'products'} = $products;
-
- $template->process("admin/products/list.html.tmpl", $vars)
- || ThrowTemplateError($template->error());
+ $template->process("admin/products/list-classifications.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
+ }
+ else {
+ my $products = $user->get_selectable_products;
+
+ # If the user has editcomponents privs for some products only,
+ # we have to restrict the list of products to display.
+ unless ($user->in_group('editcomponents')) {
+ $products = $user->get_products_by_permission('editcomponents');
}
- exit;
+ $vars->{'products'} = $products;
+
+ $template->process("admin/products/list.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
+ }
+ exit;
}
#
@@ -250,48 +255,50 @@ if ($action eq 'delete') {
#
if ($action eq 'edit' || (!$action && $product_name)) {
- my $product = $user->check_can_admin_product($product_name);
-
- if (Bugzilla->params->{'useclassification'}) {
- $vars->{'classification'} = new Bugzilla::Classification($product->classification_id);
- }
- $vars->{'product'} = $product;
- $vars->{'token'} = issue_session_token('edit_product');
-
- $template->process("admin/products/edit.html.tmpl", $vars)
- || ThrowTemplateError($template->error());
- exit;
+ my $product = $user->check_can_admin_product($product_name);
+
+ if (Bugzilla->params->{'useclassification'}) {
+ $vars->{'classification'}
+ = new Bugzilla::Classification($product->classification_id);
+ }
+ $vars->{'product'} = $product;
+ $vars->{'token'} = issue_session_token('edit_product');
+
+ $template->process("admin/products/edit.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
+ exit;
}
#
# action='update' -> update the product
#
if ($action eq 'update') {
- check_token_data($token, 'edit_product');
- my $product_old_name = trim($cgi->param('product_old_name') || '');
- my $product = $user->check_can_admin_product($product_old_name);
-
- $product->set_all({
- name => $product_name,
- description => scalar $cgi->param('description'),
- is_active => scalar $cgi->param('is_active'),
- allows_unconfirmed => scalar $cgi->param('allows_unconfirmed'),
- default_milestone => scalar $cgi->param('defaultmilestone'),
- });
-
- my $changes = $product->update();
-
- delete_token($token);
-
- if (Bugzilla->params->{'useclassification'}) {
- $vars->{'classification'} = new Bugzilla::Classification($product->classification_id);
- }
- $vars->{'product'} = $product;
- $vars->{'changes'} = $changes;
-
- $template->process("admin/products/updated.html.tmpl", $vars)
- || ThrowTemplateError($template->error());
- exit;
+ check_token_data($token, 'edit_product');
+ my $product_old_name = trim($cgi->param('product_old_name') || '');
+ my $product = $user->check_can_admin_product($product_old_name);
+
+ $product->set_all({
+ name => $product_name,
+ description => scalar $cgi->param('description'),
+ is_active => scalar $cgi->param('is_active'),
+ allows_unconfirmed => scalar $cgi->param('allows_unconfirmed'),
+ default_milestone => scalar $cgi->param('defaultmilestone'),
+ });
+
+ my $changes = $product->update();
+
+ delete_token($token);
+
+ if (Bugzilla->params->{'useclassification'}) {
+ $vars->{'classification'}
+ = new Bugzilla::Classification($product->classification_id);
+ }
+ $vars->{'product'} = $product;
+ $vars->{'changes'} = $changes;
+
+ $template->process("admin/products/updated.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
+ exit;
}
#
@@ -299,14 +306,14 @@ if ($action eq 'update') {
#
if ($action eq 'editgroupcontrols') {
- my $product = $user->check_can_admin_product($product_name);
+ my $product = $user->check_can_admin_product($product_name);
- $vars->{'product'} = $product;
- $vars->{'token'} = issue_session_token('edit_group_controls');
+ $vars->{'product'} = $product;
+ $vars->{'token'} = issue_session_token('edit_group_controls');
- $template->process("admin/products/groupcontrol/edit.html.tmpl", $vars)
- || ThrowTemplateError($template->error());
- exit;
+ $template->process("admin/products/groupcontrol/edit.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
+ exit;
}
#
@@ -314,44 +321,45 @@ if ($action eq 'editgroupcontrols') {
#
if ($action eq 'updategroupcontrols') {
- my $product = $user->check_can_admin_product($product_name);
- check_token_data($token, 'edit_group_controls');
-
- my @now_na = ();
- my @now_mandatory = ();
- foreach my $f ($cgi->param()) {
- if ($f =~ /^membercontrol_(\d+)$/) {
- my $id = $1;
- if ($cgi->param($f) == CONTROLMAPNA) {
- push @now_na,$id;
- } elsif ($cgi->param($f) == CONTROLMAPMANDATORY) {
- push @now_mandatory,$id;
- }
- }
+ my $product = $user->check_can_admin_product($product_name);
+ check_token_data($token, 'edit_group_controls');
+
+ my @now_na = ();
+ my @now_mandatory = ();
+ foreach my $f ($cgi->param()) {
+ if ($f =~ /^membercontrol_(\d+)$/) {
+ my $id = $1;
+ if ($cgi->param($f) == CONTROLMAPNA) {
+ push @now_na, $id;
+ }
+ elsif ($cgi->param($f) == CONTROLMAPMANDATORY) {
+ push @now_mandatory, $id;
+ }
}
- if (!defined $cgi->param('confirmed')) {
- my $na_groups;
- if (@now_na) {
- $na_groups = $dbh->selectall_arrayref(
- 'SELECT groups.name, COUNT(bugs.bug_id) AS count
+ }
+ if (!defined $cgi->param('confirmed')) {
+ my $na_groups;
+ if (@now_na) {
+ $na_groups = $dbh->selectall_arrayref(
+ 'SELECT groups.name, COUNT(bugs.bug_id) AS count
FROM bugs
INNER JOIN bug_group_map
ON bug_group_map.bug_id = bugs.bug_id
INNER JOIN groups
ON bug_group_map.group_id = groups.id
WHERE groups.id IN (' . join(', ', @now_na) . ')
- AND bugs.product_id = ? ' .
- $dbh->sql_group_by('groups.name'),
- {'Slice' => {}}, $product->id);
- }
-
- # return the mandatory groups which need to have bug entries
- # added to the bug_group_map and the corresponding bug count
-
- my $mandatory_groups;
- if (@now_mandatory) {
- $mandatory_groups = $dbh->selectall_arrayref(
- 'SELECT groups.name,
+ AND bugs.product_id = ? ' . $dbh->sql_group_by('groups.name'),
+ {'Slice' => {}}, $product->id
+ );
+ }
+
+ # return the mandatory groups which need to have bug entries
+ # added to the bug_group_map and the corresponding bug count
+
+ my $mandatory_groups;
+ if (@now_mandatory) {
+ $mandatory_groups = $dbh->selectall_arrayref(
+ 'SELECT groups.name,
(SELECT COUNT(bugs.bug_id)
FROM bugs
WHERE bugs.product_id = ?
@@ -361,46 +369,51 @@ if ($action eq 'updategroupcontrols') {
AS count
FROM groups
WHERE groups.id IN (' . join(', ', @now_mandatory) . ')
- ORDER BY groups.name',
- {'Slice' => {}}, $product->id);
- # remove zero counts
- @$mandatory_groups = grep { $_->{count} } @$mandatory_groups;
-
- }
- if (($na_groups && scalar(@$na_groups))
- || ($mandatory_groups && scalar(@$mandatory_groups)))
- {
- $vars->{'product'} = $product;
- $vars->{'na_groups'} = $na_groups;
- $vars->{'mandatory_groups'} = $mandatory_groups;
- $template->process("admin/products/groupcontrol/confirm-edit.html.tmpl", $vars)
- || ThrowTemplateError($template->error());
- exit;
- }
- }
+ ORDER BY groups.name', {'Slice' => {}}, $product->id
+ );
+
+ # remove zero counts
+ @$mandatory_groups = grep { $_->{count} } @$mandatory_groups;
- my $groups = Bugzilla::Group->match({isactive => 1, isbuggroup => 1});
- foreach my $group (@$groups) {
- my $group_id = $group->id;
- $product->set_group_controls($group,
- {entry => scalar $cgi->param("entry_$group_id") || 0,
- membercontrol => scalar $cgi->param("membercontrol_$group_id") || CONTROLMAPNA,
- othercontrol => scalar $cgi->param("othercontrol_$group_id") || CONTROLMAPNA,
- canedit => scalar $cgi->param("canedit_$group_id") || 0,
- editcomponents => scalar $cgi->param("editcomponents_$group_id") || 0,
- editbugs => scalar $cgi->param("editbugs_$group_id") || 0,
- canconfirm => scalar $cgi->param("canconfirm_$group_id") || 0});
}
- my $changes = $product->update;
+ if ( ($na_groups && scalar(@$na_groups))
+ || ($mandatory_groups && scalar(@$mandatory_groups)))
+ {
+ $vars->{'product'} = $product;
+ $vars->{'na_groups'} = $na_groups;
+ $vars->{'mandatory_groups'} = $mandatory_groups;
+ $template->process("admin/products/groupcontrol/confirm-edit.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
+ exit;
+ }
+ }
+
+ my $groups = Bugzilla::Group->match({isactive => 1, isbuggroup => 1});
+ foreach my $group (@$groups) {
+ my $group_id = $group->id;
+ $product->set_group_controls(
+ $group,
+ {
+ entry => scalar $cgi->param("entry_$group_id") || 0,
+ membercontrol => scalar $cgi->param("membercontrol_$group_id") || CONTROLMAPNA,
+ othercontrol => scalar $cgi->param("othercontrol_$group_id") || CONTROLMAPNA,
+ canedit => scalar $cgi->param("canedit_$group_id") || 0,
+ editcomponents => scalar $cgi->param("editcomponents_$group_id") || 0,
+ editbugs => scalar $cgi->param("editbugs_$group_id") || 0,
+ canconfirm => scalar $cgi->param("canconfirm_$group_id") || 0
+ }
+ );
+ }
+ my $changes = $product->update;
- delete_token($token);
+ delete_token($token);
- $vars->{'product'} = $product;
- $vars->{'changes'} = $changes;
+ $vars->{'product'} = $product;
+ $vars->{'changes'} = $changes;
- $template->process("admin/products/groupcontrol/updated.html.tmpl", $vars)
- || ThrowTemplateError($template->error());
- exit;
+ $template->process("admin/products/groupcontrol/updated.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
+ exit;
}
# No valid action found