Rubber-stamped by Brady Eidson.
[webbrowser.git] / BugsSite / config.cgi
blob33539675c77194f6c979975d853d17782d5f1d46
1 #!/usr/bin/env perl -wT
2 # -*- Mode: perl; indent-tabs-mode: nil -*-
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/
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.
14 # The Original Code is the Bugzilla Bug Tracking System.
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.
21 # Contributor(s): Terry Weissman <terry@mozilla.org>
22 # Myk Melez <myk@mozilla.org>
24 ################################################################################
25 # Script Initialization
26 ################################################################################
28 # Make it harder for us to do dangerous things in Perl.
29 use strict;
31 use lib qw(. lib);
33 use Bugzilla;
34 use Bugzilla::Constants;
35 use Bugzilla::Error;
36 use Bugzilla::Keyword;
37 use Bugzilla::Status;
38 use Bugzilla::Field;
40 my $user = Bugzilla->login(LOGIN_OPTIONAL);
41 my $cgi = Bugzilla->cgi;
43 # If the 'requirelogin' parameter is on and the user is not
44 # authenticated, return empty fields.
45 if (Bugzilla->params->{'requirelogin'} && !$user->id) {
46 display_data();
49 # Pass a bunch of Bugzilla configuration to the templates.
50 my $vars = {};
51 $vars->{'priority'} = get_legal_field_values('priority');
52 $vars->{'severity'} = get_legal_field_values('bug_severity');
53 $vars->{'platform'} = get_legal_field_values('rep_platform');
54 $vars->{'op_sys'} = get_legal_field_values('op_sys');
55 $vars->{'keyword'} = [map($_->name, Bugzilla::Keyword->get_all)];
56 $vars->{'resolution'} = get_legal_field_values('resolution');
57 $vars->{'status'} = get_legal_field_values('bug_status');
58 $vars->{'custom_fields'} =
59 [ grep {$_->type == FIELD_TYPE_SINGLE_SELECT || $_->type == FIELD_TYPE_MULTI_SELECT}
60 Bugzilla->active_custom_fields ];
62 # Include a list of product objects.
63 if ($cgi->param('product')) {
64 my @products = $cgi->param('product');
65 foreach my $product_name (@products) {
66 # We don't use check_product because config.cgi outputs mostly
67 # in XML and JS and we don't want to display an HTML error
68 # instead of that.
69 my $product = new Bugzilla::Product({ name => $product_name });
70 if ($product && $user->can_see_product($product->name)) {
71 push (@{$vars->{'products'}}, $product);
74 } else {
75 $vars->{'products'} = $user->get_selectable_products;
78 # Create separate lists of open versus resolved statuses. This should really
79 # be made part of the configuration.
80 my @open_status;
81 my @closed_status;
82 foreach my $status (@{$vars->{'status'}}) {
83 is_open_state($status) ? push(@open_status, $status)
84 : push(@closed_status, $status);
86 $vars->{'open_status'} = \@open_status;
87 $vars->{'closed_status'} = \@closed_status;
89 # Generate a list of fields that can be queried.
90 my @fields = @{Bugzilla::Field->match({obsolete => 0})};
91 # Exclude fields the user cannot query.
92 if (!Bugzilla->user->in_group(Bugzilla->params->{'timetrackinggroup'})) {
93 @fields = grep { $_->name !~ /^(estimated_time|remaining_time|work_time|percentage_complete|deadline)$/ } @fields;
95 $vars->{'field'} = \@fields;
97 display_data($vars);
100 sub display_data {
101 my $vars = shift;
103 my $cgi = Bugzilla->cgi;
104 my $template = Bugzilla->template;
106 # Determine how the user would like to receive the output;
107 # default is JavaScript.
108 my $format = $template->get_format("config", scalar($cgi->param('format')),
109 scalar($cgi->param('ctype')) || "js");
111 # Return HTTP headers.
112 print "Content-Type: $format->{'ctype'}\n\n";
114 # Generate the configuration file and return it to the user.
115 $template->process($format->{'template'}, $vars)
116 || ThrowTemplateError($template->error());
117 exit;