describecomponents.cgi 3.12 KB
Newer Older
1
#!/usr/bin/perl -wT
2 3
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
4 5 6 7 8 9 10 11 12 13
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
14
# The Original Code is the Bugzilla Bug Tracking System.
15
#
16
# The Initial Developer of the Original Code is Netscape Communications
17 18 19 20
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
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 25

use strict;
26
use lib qw(. lib);
27

28
use Bugzilla;
29
use Bugzilla::Constants;
30 31
use Bugzilla::Util;
use Bugzilla::Error;
32
use Bugzilla::Product;
33

34
my $user = Bugzilla->login();
35
my $cgi = Bugzilla->cgi;
36
my $template = Bugzilla->template;
37
my $vars = {};
38

39 40
print $cgi->header();

41 42 43
# This script does nothing but displaying mostly static data.
Bugzilla->switch_to_shadow_db;

44 45 46
my $product_name = trim($cgi->param('product') || '');
my $product = new Bugzilla::Product({'name' => $product_name});

47
unless ($product && $user->can_access_product($product->name)) {
48
    # Products which the user is allowed to see.
49
    my @products = @{$user->get_enterable_products};
50

51
    if (scalar(@products) == 0) {
52
        ThrowUserError("no_products");
53
    }
54 55 56 57 58
    # 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 he didn't request.
    elsif (scalar(@products) > 1 || $product_name) {
59
        $vars->{'classifications'} = [{object => undef, products => \@products}];
60 61 62 63
        $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.
64
        if ($product_name) {
65
            $vars->{'message'} = "product_invalid";
66 67 68
            # Do not use $product->name here, else you could use
            # this way to determine whether the product exists or not.
            $vars->{'product'} = $product_name;
69
        }
70

71 72
        $template->process("global/choose-product.html.tmpl", $vars)
          || ThrowTemplateError($template->error());
73 74
        exit;
    }
75

76 77 78
    # If there is only one product available and the user didn't specify
    # any product name, we show this product.
    $product = $products[0];
79 80 81 82 83 84
}

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

85
$vars->{'product'} = $product;
86

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