2003-03-27 03:07:02 +03:00
|
|
|
#!/usr/bin/perl -wT
|
2002-09-28 22:42:54 +04:00
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# The Original Code is the Bugzilla Bug Tracking System.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
# Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s): Myk Melez <myk@mozilla.org>
|
2006-05-29 21:24:54 +04:00
|
|
|
# Frédéric Buclin <LpSolit@gmail.com>
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Script Initialization
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# Make it harder for us to do dangerous things in Perl.
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
use lib qw(.);
|
2006-06-21 04:44:48 +04:00
|
|
|
|
2005-08-30 21:01:22 +04:00
|
|
|
use Bugzilla;
|
2006-06-21 04:44:48 +04:00
|
|
|
use Bugzilla::Util;
|
|
|
|
use Bugzilla::Error;
|
2002-09-28 22:42:54 +04:00
|
|
|
use Bugzilla::Flag;
|
|
|
|
use Bugzilla::FlagType;
|
|
|
|
use Bugzilla::User;
|
2006-05-29 21:24:54 +04:00
|
|
|
use Bugzilla::Product;
|
|
|
|
use Bugzilla::Component;
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
# Make sure the user is logged in.
|
2005-09-03 01:12:10 +04:00
|
|
|
my $user = Bugzilla->login();
|
|
|
|
my $cgi = Bugzilla->cgi;
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Main Body Execution
|
|
|
|
################################################################################
|
|
|
|
|
2005-08-30 21:01:22 +04:00
|
|
|
my $fields;
|
|
|
|
$fields->{'requester'}->{'type'} = 'single';
|
|
|
|
# If the user doesn't restrict his search to requests from the wind
|
|
|
|
# (requestee ne '-'), include the requestee for completion.
|
|
|
|
unless (defined $cgi->param('requestee')
|
|
|
|
&& $cgi->param('requestee') eq '-')
|
|
|
|
{
|
|
|
|
$fields->{'requestee'}->{'type'} = 'single';
|
|
|
|
}
|
|
|
|
|
|
|
|
Bugzilla::User::match_field($cgi, $fields);
|
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
queue();
|
|
|
|
exit;
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Functions
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
sub queue {
|
2004-03-06 11:54:17 +03:00
|
|
|
my $cgi = Bugzilla->cgi;
|
2006-09-05 17:04:52 +04:00
|
|
|
# There are some user privilege checks to do. We do them against the main DB.
|
2005-02-25 02:37:48 +03:00
|
|
|
my $dbh = Bugzilla->dbh;
|
2006-07-06 10:12:05 +04:00
|
|
|
my $template = Bugzilla->template;
|
|
|
|
my $user = Bugzilla->user;
|
|
|
|
my $userid = $user->id;
|
2006-09-05 17:04:52 +04:00
|
|
|
my $vars = {};
|
2006-03-09 00:35:54 +03:00
|
|
|
|
|
|
|
my $status = validateStatus($cgi->param('status'));
|
|
|
|
my $form_group = validateGroup($cgi->param('group'));
|
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
my $query =
|
|
|
|
# Select columns describing each flag, the bug/attachment on which
|
|
|
|
# it has been set, who set it, and of whom they are requesting it.
|
|
|
|
" SELECT flags.id, flagtypes.name,
|
|
|
|
flags.status,
|
|
|
|
flags.bug_id, bugs.short_desc,
|
|
|
|
products.name, components.name,
|
|
|
|
flags.attach_id, attachments.description,
|
|
|
|
requesters.realname, requesters.login_name,
|
|
|
|
requestees.realname, requestees.login_name,
|
2006-07-25 05:25:44 +04:00
|
|
|
" . $dbh->sql_date_format('flags.modification_date', '%Y.%m.%d %H:%i') .
|
2002-09-28 22:42:54 +04:00
|
|
|
# Use the flags and flagtypes tables for information about the flags,
|
|
|
|
# the bugs and attachments tables for target info, the profiles tables
|
|
|
|
# for setter and requestee info, the products/components tables
|
|
|
|
# so we can display product and component names, and the bug_group_map
|
2005-04-16 04:37:23 +04:00
|
|
|
# table to help us weed out secure bugs to which the user should not have
|
|
|
|
# access.
|
|
|
|
"
|
|
|
|
FROM flags
|
|
|
|
LEFT JOIN attachments
|
2006-10-15 01:04:56 +04:00
|
|
|
ON flags.attach_id = attachments.attach_id
|
2005-04-16 04:37:23 +04:00
|
|
|
INNER JOIN flagtypes
|
2005-04-05 01:52:06 +04:00
|
|
|
ON flags.type_id = flagtypes.id
|
2005-04-16 04:37:23 +04:00
|
|
|
INNER JOIN profiles AS requesters
|
2005-04-05 01:52:06 +04:00
|
|
|
ON flags.setter_id = requesters.userid
|
2005-04-16 04:37:23 +04:00
|
|
|
LEFT JOIN profiles AS requestees
|
2005-04-05 01:52:06 +04:00
|
|
|
ON flags.requestee_id = requestees.userid
|
2005-04-16 04:37:23 +04:00
|
|
|
INNER JOIN bugs
|
2005-04-05 01:52:06 +04:00
|
|
|
ON flags.bug_id = bugs.bug_id
|
2005-11-16 04:03:52 +03:00
|
|
|
INNER JOIN products
|
2005-04-05 01:52:06 +04:00
|
|
|
ON bugs.product_id = products.id
|
2005-11-16 04:03:52 +03:00
|
|
|
INNER JOIN components
|
2005-04-05 01:52:06 +04:00
|
|
|
ON bugs.component_id = components.id
|
2005-04-16 04:37:23 +04:00
|
|
|
LEFT JOIN bug_group_map AS bgmap
|
2005-04-05 01:52:06 +04:00
|
|
|
ON bgmap.bug_id = bugs.bug_id
|
2005-04-16 04:37:23 +04:00
|
|
|
AND bgmap.group_id NOT IN (" .
|
2005-09-03 01:12:10 +04:00
|
|
|
join(', ', (-1, values(%{$user->groups}))) . ")
|
2005-04-16 04:37:23 +04:00
|
|
|
LEFT JOIN cc AS ccmap
|
2005-09-03 01:12:10 +04:00
|
|
|
ON ccmap.who = $userid
|
|
|
|
AND ccmap.bug_id = bugs.bug_id
|
2005-04-16 04:37:23 +04:00
|
|
|
" .
|
|
|
|
|
|
|
|
# Weed out bug the user does not have access to
|
|
|
|
" WHERE ((bgmap.group_id IS NULL) OR
|
|
|
|
(ccmap.who IS NOT NULL AND cclist_accessible = 1) OR
|
2005-09-03 01:12:10 +04:00
|
|
|
(bugs.reporter = $userid AND bugs.reporter_accessible = 1) OR
|
2005-11-16 04:03:52 +03:00
|
|
|
(bugs.assigned_to = $userid) " .
|
2006-07-04 01:26:22 +04:00
|
|
|
(Bugzilla->params->{'useqacontact'} ? "OR
|
2005-11-16 04:03:52 +03:00
|
|
|
(bugs.qa_contact = $userid))" : ")");
|
2006-10-15 01:04:56 +04:00
|
|
|
|
|
|
|
unless ($user->is_insider) {
|
|
|
|
$query .= " AND (attachments.attach_id IS NULL
|
|
|
|
OR attachments.isprivate = 0
|
|
|
|
OR attachments.submitter_id = $userid)";
|
|
|
|
}
|
|
|
|
|
2002-11-19 07:52:54 +03:00
|
|
|
# Limit query to pending requests.
|
2006-03-09 00:35:54 +03:00
|
|
|
$query .= " AND flags.status = '?' " unless $status;
|
2002-11-19 07:52:54 +03:00
|
|
|
|
|
|
|
# The set of criteria by which we filter records to display in the queue.
|
2006-09-05 17:04:52 +04:00
|
|
|
# We now move to the shadow DB to query the DB.
|
2002-11-19 07:52:54 +03:00
|
|
|
my @criteria = ();
|
2006-09-05 17:04:52 +04:00
|
|
|
$dbh = Bugzilla->switch_to_shadow_db;
|
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
# A list of columns to exclude from the report because the report conditions
|
|
|
|
# limit the data being displayed to exact matches for those columns.
|
|
|
|
# In other words, if we are only displaying "pending" , we don't
|
|
|
|
# need to display a "status" column in the report because the value for that
|
|
|
|
# column will always be the same.
|
|
|
|
my @excluded_columns = ();
|
|
|
|
|
|
|
|
# Filter requests by status: "pending", "granted", "denied", "all"
|
|
|
|
# (which means any), or "fulfilled" (which means "granted" or "denied").
|
2006-03-09 00:35:54 +03:00
|
|
|
if ($status) {
|
|
|
|
if ($status eq "+-") {
|
2002-11-19 07:52:54 +03:00
|
|
|
push(@criteria, "flags.status IN ('+', '-')");
|
2004-03-06 11:54:17 +03:00
|
|
|
push(@excluded_columns, 'status') unless $cgi->param('do_union');
|
2002-11-19 07:52:54 +03:00
|
|
|
}
|
2006-03-09 00:35:54 +03:00
|
|
|
elsif ($status ne "all") {
|
|
|
|
push(@criteria, "flags.status = '$status'");
|
2004-03-06 11:54:17 +03:00
|
|
|
push(@excluded_columns, 'status') unless $cgi->param('do_union');
|
2002-11-19 07:52:54 +03:00
|
|
|
}
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Filter results by exact email address of requester or requestee.
|
2004-03-06 11:54:17 +03:00
|
|
|
if (defined $cgi->param('requester') && $cgi->param('requester') ne "") {
|
2005-10-26 20:15:50 +04:00
|
|
|
my $requester = $dbh->quote($cgi->param('requester'));
|
|
|
|
trick_taint($requester); # Quoted above
|
|
|
|
push(@criteria, $dbh->sql_istrcmp('requesters.login_name', $requester));
|
2004-03-06 11:54:17 +03:00
|
|
|
push(@excluded_columns, 'requester') unless $cgi->param('do_union');
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
2004-03-06 11:54:17 +03:00
|
|
|
if (defined $cgi->param('requestee') && $cgi->param('requestee') ne "") {
|
2004-10-25 03:34:20 +04:00
|
|
|
if ($cgi->param('requestee') ne "-") {
|
2005-10-26 20:15:50 +04:00
|
|
|
my $requestee = $dbh->quote($cgi->param('requestee'));
|
|
|
|
trick_taint($requestee); # Quoted above
|
2005-07-08 06:31:43 +04:00
|
|
|
push(@criteria, $dbh->sql_istrcmp('requestees.login_name',
|
2005-10-26 20:15:50 +04:00
|
|
|
$requestee));
|
2004-10-25 03:34:20 +04:00
|
|
|
}
|
|
|
|
else { push(@criteria, "flags.requestee_id IS NULL") }
|
2004-03-06 11:54:17 +03:00
|
|
|
push(@excluded_columns, 'requestee') unless $cgi->param('do_union');
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Filter results by exact product or component.
|
2004-03-06 11:54:17 +03:00
|
|
|
if (defined $cgi->param('product') && $cgi->param('product') ne "") {
|
2006-05-29 21:24:54 +04:00
|
|
|
my $product = Bugzilla::Product::check_product(scalar $cgi->param('product'));
|
|
|
|
push(@criteria, "bugs.product_id = " . $product->id);
|
|
|
|
push(@excluded_columns, 'product') unless $cgi->param('do_union');
|
|
|
|
if (defined $cgi->param('component') && $cgi->param('component') ne "") {
|
|
|
|
my $component =
|
|
|
|
Bugzilla::Component::check_component($product, scalar $cgi->param('component'));
|
|
|
|
push(@criteria, "bugs.component_id = " . $component->id);
|
|
|
|
push(@excluded_columns, 'component') unless $cgi->param('do_union');
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
}
|
2006-05-29 21:24:54 +04:00
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
# Filter results by flag types.
|
2004-03-06 11:54:17 +03:00
|
|
|
my $form_type = $cgi->param('type');
|
|
|
|
if (defined $form_type && !grep($form_type eq $_, ("", "all"))) {
|
2002-09-28 22:42:54 +04:00
|
|
|
# Check if any matching types are for attachments. If not, don't show
|
|
|
|
# the attachment column in the report.
|
2006-07-25 04:24:54 +04:00
|
|
|
my $has_attachment_type =
|
|
|
|
Bugzilla::FlagType::count({ 'name' => $form_type,
|
|
|
|
'target_type' => 'attachment' });
|
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
if (!$has_attachment_type) { push(@excluded_columns, 'attachment') }
|
2005-10-26 20:15:50 +04:00
|
|
|
|
|
|
|
my $quoted_form_type = $dbh->quote($form_type);
|
|
|
|
trick_taint($quoted_form_type); # Already SQL quoted
|
|
|
|
push(@criteria, "flagtypes.name = " . $quoted_form_type);
|
2004-03-06 11:54:17 +03:00
|
|
|
push(@excluded_columns, 'type') unless $cgi->param('do_union');
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|
2002-11-19 07:52:54 +03:00
|
|
|
# Add the criteria to the query. We do an intersection by default
|
|
|
|
# but do a union if the "do_union" URL parameter (for which there is no UI
|
|
|
|
# because it's an advanced feature that people won't usually want) is true.
|
2004-03-06 11:54:17 +03:00
|
|
|
my $and_or = $cgi->param('do_union') ? " OR " : " AND ";
|
2002-11-19 07:52:54 +03:00
|
|
|
$query .= " AND (" . join($and_or, @criteria) . ") " if scalar(@criteria);
|
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
# Group the records by flag ID so we don't get multiple rows of data
|
|
|
|
# for each flag. This is only necessary because of the code that
|
|
|
|
# removes flags on bugs the user is unauthorized to access.
|
2005-03-16 03:27:15 +03:00
|
|
|
$query .= ' ' . $dbh->sql_group_by('flags.id',
|
|
|
|
'flagtypes.name, flags.status, flags.bug_id, bugs.short_desc,
|
|
|
|
products.name, components.name, flags.attach_id,
|
|
|
|
attachments.description, requesters.realname,
|
|
|
|
requesters.login_name, requestees.realname,
|
2006-07-25 05:25:44 +04:00
|
|
|
requestees.login_name, flags.modification_date,
|
2005-03-16 03:27:15 +03:00
|
|
|
cclist_accessible, bugs.reporter, bugs.reporter_accessible,
|
|
|
|
bugs.assigned_to');
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
# Group the records, in other words order them by the group column
|
|
|
|
# so the loop in the display template can break them up into separate
|
|
|
|
# tables every time the value in the group column changes.
|
2004-03-06 11:54:17 +03:00
|
|
|
|
|
|
|
$form_group ||= "requestee";
|
|
|
|
if ($form_group eq "requester") {
|
2002-09-28 22:42:54 +04:00
|
|
|
$query .= " ORDER BY requesters.realname, requesters.login_name";
|
|
|
|
}
|
2004-03-06 11:54:17 +03:00
|
|
|
elsif ($form_group eq "requestee") {
|
2002-09-28 22:42:54 +04:00
|
|
|
$query .= " ORDER BY requestees.realname, requestees.login_name";
|
|
|
|
}
|
2004-03-06 11:54:17 +03:00
|
|
|
elsif ($form_group eq "category") {
|
2002-09-28 22:42:54 +04:00
|
|
|
$query .= " ORDER BY products.name, components.name";
|
|
|
|
}
|
2004-03-06 11:54:17 +03:00
|
|
|
elsif ($form_group eq "type") {
|
2002-09-28 22:42:54 +04:00
|
|
|
$query .= " ORDER BY flagtypes.name";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Order the records (within each group).
|
2006-07-25 05:25:44 +04:00
|
|
|
$query .= " , flags.modification_date";
|
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
# Pass the query to the template for use when debugging this script.
|
|
|
|
$vars->{'query'} = $query;
|
2004-03-06 11:54:17 +03:00
|
|
|
$vars->{'debug'} = $cgi->param('debug') ? 1 : 0;
|
2002-09-28 22:42:54 +04:00
|
|
|
|
2005-10-26 20:15:50 +04:00
|
|
|
my $results = $dbh->selectall_arrayref($query);
|
2002-09-28 22:42:54 +04:00
|
|
|
my @requests = ();
|
2005-10-26 20:15:50 +04:00
|
|
|
foreach my $result (@$results) {
|
|
|
|
my @data = @$result;
|
2002-09-28 22:42:54 +04:00
|
|
|
my $request = {
|
|
|
|
'id' => $data[0] ,
|
|
|
|
'type' => $data[1] ,
|
|
|
|
'status' => $data[2] ,
|
|
|
|
'bug_id' => $data[3] ,
|
|
|
|
'bug_summary' => $data[4] ,
|
|
|
|
'category' => "$data[5]: $data[6]" ,
|
|
|
|
'attach_id' => $data[7] ,
|
|
|
|
'attach_summary' => $data[8] ,
|
|
|
|
'requester' => ($data[9] ? "$data[9] <$data[10]>" : $data[10]) ,
|
|
|
|
'requestee' => ($data[11] ? "$data[11] <$data[12]>" : $data[12]) ,
|
|
|
|
'created' => $data[13]
|
|
|
|
};
|
|
|
|
push(@requests, $request);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get a list of request type names to use in the filter form.
|
|
|
|
my @types = ("all");
|
2005-10-26 20:15:50 +04:00
|
|
|
my $flagtypes = $dbh->selectcol_arrayref(
|
|
|
|
"SELECT DISTINCT(name) FROM flagtypes ORDER BY name");
|
|
|
|
push(@types, @$flagtypes);
|
2006-09-05 17:04:52 +04:00
|
|
|
|
|
|
|
# We move back to the main DB to get the list of products the user can see.
|
|
|
|
$dbh = Bugzilla->switch_to_main_db;
|
|
|
|
|
2005-09-03 01:12:10 +04:00
|
|
|
$vars->{'products'} = $user->get_selectable_products;
|
2002-09-28 22:42:54 +04:00
|
|
|
$vars->{'excluded_columns'} = \@excluded_columns;
|
2004-03-06 11:54:17 +03:00
|
|
|
$vars->{'group_field'} = $form_group;
|
2002-09-28 22:42:54 +04:00
|
|
|
$vars->{'requests'} = \@requests;
|
|
|
|
$vars->{'types'} = \@types;
|
|
|
|
|
|
|
|
# Return the appropriate HTTP response headers.
|
2006-09-05 17:04:52 +04:00
|
|
|
print $cgi->header();
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
# Generate and return the UI (HTML page) from the appropriate template.
|
|
|
|
$template->process("request/queue.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
}
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Data Validation / Security Authorization
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
sub validateStatus {
|
2006-03-09 00:35:54 +03:00
|
|
|
my $status = shift;
|
2004-03-06 11:54:17 +03:00
|
|
|
return if !defined $status;
|
2006-03-09 00:35:54 +03:00
|
|
|
|
2004-03-06 11:54:17 +03:00
|
|
|
grep($status eq $_, qw(? +- + - all))
|
2003-09-14 10:05:23 +04:00
|
|
|
|| ThrowCodeError("flag_status_invalid",
|
2004-03-06 11:54:17 +03:00
|
|
|
{ status => $status });
|
2006-03-09 00:35:54 +03:00
|
|
|
trick_taint($status);
|
|
|
|
return $status;
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub validateGroup {
|
2006-03-09 00:35:54 +03:00
|
|
|
my $group = shift;
|
2004-03-06 11:54:17 +03:00
|
|
|
return if !defined $group;
|
2006-03-09 00:35:54 +03:00
|
|
|
|
2004-03-06 11:54:17 +03:00
|
|
|
grep($group eq $_, qw(requester requestee category type))
|
2002-09-28 22:42:54 +04:00
|
|
|
|| ThrowCodeError("request_queue_group_invalid",
|
2004-03-06 11:54:17 +03:00
|
|
|
{ group => $group });
|
2006-03-09 00:35:54 +03:00
|
|
|
trick_taint($group);
|
|
|
|
return $group;
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|