You need to sign in or sign up before continuing.
describecomponents.cgi 2.55 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
my $user = Bugzilla->login();
23
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
    # Products which the user is allowed to see.
37
    my @products = @{$user->get_accessible_products};
38

39
    if (scalar(@products) == 0) {
40
        ThrowUserError("no_products");
41
    }
42 43 44
    # 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
45
    # product they didn't request.
46
    elsif (scalar(@products) > 1 || $product_name) {
47
        $vars->{'classifications'} = sort_products_by_classification(\@products);
48 49 50 51
        $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.
52
        if ($product_name) {
53
            $vars->{'message'} = "product_invalid";
54 55 56
            # Do not use $product->name here, else you could use
            # this way to determine whether the product exists or not.
            $vars->{'product'} = $product_name;
57
        }
58

59 60
        $template->process("global/choose-product.html.tmpl", $vars)
          || ThrowTemplateError($template->error());
61 62
        exit;
    }
63

64 65 66
    # If there is only one product available and the user didn't specify
    # any product name, we show this product.
    $product = $products[0];
67 68 69 70 71 72
}

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

73
$vars->{'product'} = $product;
74

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