Upgrade 4.0.17 clean.
[usit-rt.git] / share / html / REST / 1.0 / ticket / comment
CommitLineData
84fb5b46
MKG
1%# BEGIN BPS TAGGED BLOCK {{{
2%#
3%# COPYRIGHT:
4%#
403d7b0b 5%# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
84fb5b46
MKG
6%# <sales@bestpractical.com>
7%#
8%# (Except where explicitly superseded by other copyright notices)
9%#
10%#
11%# LICENSE:
12%#
13%# This work is made available to you under the terms of Version 2 of
14%# the GNU General Public License. A copy of that license should have
15%# been provided with this software, but in any event can be snarfed
16%# from www.gnu.org.
17%#
18%# This work is distributed in the hope that it will be useful, but
19%# WITHOUT ANY WARRANTY; without even the implied warranty of
20%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21%# General Public License for more details.
22%#
23%# You should have received a copy of the GNU General Public License
24%# along with this program; if not, write to the Free Software
25%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26%# 02110-1301 or visit their web page on the internet at
27%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28%#
29%#
30%# CONTRIBUTION SUBMISSION POLICY:
31%#
32%# (The following paragraph is not intended to limit the rights granted
33%# to you to modify and distribute this software under the terms of
34%# the GNU General Public License and is only of importance to you if
35%# you choose to contribute your changes and enhancements to the
36%# community by submitting them to Best Practical Solutions, LLC.)
37%#
38%# By intentionally submitting any modifications, corrections or
39%# derivatives to this work, or any other work intended for use with
40%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41%# you are the copyright holder for those contributions and you grant
42%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43%# royalty-free, perpetual, license to use, copy, create derivative
44%# works based on those contributions, and sublicense and distribute
45%# those contributions and any derivatives thereof.
46%#
47%# END BPS TAGGED BLOCK }}}
48%# REST/1.0/ticket/comment
49%#
50<%ARGS>
51$content
52</%ARGS>
53<%INIT>
54use MIME::Entity;
55use LWP::MediaTypes;
56use RT::Interface::REST;
84fb5b46
MKG
57
58my $ticket = RT::Ticket->new($session{CurrentUser});
59my $object = $r->path_info;
60my $status = "200 Ok";
61my $output;
62my $action;
63
64# http://.../REST/1.0/ticket/1/comment
65my ($c, $o, $k, $e) = @{ form_parse($content)->[0] };
66if ($e || !$o) {
67 if (!$o) {
68 $output = "Empty form submitted.\n";
69 }
70 else {
71 $c = "# Syntax error.";
72 $output = form_compose([[$c, $o, $k, $e]]);
73 }
74 $status = "400 Bad Request";
75 goto OUTPUT;
76}
77
78$object =~ s#^/##;
79$object ||= $k->{Ticket};
80unless ($object =~ /^\d+/) {
81 $output = "Invalid ticket id: `$object'.\n";
82 $status = "400 Bad Request";
83 goto OUTPUT;
84}
85if ($k->{Ticket} && $object ne $k->{Ticket}) {
86 $output = "The submitted form and URL specify different tickets.\n";
87 $status = "400 Bad Request";
88 goto OUTPUT;
89}
90
91($action = $k->{Action}) =~ s/^(.)(.*)$/\U$1\L$2\E/;
92unless ($action =~ /^(?:Comment|Correspond)$/) {
93 $output = "Invalid action: `$action'.\n";
94 $status = "400 Bad Request";
95 goto OUTPUT;
96}
97
98my $text = $k->{Text};
99my @atts = @{ vsplit($k->{Attachment}) };
100
101if (!$k->{Text} && @atts == 0) {
102 $status = "400 Bad Request";
103 $output = "Empty comment with no attachments submitted.\n";
104 goto OUTPUT;
105}
106
107my $cgi = $m->cgi_object;
403d7b0b
MKG
108my $ent = MIME::Entity->build(
109 Type => "multipart/mixed",
110 'X-RT-Interface' => 'REST',
111);
84fb5b46
MKG
112$ent->attach(Data => $k->{Text}) if $k->{Text};
113
01e3b242
MKG
114{
115 my ($res, $msg) = process_attachments($ent, @atts);
116 unless ( $res ) {
84fb5b46 117 $status = "400 Bad Request";
01e3b242 118 $output = "$msg\n";
84fb5b46
MKG
119 goto OUTPUT;
120 }
84fb5b46
MKG
121}
122
123$ticket->Load($object);
124unless ($ticket->Id) {
125 $output = "Couldn't load ticket id: `$object'.\n";
126 $status = "404 Ticket not found";
127 goto OUTPUT;
128}
129unless ($ticket->CurrentUserHasRight('ModifyTicket') ||
130 ($action eq "Comment" &&
131 $ticket->CurrentUserHasRight("CommentOnTicket")) ||
132 ($action eq "Correspond" &&
133 $ticket->CurrentUserHasRight("ReplyToTicket")))
134{
135 $output = "You are not allowed to $action on ticket $object.\n";
136 $status = "403 Permission denied";
137 goto OUTPUT;
138}
139
140my $cc = join ", ", @{ vsplit($k->{Cc}) };
141my $bcc = join ", ", @{ vsplit($k->{Bcc}) };
142my ($n, $s) = $ticket->$action(MIMEObj => $ent,
143 CcMessageTo => $cc,
144 BccMessageTo => $bcc,
145 TimeTaken => $k->{TimeWorked} || 0);
146$output = $s;
147if ($k->{Status}) {
148 my ($status_n, $status_s) = $ticket->SetStatus($k->{'Status'} );
149 $output .= "\n".$status_s;
150}
151
152OUTPUT:
c36a7e1d 153
84fb5b46
MKG
154</%INIT>
155RT/<% $RT::VERSION %> <% $status %>
156
157<% $output |n %>