describecomponents.cgi 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env perl -wT
  2. # -*- Mode: perl; indent-tabs-mode: nil -*-
  3. #
  4. # The contents of this file are subject to the Mozilla Public
  5. # License Version 1.1 (the "License"); you may not use this file
  6. # except in compliance with the License. You may obtain a copy of
  7. # the License at http://www.mozilla.org/MPL/
  8. #
  9. # Software distributed under the License is distributed on an "AS
  10. # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  11. # implied. See the License for the specific language governing
  12. # rights and limitations under the License.
  13. #
  14. # The Original Code is the Bugzilla Bug Tracking System.
  15. #
  16. # The Initial Developer of the Original Code is Netscape Communications
  17. # Corporation. Portions created by Netscape are
  18. # Copyright (C) 1998 Netscape Communications Corporation. All
  19. # Rights Reserved.
  20. #
  21. # Contributor(s): Terry Weissman <terry@mozilla.org>
  22. # Bradley Baetz <bbaetz@student.usyd.edu.au>
  23. # Frédéric Buclin <LpSolit@gmail.com>
  24. use strict;
  25. use lib qw(. lib);
  26. use Bugzilla;
  27. use Bugzilla::Constants;
  28. use Bugzilla::Util;
  29. use Bugzilla::Error;
  30. use Bugzilla::Product;
  31. my $user = Bugzilla->login();
  32. my $cgi = Bugzilla->cgi;
  33. my $dbh = Bugzilla->dbh;
  34. my $template = Bugzilla->template;
  35. my $vars = {};
  36. print $cgi->header();
  37. my $product_name = trim($cgi->param('product') || '');
  38. my $product = new Bugzilla::Product({'name' => $product_name});
  39. unless ($product && $user->can_enter_product($product->name)) {
  40. # Products which the user is allowed to see.
  41. my @products = @{$user->get_enterable_products};
  42. if (scalar(@products) == 0) {
  43. ThrowUserError("no_products");
  44. }
  45. # If there is only one product available but the user entered
  46. # another product name, we display a list with this single
  47. # product only, to not confuse the user with components of a
  48. # product he didn't request.
  49. elsif (scalar(@products) > 1 || $product_name) {
  50. $vars->{'classifications'} = [{object => undef, products => \@products}];
  51. $vars->{'target'} = "describecomponents.cgi";
  52. # If an invalid product name is given, or the user is not
  53. # allowed to access that product, a message is displayed
  54. # with a list of the products the user can choose from.
  55. if ($product_name) {
  56. $vars->{'message'} = "product_invalid";
  57. # Do not use $product->name here, else you could use
  58. # this way to determine whether the product exists or not.
  59. $vars->{'product'} = $product_name;
  60. }
  61. $template->process("global/choose-product.html.tmpl", $vars)
  62. || ThrowTemplateError($template->error());
  63. exit;
  64. }
  65. # If there is only one product available and the user didn't specify
  66. # any product name, we show this product.
  67. $product = $products[0];
  68. }
  69. ######################################################################
  70. # End Data/Security Validation
  71. ######################################################################
  72. $vars->{'product'} = $product;
  73. $template->process("reports/components.html.tmpl", $vars)
  74. || ThrowTemplateError($template->error());