/bugzilla-4.2.1/describecomponents.cgi

# · Perl · 88 lines · 36 code · 13 blank · 39 comment · 8 complexity · ad3564bb38ddb3deb925b7903517767a MD5 · raw file

  1. #!/usr/bin/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 $template = Bugzilla->template;
  34. my $vars = {};
  35. print $cgi->header();
  36. # This script does nothing but displaying mostly static data.
  37. Bugzilla->switch_to_shadow_db;
  38. my $product_name = trim($cgi->param('product') || '');
  39. my $product = new Bugzilla::Product({'name' => $product_name});
  40. unless ($product && $user->can_access_product($product->name)) {
  41. # Products which the user is allowed to see.
  42. my @products = @{$user->get_accessible_products};
  43. if (scalar(@products) == 0) {
  44. ThrowUserError("no_products");
  45. }
  46. # If there is only one product available but the user entered
  47. # another product name, we display a list with this single
  48. # product only, to not confuse the user with components of a
  49. # product he didn't request.
  50. elsif (scalar(@products) > 1 || $product_name) {
  51. $vars->{'classifications'} = [{object => undef, products => \@products}];
  52. $vars->{'target'} = "describecomponents.cgi";
  53. # If an invalid product name is given, or the user is not
  54. # allowed to access that product, a message is displayed
  55. # with a list of the products the user can choose from.
  56. if ($product_name) {
  57. $vars->{'message'} = "product_invalid";
  58. # Do not use $product->name here, else you could use
  59. # this way to determine whether the product exists or not.
  60. $vars->{'product'} = $product_name;
  61. }
  62. $template->process("global/choose-product.html.tmpl", $vars)
  63. || ThrowTemplateError($template->error());
  64. exit;
  65. }
  66. # If there is only one product available and the user didn't specify
  67. # any product name, we show this product.
  68. $product = $products[0];
  69. }
  70. ######################################################################
  71. # End Data/Security Validation
  72. ######################################################################
  73. $vars->{'product'} = $product;
  74. $template->process("reports/components.html.tmpl", $vars)
  75. || ThrowTemplateError($template->error());