forked from bugzilla/extensions-Testopia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tr_new_plan.cgi
executable file
·130 lines (112 loc) · 4.55 KB
/
tr_new_plan.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/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 Test Runner System.
#
# The Initial Developer of the Original Code is Maciej Maczynski.
# Portions created by Maciej Maczynski are Copyright (C) 2001
# Maciej Maczynski. All Rights Reserved.
#
# Contributor(s): Greg Hendricks <[email protected]>
use strict;
use lib qw(. lib);
use Bugzilla;
use Bugzilla::Constants;
use Bugzilla::Config;
use Bugzilla::Error;
use Bugzilla::Util;
use JSON;
BEGIN { Bugzilla->extensions }
use Bugzilla::Extension::Testopia::Util;
use Bugzilla::Extension::Testopia::TestPlan;
use Bugzilla::Extension::Testopia::Product;
use Bugzilla::Extension::Testopia::Constants;
###############################################################################
# tr_new_plan.cgi
# Presents a webform to the user for the creation of a new test plan.
# Creates a new testplan via Ajax
#
# INTERFACE:
# action:
# undef - Present form for new plan creation
# "add" - Form has been submitted with plan data. Create the test
# plan.
#
# product_id: integer - (REQUIRED) ID of the Product the new plan should be created in
# type: integer - (REQUIRED) ID of the Plan type
# prod_version: string - (REQUIRED) Version of the product to associate
# plan_name: string - (REQUIRED) Limited to 255 chars. Name for the plan
# plandoc: string - (OPTIONAL) HTML document describing the test plan
# file1-5: fileloc - (OPTIONAL) Path to a file to upload
# file_desc1-5: string - (OPTIONAL) Description of file to attach
#
#
################################################################################
my $vars = {};
my $template = Bugzilla->template;
Bugzilla->login(LOGIN_REQUIRED);
my $cgi = Bugzilla->cgi;
print $cgi->header;
my $action = $cgi->param('action') || '';
if ($action eq 'add'){
Bugzilla->error_mode(ERROR_MODE_AJAX);
ThrowUserError("testopia-create-denied", {'object' => 'Test Plan'}) unless Bugzilla->user->in_group('Testers');
my $plan = Bugzilla::Extension::Testopia::TestPlan->create({
'product_id' => $cgi->param('product_id'),
'author_id' => Bugzilla->user->id,
'type_id' => $cgi->param('type'),
'default_product_version' => $cgi->param('prod_version'),
'name' => $cgi->param('plan_name'),
'text' => $cgi->param("plandoc") || '',
});
my $err = JSON::false;
for (my $i=1; $i<5; $i++){
next unless defined $cgi->upload("file$i");
my $fh = $cgi->upload("file$i");
my $data;
# enable 'slurp' mode
local $/;
$data = <$fh>;
$data || ThrowUserError("zero_length_file");
Bugzilla->error_mode(ERROR_MODE_DIE);
eval {
my $attachment = Bugzilla::Extension::Testopia::Attachment->create({
plan_id => $plan->id,
submitter_id => Bugzilla->user->id,
description => $cgi->param("file_desc$i") || 'Attachment',
filename => $cgi->upload("file$i"),
mime_type => $cgi->uploadInfo($cgi->param("file$i"))->{'Content-Type'},
contents => $data
});
};
if ($@){
$err = JSON::true;
}
}
print "{success: true, plan: '". $plan->id ."', err: $err}";
}
####################
### Display Form ###
####################
else {
my $product;
if ($cgi->param('product_id')){
$product = Bugzilla::Extension::Testopia::Product->new($cgi->param('product_id'));
ThrowUserError('testopia-read-only', {'object' => $product}) unless $product->canedit;
$vars->{'product'} = $product;
}
ThrowUserError("testopia-create-denied", {'object' => 'Test Plan'}) unless Bugzilla->user->in_group('Testers');
$vars->{'plan'} = Bugzilla::Extension::Testopia::TestPlan->new({});
$template->process("testopia/plan/add.html.tmpl", $vars) ||
ThrowTemplateError($template->error());
}