import Net::Whois::Raw into install/5.005 directory *sigh*
[freeside.git] / rt / html / REST / 1.0 / ticket / merge
1 %# BEGIN LICENSE BLOCK
2 %# 
3 %# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
4 %# 
5 %# (Except where explictly superceded by other copyright notices)
6 %# 
7 %# This work is made available to you under the terms of Version 2 of
8 %# the GNU General Public License. A copy of that license should have
9 %# been provided with this software, but in any event can be snarfed
10 %# from www.gnu.org.
11 %# 
12 %# This work is distributed in the hope that it will be useful, but
13 %# WITHOUT ANY WARRANTY; without even the implied warranty of
14 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 %# General Public License for more details.
16 %# 
17 %# Unless otherwise specified, all modifications, corrections or
18 %# extensions to this work which alter its source code become the
19 %# property of Best Practical Solutions, LLC when submitted for
20 %# inclusion in the work.
21 %# 
22 %# 
23 %# END LICENSE BLOCK
24 %# REST/1.0/ticket/merge
25 %#
26 <%ARGS>
27 $id => undef
28 $into
29 </%ARGS>
30 <%INIT>
31 use RT::Interface::REST;
32
33 my $output;
34 my $status = "200 Ok";
35 my $ticket = new RT::Ticket $session{CurrentUser};
36 my $object = $r->path_info;
37
38 # http://.../REST/1.0/ticket/merge/1
39
40 $object =~ s#^/##;
41 if ($id && $object && $id != $object) {
42     $output = "Different ids in URL (`$object') and submitted form (`$id').\n";
43     $status = "400 Bad Request";
44     goto OUTPUT;
45 }
46 $id ||= $object;
47 unless ($id =~ /^\d+$/ && $into =~ /^\d+$/) {
48     my $bad = ($id !~ /^\d+$/) ? $id : $into;
49     $output = $r->path_info. "\n";
50     $output .= "Invalid ticket id: `$bad'.\n";
51     $status = "400 Bad Request";
52     goto OUTPUT;
53 }
54
55 $ticket->Load($id);
56 unless ($ticket->Id) {
57     $output = "Couldn't load ticket id: `$id'.\n";
58     $status = "404 Ticket not found";
59     goto OUTPUT;
60 }
61 unless ($ticket->CurrentUserHasRight('ModifyTicket')) {
62     $output = "You are not allowed to modify ticket $id.\n";
63     $status = "403 Permission denied";
64     goto OUTPUT;
65 }
66
67 my ($n, $s) = $ticket->MergeInto($into);
68
69 if ($n == 0) {
70     $status = "500 Error";
71 }
72 $output = $s;
73
74 OUTPUT:
75 </%INIT>
76 RT/<% $RT::VERSION %> <% $status %>
77
78 <% $output |n %>