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
|
|
|
#
|
|
|
|
# Contributor(s): Greg Hendricks <ghendricks@novell.com>
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use lib ".";
|
|
|
|
|
|
|
|
use Bugzilla;
|
|
|
|
use Bugzilla::Util;
|
|
|
|
use Bugzilla::Constants;
|
|
|
|
use Bugzilla::Error;
|
|
|
|
use Bugzilla::Testopia::Util;
|
|
|
|
use Bugzilla::Testopia::Attachment;
|
|
|
|
use Bugzilla::Testopia::Search;
|
|
|
|
use Bugzilla::Testopia::Table;
|
|
|
|
|
2007-02-26 22:06:35 +03:00
|
|
|
use vars qw($vars);
|
|
|
|
my $template = Bugzilla->template;
|
2006-06-13 19:09:54 +04:00
|
|
|
my $cgi = Bugzilla->cgi;
|
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
|
2007-02-26 22:06:35 +03:00
|
|
|
Bugzilla->login(LOGIN_REQUIRED);
|
2006-06-13 19:09:54 +04:00
|
|
|
|
|
|
|
push @{$::vars->{'style_urls'}}, 'testopia/css/default.css';
|
2007-02-26 22:06:35 +03:00
|
|
|
|
|
|
|
my $action = $cgi->param('action') || '';
|
|
|
|
my $attach_id = $cgi->param('attach_id');
|
|
|
|
my $plan_id = $cgi->param('plan_id');
|
|
|
|
my $case_id = $cgi->param('case_id');
|
2007-02-13 03:21:02 +03:00
|
|
|
my $caserun_id = $cgi->param('caserun_id');
|
2006-06-13 19:09:54 +04:00
|
|
|
|
2007-02-26 22:06:35 +03:00
|
|
|
detaint_natural($attach_id) if $attach_id;
|
2007-02-13 03:21:02 +03:00
|
|
|
|
2007-02-26 22:06:35 +03:00
|
|
|
unless ($attach_id){
|
2006-06-13 19:09:54 +04:00
|
|
|
print $cgi->header();
|
|
|
|
$template->process("testopia/attachment/choose.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
exit;
|
|
|
|
}
|
2007-02-13 03:21:02 +03:00
|
|
|
|
2007-02-26 22:06:35 +03:00
|
|
|
validate_test_id($attach_id,'attachment');
|
|
|
|
my $attachment = Bugzilla::Testopia::Attachment->new($attach_id);
|
|
|
|
|
2007-02-13 03:21:02 +03:00
|
|
|
my $obj;
|
|
|
|
if ($plan_id){
|
2007-02-26 22:06:35 +03:00
|
|
|
detaint_natural($plan_id);
|
2007-02-13 03:21:02 +03:00
|
|
|
$obj = Bugzilla::Testopia::TestPlan->new($plan_id);
|
|
|
|
}
|
|
|
|
elsif ($case_id){
|
2007-02-26 22:06:35 +03:00
|
|
|
detaint_natural($case_id);
|
2007-02-13 03:21:02 +03:00
|
|
|
$obj = Bugzilla::Testopia::TestCase->new($case_id);
|
|
|
|
}
|
|
|
|
elsif ($caserun_id){
|
2007-02-26 22:06:35 +03:00
|
|
|
detaint_natural($caserun_id);
|
2007-02-13 03:21:02 +03:00
|
|
|
$obj = Bugzilla::Testopia::TestCaseRun->new($caserun_id);
|
|
|
|
}
|
|
|
|
|
2006-06-13 19:09:54 +04:00
|
|
|
##################
|
|
|
|
### Edit ###
|
|
|
|
##################
|
|
|
|
if ($action eq 'edit'){
|
2007-02-26 22:06:35 +03:00
|
|
|
print $cgi->header;
|
2007-03-15 18:49:26 +03:00
|
|
|
ThrowUserError('testopia-permission-denied', {'object' => $attachment}) unless $attachment->canedit;
|
2007-02-26 22:06:35 +03:00
|
|
|
|
|
|
|
$vars->{'attachment'} = $attachment;
|
2006-06-13 19:09:54 +04:00
|
|
|
$vars->{'isviewable'} = $attachment->isViewable($cgi);
|
2007-02-13 03:21:02 +03:00
|
|
|
$vars->{'obj'} = $obj;
|
2006-06-13 19:09:54 +04:00
|
|
|
$template->process("testopia/attachment/show.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
}
|
|
|
|
elsif ($action eq 'do_edit') {
|
2007-02-26 22:06:35 +03:00
|
|
|
print $cgi->header;
|
2007-03-15 18:49:26 +03:00
|
|
|
ThrowUserError('testopia-permission-denied', {'object' => $attachment}) unless $attachment->canedit;
|
2007-02-26 22:06:35 +03:00
|
|
|
|
2006-06-13 19:09:54 +04:00
|
|
|
my %newvalues = (
|
|
|
|
'description' => $cgi->param('description') || '',
|
|
|
|
'filename' => $cgi->param('filename'),
|
|
|
|
'mime_type' => $cgi->param('mime_type'),
|
|
|
|
);
|
|
|
|
$attachment->update(\%newvalues);
|
2007-02-13 03:21:02 +03:00
|
|
|
|
|
|
|
$vars->{'attachment'} = $attachment;
|
2006-06-13 19:09:54 +04:00
|
|
|
$vars->{'tr_message'} = "Attachment updated";
|
2007-02-13 03:21:02 +03:00
|
|
|
$vars->{'backlink'} = $obj;
|
|
|
|
$vars->{'obj'} = $obj;
|
|
|
|
$vars->{'isviewable'} = $attachment->isViewable($cgi);
|
|
|
|
$template->process("testopia/attachment/show.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
2006-06-13 19:09:54 +04:00
|
|
|
}
|
2007-02-26 22:06:35 +03:00
|
|
|
|
2006-06-13 19:09:54 +04:00
|
|
|
####################
|
2007-02-26 22:06:35 +03:00
|
|
|
### Unlink ###
|
2006-06-13 19:09:54 +04:00
|
|
|
####################
|
2007-02-26 22:06:35 +03:00
|
|
|
|
|
|
|
elsif ($action eq 'remove') {
|
|
|
|
print $cgi->header;
|
|
|
|
ThrowUserError('testopia-missing-parameter', {'param' => 'case_id or plan_id'}) unless $obj;
|
2007-03-15 18:49:26 +03:00
|
|
|
ThrowUserError('testopia-no-delete', {'object' => $attachment}) unless $obj->canedit;
|
2007-02-26 22:06:35 +03:00
|
|
|
$vars->{'attachment'} = $attachment;
|
|
|
|
$vars->{'action'} = 'do_remove';
|
2007-02-13 03:21:02 +03:00
|
|
|
$vars->{'obj'} = $obj;
|
2007-02-26 22:06:35 +03:00
|
|
|
|
2006-06-13 19:09:54 +04:00
|
|
|
$template->process("testopia/attachment/delete.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
|
|
}
|
2007-02-26 22:06:35 +03:00
|
|
|
elsif ($action eq 'do_remove') {
|
|
|
|
print $cgi->header;
|
2006-06-13 19:09:54 +04:00
|
|
|
$vars->{'tr_message'} = "Attachment ". $attachment->description ." deleted";
|
2007-02-26 22:06:35 +03:00
|
|
|
ThrowUserError('testopia-missing-parameter', {'param' => 'case_id or plan_id'}) unless $obj;
|
2007-03-15 18:49:26 +03:00
|
|
|
ThrowUserError('testopia-no-delete', {'object' => $attachment}) unless $obj->canedit;
|
2007-02-13 03:21:02 +03:00
|
|
|
if ($plan_id){
|
|
|
|
$attachment->unlink_plan($plan_id);
|
|
|
|
}
|
|
|
|
elsif ($case_id){
|
|
|
|
$attachment->unlink_plan($case_id);
|
|
|
|
}
|
|
|
|
|
2007-02-26 22:06:35 +03:00
|
|
|
$vars->{'tr_message'} = "Attachment removed";
|
2007-02-13 03:21:02 +03:00
|
|
|
$vars->{'backlink'} = $obj;
|
|
|
|
$vars->{'deleted'} = 1;
|
|
|
|
$template->process("testopia/attachment/delete.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
2007-02-26 22:06:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
####################
|
|
|
|
### Delete ###
|
|
|
|
####################
|
|
|
|
|
|
|
|
elsif ($action eq 'delete') {
|
|
|
|
print $cgi->header;
|
2007-03-15 18:49:26 +03:00
|
|
|
ThrowUserError('testopia-no-delete', {'object' => $attachment}) unless $attachment->candelete;
|
2007-02-26 22:06:35 +03:00
|
|
|
$vars->{'attachment'} = $attachment;
|
|
|
|
$vars->{'action'} = 'do_delete';
|
|
|
|
|
|
|
|
$template->process("testopia/attachment/delete.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
|
|
}
|
|
|
|
elsif ($action eq 'do_delete') {
|
|
|
|
print $cgi->header;
|
|
|
|
$vars->{'tr_message'} = "Attachment ". $attachment->description ." deleted";
|
2007-03-15 18:49:26 +03:00
|
|
|
ThrowUserError('testopia-no-delete', {'object' => $attachment}) unless $attachment->candelete;
|
2007-02-26 22:06:35 +03:00
|
|
|
|
|
|
|
$attachment->obliterate;
|
|
|
|
$vars->{'tr_message'} = "Attachment deleted";
|
|
|
|
$vars->{'deleted'} = 1;
|
|
|
|
$template->process("testopia/attachment/delete.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
2006-06-13 19:09:54 +04:00
|
|
|
}
|
|
|
|
################
|
|
|
|
### View ###
|
|
|
|
################
|
|
|
|
else {
|
2007-02-26 22:06:35 +03:00
|
|
|
|
2006-06-13 19:09:54 +04:00
|
|
|
my $filename = $attachment->filename;
|
|
|
|
$filename =~ s/\\/\\\\/g; # escape backslashes
|
|
|
|
$filename =~ s/"/\\"/g; # escape quotes
|
|
|
|
|
|
|
|
print $cgi->header(-type => $attachment->mime_type . "; name=\"$filename\"",
|
|
|
|
-content_disposition => "inline; filename=\"$filename\"",
|
|
|
|
-content_length => $attachment->datasize);
|
|
|
|
|
|
|
|
print $attachment->contents;
|
|
|
|
}
|