2006-06-13 19:09:54 +04: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.
|
|
|
|
#
|
2007-02-26 22:06:35 +03:00
|
|
|
# The Original Code is the Bugzilla Testopia System.
|
2006-06-13 19:09:54 +04:00
|
|
|
#
|
2007-02-26 22:06:35 +03:00
|
|
|
# The Initial Developer of the Original Code is Greg Hendricks.
|
|
|
|
# Portions created by Greg Hendricks are Copyright (C) 2006
|
|
|
|
# Novell. All Rights Reserved.
|
2006-06-13 19:09:54 +04:00
|
|
|
#
|
2007-02-26 22:06:35 +03:00
|
|
|
# Contributor(s): Greg Hendricks <ghendricks@novell.com>
|
2006-06-13 19:09:54 +04:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use lib ".";
|
|
|
|
|
|
|
|
use Bugzilla;
|
2006-07-29 02:32:36 +04:00
|
|
|
use Bugzilla::Bug;
|
2006-06-13 19:09:54 +04:00
|
|
|
use Bugzilla::Util;
|
2007-02-26 22:06:35 +03:00
|
|
|
use Bugzilla::User;
|
2006-06-13 19:09:54 +04:00
|
|
|
use Bugzilla::Error;
|
|
|
|
use Bugzilla::Constants;
|
|
|
|
use Bugzilla::Testopia::Search;
|
|
|
|
use Bugzilla::Testopia::Util;
|
|
|
|
use Bugzilla::Testopia::TestCaseRun;
|
|
|
|
use Bugzilla::Testopia::Table;
|
2006-12-09 02:12:16 +03:00
|
|
|
use Bugzilla::Testopia::Constants;
|
2008-02-16 03:00:53 +03:00
|
|
|
use JSON;
|
2006-06-13 19:09:54 +04:00
|
|
|
|
2007-05-24 00:42:27 +04:00
|
|
|
my $vars = {};
|
2006-07-29 02:32:36 +04:00
|
|
|
|
2006-06-13 19:09:54 +04:00
|
|
|
my $cgi = Bugzilla->cgi;
|
|
|
|
my $template = Bugzilla->template;
|
2007-02-26 22:06:35 +03:00
|
|
|
|
|
|
|
Bugzilla->login(LOGIN_REQUIRED);
|
2007-02-09 20:31:45 +03:00
|
|
|
|
2008-02-16 03:00:53 +03:00
|
|
|
my $format = $template->get_format("testopia/caserun/list", scalar $cgi->param('format'), scalar $cgi->param('ctype'));
|
2006-10-21 03:27:56 +04:00
|
|
|
|
2008-02-16 03:00:53 +03:00
|
|
|
print $cgi->header;
|
2007-06-06 03:10:11 +04:00
|
|
|
|
2006-10-21 03:27:56 +04:00
|
|
|
# prevent DOS attacks from multiple refreshes of large data
|
|
|
|
$::SIG{TERM} = 'DEFAULT';
|
|
|
|
$::SIG{PIPE} = 'DEFAULT';
|
2006-10-19 00:59:28 +04:00
|
|
|
|
2006-06-13 19:09:54 +04:00
|
|
|
my $action = $cgi->param('action') || '';
|
|
|
|
|
2008-02-16 03:00:53 +03:00
|
|
|
if ($action eq 'update'){
|
|
|
|
Bugzilla->error_mode(ERROR_MODE_AJAX);
|
|
|
|
my @caseruns;
|
2007-02-26 22:06:35 +03:00
|
|
|
my @uneditable;
|
2008-02-16 03:00:53 +03:00
|
|
|
my $assignee_id;
|
|
|
|
my $status_id;
|
2007-02-26 22:06:35 +03:00
|
|
|
|
2008-02-16 03:00:53 +03:00
|
|
|
if ($cgi->param('applyall') eq 'true'){
|
|
|
|
my $run = Bugzilla::Testopia::TestRun->new($cgi->param('run_id'));
|
|
|
|
exit if $run->stop_date;
|
|
|
|
@caseruns = @{$run->current_caseruns()} if $run->canedit;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
foreach my $id (split(',', $cgi->param('ids'))){
|
|
|
|
my $caserun = Bugzilla::Testopia::TestCaseRun->new($id);
|
|
|
|
if ($caserun->canedit){
|
|
|
|
push @caseruns, $caserun;
|
2007-05-31 23:47:39 +04:00
|
|
|
}
|
2008-02-16 03:00:53 +03:00
|
|
|
else {
|
|
|
|
push @uneditable, $caserun->case_id;
|
|
|
|
}
|
2006-06-13 19:09:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-16 03:00:53 +03:00
|
|
|
$status_id = $cgi->param('status_id') if $cgi->param('status_id');
|
|
|
|
$assignee_id = login_to_id(trim($cgi->param('assignee')),'THROW_ERROR') if $cgi->param('assignee');
|
|
|
|
detaint_natural($status_id);
|
|
|
|
|
|
|
|
foreach my $cr (@caseruns){
|
|
|
|
next if $cr->run->stop_date;
|
|
|
|
$cr = $cr->switch($cgi->param('build_id')) if $cgi->param('build_id');
|
|
|
|
$cr = $cr->switch($cr->build->id, $cgi->param('env_id')) if $cgi->param('env_id');
|
|
|
|
$cr->set_status($status_id, $cgi->param('update_bug') eq 'true' ? 1 : 0) if $status_id;
|
|
|
|
$cr->set_assignee($assignee_id) if $assignee_id;
|
2006-06-13 19:09:54 +04:00
|
|
|
}
|
2008-02-16 03:00:53 +03:00
|
|
|
|
|
|
|
ThrowUserError('testopia-update-failed', {'object' => 'case-run', 'list' => join(',',@uneditable)}) if (scalar @uneditable);
|
|
|
|
exit unless scalar @caseruns;
|
|
|
|
|
|
|
|
my $run = $caseruns[0]->run;
|
|
|
|
$vars->{'passed'} = $run->case_run_count(PASSED) / $run->case_run_count;
|
|
|
|
$vars->{'failed'} = $run->case_run_count(FAILED) / $run->case_run_count;
|
|
|
|
$vars->{'blocked'} = $run->case_run_count(BLOCKED) / $run->case_run_count;
|
|
|
|
$vars->{'complete'} = $run->percent_complete() . '%';
|
|
|
|
$vars->{'success'} = 'true' ;
|
|
|
|
|
|
|
|
print objToJson($vars);
|
2006-06-13 19:09:54 +04:00
|
|
|
}
|
2008-02-16 03:00:53 +03:00
|
|
|
|
|
|
|
elsif ($action eq 'delete'){
|
|
|
|
Bugzilla->error_mode(ERROR_MODE_AJAX);
|
|
|
|
my @case_ids;
|
|
|
|
if ($cgi->param('ids')){
|
|
|
|
@case_ids = $cgi->param('ids');
|
2006-12-01 22:37:26 +03:00
|
|
|
}
|
2008-02-16 03:00:53 +03:00
|
|
|
else {
|
|
|
|
@case_ids = split(",", $cgi->param('caserun_ids'));
|
2006-10-19 00:59:28 +04:00
|
|
|
}
|
2008-02-16 03:00:53 +03:00
|
|
|
my @uneditable;
|
|
|
|
foreach my $id (@case_ids){
|
|
|
|
my $case = Bugzilla::Testopia::TestCaseRun->new($id);
|
|
|
|
unless ($case->candelete){
|
|
|
|
push @uneditable, $case;
|
|
|
|
next;
|
2006-10-21 03:27:56 +04:00
|
|
|
}
|
2008-02-16 03:00:53 +03:00
|
|
|
|
|
|
|
$case->obliterate($cgi->param('single'));
|
2006-10-21 03:27:56 +04:00
|
|
|
}
|
2007-01-09 03:41:23 +03:00
|
|
|
|
2008-02-16 03:00:53 +03:00
|
|
|
ThrowUserError('testopia-update-failed', {'object' => 'case-run', 'list' => join(',',@uneditable)}) if (scalar @uneditable);
|
|
|
|
print "{'success': true}";
|
2006-12-01 22:37:26 +03:00
|
|
|
}
|
2006-06-13 19:09:54 +04:00
|
|
|
|
2008-02-16 03:00:53 +03:00
|
|
|
else {
|
|
|
|
$vars->{'qname'} = $cgi->param('qname') if $cgi->param('qname');
|
2006-06-13 19:09:54 +04:00
|
|
|
|
2008-02-16 03:00:53 +03:00
|
|
|
# Take the search from the URL params and convert it to SQL
|
|
|
|
$cgi->param('current_tab', 'case_run');
|
|
|
|
my $search = Bugzilla::Testopia::Search->new($cgi);
|
|
|
|
my $table = Bugzilla::Testopia::Table->new('case_run', 'tr_list_caseruns.cgi', $cgi, undef, $search->query);
|
|
|
|
|
|
|
|
if ($cgi->param('ctype') eq 'json'){
|
|
|
|
print $cgi->header;
|
|
|
|
$vars->{'json'} = $table->to_ext_json;
|
|
|
|
$template->process($format->{'template'}, $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
2007-02-15 21:57:24 +03:00
|
|
|
}
|
2006-06-13 19:09:54 +04:00
|
|
|
}
|