ddkilzer@apple.com | f573e63 | 2009-07-03 02:14:39 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl -wT |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 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 | # Myk Melez <myk@mozilla.org> |
| 23 | |
| 24 | ################################################################################ |
| 25 | # Script Initialization |
| 26 | ################################################################################ |
| 27 | |
| 28 | # Make it harder for us to do dangerous things in Perl. |
| 29 | use strict; |
| 30 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 31 | use lib qw(. lib); |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 32 | |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 33 | use Bugzilla; |
| 34 | use Bugzilla::Constants; |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 35 | use Bugzilla::Error; |
| 36 | use Bugzilla::Keyword; |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 37 | use Bugzilla::Status; |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 38 | use Bugzilla::Field; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 39 | |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 40 | my $user = Bugzilla->login(LOGIN_OPTIONAL); |
| 41 | my $cgi = Bugzilla->cgi; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 42 | |
| 43 | # If the 'requirelogin' parameter is on and the user is not |
| 44 | # authenticated, return empty fields. |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 45 | if (Bugzilla->params->{'requirelogin'} && !$user->id) { |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 46 | display_data(); |
| 47 | } |
| 48 | |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 49 | # Pass a bunch of Bugzilla configuration to the templates. |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 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'} = |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 59 | [ grep {$_->type == FIELD_TYPE_SINGLE_SELECT || $_->type == FIELD_TYPE_MULTI_SELECT} |
| 60 | Bugzilla->active_custom_fields ]; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 61 | |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 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); |
| 72 | } |
| 73 | } |
| 74 | } else { |
| 75 | $vars->{'products'} = $user->get_selectable_products; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 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; |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 82 | foreach my $status (@{$vars->{'status'}}) { |
| 83 | is_open_state($status) ? push(@open_status, $status) |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 84 | : push(@closed_status, $status); |
| 85 | } |
| 86 | $vars->{'open_status'} = \@open_status; |
| 87 | $vars->{'closed_status'} = \@closed_status; |
| 88 | |
| 89 | # Generate a list of fields that can be queried. |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 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; |
| 94 | } |
| 95 | $vars->{'field'} = \@fields; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 96 | |
| 97 | display_data($vars); |
| 98 | |
| 99 | |
| 100 | sub display_data { |
| 101 | my $vars = shift; |
| 102 | |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 103 | my $cgi = Bugzilla->cgi; |
| 104 | my $template = Bugzilla->template; |
| 105 | |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 106 | # Determine how the user would like to receive the output; |
| 107 | # default is JavaScript. |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 108 | my $format = $template->get_format("config", scalar($cgi->param('format')), |
| 109 | scalar($cgi->param('ctype')) || "js"); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 110 | |
| 111 | # Return HTTP headers. |
| 112 | print "Content-Type: $format->{'ctype'}\n\n"; |
| 113 | |
| 114 | # Generate the configuration file and return it to the user. |
| 115 | $template->process($format->{'template'}, $vars) |
| 116 | || ThrowTemplateError($template->error()); |
| 117 | exit; |
| 118 | } |