describecomponents.cgi 2.49 KB
Newer Older
1
#!/usr/bin/perl -T
2 3 4
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
#
6 7
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
8

9
use 5.10.1;
10
use strict;
11 12
use warnings;

13
use lib qw(. lib);
14

15
use Bugzilla;
16
use Bugzilla::Constants;
17 18
use Bugzilla::Util;
use Bugzilla::Error;
19
use Bugzilla::Classification;
20
use Bugzilla::Product;
21

22 23
my $user     = Bugzilla->login();
my $cgi      = Bugzilla->cgi;
24
my $template = Bugzilla->template;
25
my $vars     = {};
26

27 28
print $cgi->header();

29 30 31
# This script does nothing but displaying mostly static data.
Bugzilla->switch_to_shadow_db;

32 33 34
my $product_name = trim($cgi->param('product') || '');
my $product = new Bugzilla::Product({'name' => $product_name});

35
unless ($product && $user->can_access_product($product->name)) {
36

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
  # Products which the user is allowed to see.
  my @products = @{$user->get_accessible_products};

  if (scalar(@products) == 0) {
    ThrowUserError("no_products");
  }

  # If there is only one product available but the user entered
  # another product name, we display a list with this single
  # product only, to not confuse the user with components of a
  # product they didn't request.
  elsif (scalar(@products) > 1 || $product_name) {
    $vars->{'classifications'} = sort_products_by_classification(\@products);
    $vars->{'target'}          = "describecomponents.cgi";

    # If an invalid product name is given, or the user is not
    # allowed to access that product, a message is displayed
    # with a list of the products the user can choose from.
    if ($product_name) {
      $vars->{'message'} = "product_invalid";

      # Do not use $product->name here, else you could use
      # this way to determine whether the product exists or not.
      $vars->{'product'} = $product_name;
61
    }
62

63 64 65 66 67 68 69 70
    $template->process("global/choose-product.html.tmpl", $vars)
      || ThrowTemplateError($template->error());
    exit;
  }

  # If there is only one product available and the user didn't specify
  # any product name, we show this product.
  $product = $products[0];
71 72 73 74 75 76
}

######################################################################
# End Data/Security Validation
######################################################################

77
$vars->{'product'} = $product;
78

79 80
$template->process("reports/components.html.tmpl", $vars)
  || ThrowTemplateError($template->error());