2006-12-06 22:35:10 +03:00
|
|
|
#!/usr/bin/perl -wT
|
|
|
|
# -*- 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 Testopia System.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Greg Hendricks.
|
|
|
|
# Portions created by Greg Hendricks are Copyright (C) 2006
|
|
|
|
# Novell. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s): Greg Hendricks <ghendricks@novell.com>
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use lib ".";
|
|
|
|
|
|
|
|
use Bugzilla;
|
|
|
|
use Bugzilla::Constants;
|
2007-01-04 03:17:18 +03:00
|
|
|
use Bugzilla::Config;
|
2006-12-06 22:35:10 +03:00
|
|
|
use Bugzilla::Error;
|
|
|
|
use Bugzilla::Util;
|
|
|
|
use Bugzilla::Testopia::Util;
|
2007-01-04 03:17:18 +03:00
|
|
|
use Bugzilla::Testopia::Search;
|
|
|
|
use Bugzilla::Testopia::Table;
|
2007-03-09 00:20:38 +03:00
|
|
|
use Bugzilla::Testopia::TestRun;
|
2007-01-04 03:17:18 +03:00
|
|
|
|
2006-12-06 22:35:10 +03:00
|
|
|
use JSON;
|
|
|
|
|
|
|
|
use vars qw($vars);
|
2007-01-04 03:17:18 +03:00
|
|
|
|
2007-02-26 22:06:35 +03:00
|
|
|
Bugzilla->login(LOGIN_REQUIRED);
|
2007-01-04 03:17:18 +03:00
|
|
|
|
2006-12-06 22:35:10 +03:00
|
|
|
my $template = Bugzilla->template;
|
|
|
|
my $cgi = Bugzilla->cgi;
|
|
|
|
|
|
|
|
my $action = $cgi->param('action') || '';
|
2007-01-05 03:38:08 +03:00
|
|
|
my $term = trim($cgi->param('query')) || '';
|
|
|
|
|
2007-01-04 03:17:18 +03:00
|
|
|
push @{$::vars->{'style_urls'}}, 'testopia/css/default.css';
|
2006-12-06 22:35:10 +03:00
|
|
|
|
2007-01-05 03:38:08 +03:00
|
|
|
# Quicksearch allows a user to look up any of the major objects in Testopia
|
|
|
|
# using a simple prefix. For instance, e:linux will search for all environments
|
|
|
|
# with linux in the name or tr 33 will bring up Test Run 33.
|
|
|
|
# If only one is returned, we jump to the appropriate page, otherwise
|
|
|
|
# we display the list.
|
|
|
|
|
|
|
|
# If we have a term we are using this quicksearch
|
2007-01-04 03:17:18 +03:00
|
|
|
if ($term){
|
|
|
|
SWITCH: for ($term){
|
|
|
|
/^(tag)?[\s:-]+(.*)$/i && do{
|
|
|
|
my $text = trim($2);
|
|
|
|
print "Location: " . Param('urlbase') . "tr_tags.cgi?tag=" . $text . "\n\n";
|
|
|
|
last SWITCH;
|
|
|
|
};
|
|
|
|
/^(plan|TP|p)?[\s:-]+(.*)$/i && do{
|
|
|
|
my $text = trim($2);
|
|
|
|
if ($text =~ /^\d+$/){
|
|
|
|
print "Location: " . Param('urlbase') . "tr_show_plan.cgi?plan_id=" . $text . "\n\n";
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$cgi->param('current_tab', 'plan');
|
|
|
|
$cgi->param('name_type', 'anywordssubstr');
|
|
|
|
$cgi->param('name', $text);
|
|
|
|
|
|
|
|
my $search = Bugzilla::Testopia::Search->new($cgi);
|
|
|
|
my $table = Bugzilla::Testopia::Table->new('plan', 'tr_list_plans.cgi', $cgi, undef, $search->query);
|
|
|
|
if ($table->list_count == 1){
|
|
|
|
print "Location: " . Param('urlbase') . "tr_show_plan.cgi?plan_id=" . ${$table->list}[0]->id . "\n\n";
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
print "Location: " . Param('urlbase') . "tr_list_plans.cgi?" . $table->get_query_part . "\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
last SWITCH;
|
|
|
|
};
|
|
|
|
/^(run|TR|r)?[\s:-]+(.*)$/i && do{
|
|
|
|
my $text = trim($2);
|
|
|
|
if ($text =~ /^\d+$/){
|
|
|
|
print "Location: " . Param('urlbase') . "tr_show_run.cgi?run_id=" . $text . "\n\n";
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$cgi->param('current_tab', 'run');
|
|
|
|
$cgi->param('summary_type', 'anywordssubstr');
|
|
|
|
$cgi->param('summary', $text);
|
|
|
|
|
|
|
|
my $search = Bugzilla::Testopia::Search->new($cgi);
|
|
|
|
my $table = Bugzilla::Testopia::Table->new('run', 'tr_list_runs.cgi', $cgi, undef, $search->query);
|
|
|
|
if ($table->list_count == 1){
|
|
|
|
print "Location: " . Param('urlbase') . "tr_show_run.cgi?run_id=" . ${$table->list}[0]->id . "\n\n";
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
print "Location: " . Param('urlbase') . "tr_list_runs.cgi?" . $table->get_query_part . "\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
last SWITCH;
|
|
|
|
};
|
|
|
|
/^(environment|TE|e|env)?[\s:-]+(.*)$/i && do{
|
|
|
|
my $text = trim($2);
|
|
|
|
if ($text =~ /^\d+$/){
|
|
|
|
print "Location: " . Param('urlbase') . "tr_show_environment.cgi?env_id=" . $text . "\n\n";
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$cgi->param('current_tab', 'environment');
|
|
|
|
$cgi->param('name_type', 'anywordssubstr');
|
|
|
|
$cgi->param('name', $text);
|
|
|
|
|
|
|
|
my $search = Bugzilla::Testopia::Search->new($cgi);
|
|
|
|
my $table = Bugzilla::Testopia::Table->new('environment', 'tr_list_runs.cgi', $cgi, undef, $search->query);
|
|
|
|
if ($table->list_count == 1){
|
|
|
|
print "Location: " . Param('urlbase') . "tr_show_environment.cgi?env_id=" . ${$table->list}[0]->id . "\n\n";
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
print "Location: " . Param('urlbase') . "tr_list_environments.cgi?" . $table->get_query_part . "\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
last SWITCH;
|
|
|
|
};
|
|
|
|
/^(caserun|TCR|cr)?[\s:-]+(.*)$/i && do{
|
|
|
|
my $text = trim($2);
|
|
|
|
if ($text =~ /^\d+$/){
|
2007-01-05 03:38:08 +03:00
|
|
|
print "Location: " . Param('urlbase') . "tr_show_caserun.cgi?caserun_id=" . $text . "\n\n";
|
2007-01-04 03:17:18 +03:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
$cgi->param('current_tab', 'case_run');
|
|
|
|
$cgi->param('notes_type', 'anywordssubstr');
|
|
|
|
$cgi->param('notes', $text);
|
|
|
|
|
|
|
|
my $search = Bugzilla::Testopia::Search->new($cgi);
|
|
|
|
my $table = Bugzilla::Testopia::Table->new('run', 'tr_list_runs.cgi', $cgi, undef, $search->query);
|
|
|
|
if ($table->list_count == 1){
|
2007-01-05 03:38:08 +03:00
|
|
|
print "Location: " . Param('urlbase') . "tr_show_caserun.cgi?caserun_id=" . ${$table->list}[0]->id . "\n\n";
|
2007-01-04 03:17:18 +03:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
print "Location: " . Param('urlbase') . "tr_list_caseruns.cgi?" . $table->get_query_part . "\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
last SWITCH;
|
|
|
|
};
|
|
|
|
do{
|
|
|
|
$term =~ s/^(case|TC|c)?[\s:-]+(.*)$/$2/gi;
|
|
|
|
if ($term =~ /^\d+$/){
|
|
|
|
print "Location: " . Param('urlbase') . "tr_show_case.cgi?case_id=" . $term . "\n\n";
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$cgi->param('current_tab', 'case');
|
|
|
|
$cgi->param('summary_type', 'anywordssubstr');
|
|
|
|
$cgi->param('summary', $term);
|
|
|
|
|
|
|
|
my $search = Bugzilla::Testopia::Search->new($cgi);
|
|
|
|
my $table = Bugzilla::Testopia::Table->new('case', 'tr_list_cases.cgi', $cgi, undef, $search->query);
|
|
|
|
if ($table->list_count == 1){
|
|
|
|
print "Location: " . Param('urlbase') . "tr_show_case.cgi?case_id=" . ${$table->list}[0]->id . "\n\n";
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
print "Location: " . Param('urlbase') . "tr_list_cases.cgi?" . $table->get_query_part . "\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2006-12-06 22:35:10 +03:00
|
|
|
|
|
|
|
}
|
2007-01-05 03:38:08 +03:00
|
|
|
############
|
|
|
|
### Ajax ###
|
|
|
|
############
|
2007-01-04 03:17:18 +03:00
|
|
|
|
2007-01-05 03:38:08 +03:00
|
|
|
# This is where we lookup items typed into Dojo combo boxes
|
2006-12-06 22:35:10 +03:00
|
|
|
else{
|
2007-01-05 03:38:08 +03:00
|
|
|
print $cgi->header;
|
|
|
|
|
|
|
|
# Environment Lookup
|
2007-01-04 03:17:18 +03:00
|
|
|
if ($action eq 'getenv'){
|
2007-03-09 00:20:38 +03:00
|
|
|
Bugzilla->batch(1);
|
2007-01-04 03:17:18 +03:00
|
|
|
my $search = $cgi->param('search');
|
2007-03-09 00:20:38 +03:00
|
|
|
my $run_id = $cgi->param('run_id');
|
|
|
|
eval {
|
|
|
|
detaint_natural($run_id);
|
|
|
|
trick_taint($search);
|
|
|
|
validate_test_id($run_id, 'run');
|
|
|
|
};
|
|
|
|
exit if $@;
|
2007-02-15 21:57:24 +03:00
|
|
|
|
2007-03-09 00:20:38 +03:00
|
|
|
my $run = Bugzilla::Testopia::TestRun->new($run_id);
|
2007-01-04 03:17:18 +03:00
|
|
|
$search = "%$search%";
|
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
|
2007-02-15 21:57:24 +03:00
|
|
|
# The order of name and environment are important in the select statment.
|
2007-01-04 03:17:18 +03:00
|
|
|
# JSON will convert this to an array of arrays which Dojo will interpret
|
|
|
|
# as a select list in the ComboBox widget.
|
2007-02-15 21:57:24 +03:00
|
|
|
my $ref;
|
2007-03-09 00:20:38 +03:00
|
|
|
|
|
|
|
if ($run_id){
|
2007-02-15 21:57:24 +03:00
|
|
|
$ref = $dbh->selectall_arrayref(
|
2007-03-09 00:20:38 +03:00
|
|
|
"SELECT test_environments.name AS name, test_environments.environment_id
|
2007-02-15 21:57:24 +03:00
|
|
|
FROM test_environments
|
2007-03-13 02:06:34 +03:00
|
|
|
WHERE name like ? AND product_id = ? AND isactive = 1
|
2007-03-09 00:20:38 +03:00
|
|
|
UNION SELECT test_environments.name AS name, test_environments.environment_id
|
|
|
|
FROM test_case_runs
|
|
|
|
INNER JOIN test_environments ON test_case_runs.environment_id = test_environments.environment_id
|
|
|
|
WHERE name like ? AND test_case_runs.run_id = ?
|
2007-03-13 02:06:34 +03:00
|
|
|
AND isactive = 1
|
2007-02-15 21:57:24 +03:00
|
|
|
ORDER BY name",
|
2007-03-09 00:20:38 +03:00
|
|
|
undef, ($search, $run->plan->product_id,
|
|
|
|
$search, $run_id));
|
2007-02-15 21:57:24 +03:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
$ref = $dbh->selectall_arrayref(
|
|
|
|
"SELECT name, environment_id
|
|
|
|
FROM test_environments
|
2007-03-13 02:06:34 +03:00
|
|
|
WHERE name like ? AND isactive = 1
|
2007-02-15 21:57:24 +03:00
|
|
|
ORDER BY name
|
|
|
|
LIMIT 20",
|
|
|
|
undef, ($search));
|
|
|
|
}
|
2007-01-04 03:17:18 +03:00
|
|
|
print objToJson($ref);
|
|
|
|
}
|
2007-03-09 00:20:38 +03:00
|
|
|
elsif ($action eq 'getuser'){
|
|
|
|
my $search = $cgi->param('search');
|
|
|
|
$search = "%$search%";
|
|
|
|
trick_taint($search);
|
|
|
|
my $dbh = Bugzilla->dbh;
|
2007-01-05 03:38:08 +03:00
|
|
|
|
2007-03-09 00:20:38 +03:00
|
|
|
my $query = "SELECT DISTINCT login_name, realname,";
|
|
|
|
if (&::Param('usevisibilitygroups')) {
|
|
|
|
$query .= " COUNT(group_id) ";
|
|
|
|
} else {
|
|
|
|
$query .= " 1 ";
|
|
|
|
}
|
|
|
|
$query .= "FROM profiles ";
|
|
|
|
if (&::Param('usevisibilitygroups')) {
|
|
|
|
$query .= "LEFT JOIN user_group_map " .
|
|
|
|
"ON user_group_map.user_id = userid AND isbless = 0 " .
|
|
|
|
"AND group_id IN(" .
|
|
|
|
join(', ', (-1, @{Bugzilla->user->visible_groups_inherited})) . ")";
|
|
|
|
}
|
|
|
|
$query .= " WHERE disabledtext = '' AND (login_name LIKE ? OR realname LIKE ?) ";
|
|
|
|
$query .= $dbh->sql_group_by('userid', 'login_name, realname');
|
|
|
|
$query .= " ORDER BY login_name LIMIT 20";
|
|
|
|
|
|
|
|
my $sth = $dbh->prepare($query);
|
|
|
|
$sth->execute($search,$search);
|
|
|
|
|
|
|
|
my @userlist;
|
|
|
|
while (my($login, $name, $visible) = $sth->fetchrow_array) {
|
|
|
|
if ($visible){
|
|
|
|
push @userlist, [
|
|
|
|
$name ? "$name <$login>" : $login, $login
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print objToJson(\@userlist);
|
|
|
|
|
|
|
|
}
|
2007-01-05 03:38:08 +03:00
|
|
|
# Tag lookup
|
|
|
|
elsif ($action eq 'gettag'){
|
|
|
|
my $search = $cgi->param('search');
|
2007-02-15 21:57:24 +03:00
|
|
|
my @product_ids;
|
|
|
|
foreach my $id (split(",", $cgi->param('product_id'))){
|
|
|
|
push @product_ids, $id if detaint_natural($id);
|
|
|
|
}
|
|
|
|
my $product_ids = join(",". @product_ids);
|
|
|
|
|
2007-01-05 03:38:08 +03:00
|
|
|
trick_taint($search);
|
|
|
|
$search = "%$search%";
|
|
|
|
my $dbh = Bugzilla->dbh;
|
2007-01-09 00:48:18 +03:00
|
|
|
my $ref;
|
|
|
|
my $run_id = $cgi->param('run_id');
|
2007-02-15 21:57:24 +03:00
|
|
|
if ($product_ids){
|
2007-01-09 00:48:18 +03:00
|
|
|
$ref = $dbh->selectall_arrayref(
|
|
|
|
"SELECT tag_name, test_tags.tag_id
|
2007-02-15 21:57:24 +03:00
|
|
|
FROM test_tags
|
|
|
|
INNER JOIN test_case_tags ON test_tags.tag_id = test_case_tags.tag_id
|
|
|
|
INNER JOIN test_cases on test_cases.case_id = test_case_tags.case_id
|
|
|
|
INNER JOIN test_case_plans on test_case_plans.case_id = test_cases.case_id
|
|
|
|
INNER JOIN test_plans ON test_plans.plan_id = test_case_plans.plan_id
|
|
|
|
WHERE tag_name like ? AND test_plans.product_id IN ($product_ids)
|
|
|
|
UNION SELECT tag_name, test_tags.tag_id
|
|
|
|
FROM test_tags
|
|
|
|
INNER JOIN test_plan_tags ON test_plan_tags.tag_id = test_tags.tag_id
|
|
|
|
INNER JOIN test_plans ON test_plan_tags.plan_id = test_plans.plan_id
|
|
|
|
WHERE tag_name like ? AND test_plans.product_id IN ($product_ids)
|
|
|
|
UNION SELECT tag_name, test_tags.tag_id
|
|
|
|
FROM test_tags
|
|
|
|
INNER JOIN test_run_tags ON test_run_tags.tag_id = test_tags.tag_id
|
|
|
|
INNER JOIN test_runs ON test_runs.run_id = test_run_tags.run_id
|
|
|
|
INNER JOIN test_plans ON test_plans.plan_id = test_runs.plan_id
|
|
|
|
WHERE tag_name like ? AND test_plans.product_id IN ($product_ids)
|
|
|
|
ORDER BY tag_name",
|
|
|
|
undef, ($search,$search,$search));
|
2007-01-09 00:48:18 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$ref = $dbh->selectall_arrayref(
|
|
|
|
"SELECT tag_name, tag_id
|
|
|
|
FROM test_tags
|
2007-02-07 20:47:28 +03:00
|
|
|
WHERE tag_name like ?
|
2007-02-09 01:31:19 +03:00
|
|
|
ORDER BY tag_name
|
2007-02-07 20:47:28 +03:00
|
|
|
LIMIT 20",
|
2007-01-09 00:48:18 +03:00
|
|
|
undef, $search);
|
|
|
|
}
|
2007-01-05 03:38:08 +03:00
|
|
|
print objToJson($ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
# If neither is true above, display the quicksearch form and explaination.
|
2007-01-04 03:17:18 +03:00
|
|
|
else{
|
|
|
|
$template->process("testopia/quicksearch.html.tmpl", $vars) ||
|
|
|
|
ThrowTemplateError($template->error());
|
|
|
|
}
|
2006-12-06 22:35:10 +03:00
|
|
|
}
|