3 %# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
5 %# (Except where explictly superceded by other copyright notices)
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
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.
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.
24 %# REST/1.0/ticket/link
33 use RT::Interface::REST;
36 my $status = "200 Ok";
37 my $ticket = new RT::Ticket $session{CurrentUser};
38 my $object = $r->path_info;
40 my @fields = qw(DependsOn DependedOnBy RefersTo ReferredToBy HasMember MemberOf);
41 my %fields = map { lc $_ => $_ } @fields;
43 HasMember => { Type => 'MemberOf', Mode => 'Base' },
44 ReferredToBy => { Type => 'RefersTo', Mode => 'Base' },
45 DependedOnBy => { Type => 'DependsOn', Mode => 'Base' },
46 MemberOf => { Type => 'MemberOf', Mode => 'Target' },
47 RefersTo => { Type => 'RefersTo', Mode => 'Target' },
48 DependsOn => { Type => 'DependsOn', Mode => 'Target' },
51 # http://.../REST/1.0/ticket/link/1
54 if ($id && $object && $id != $object) {
55 $output = "Different ids in URL (`$object') and submitted form (`$id').\n";
56 $status = "400 Bad Request";
60 unless ($id =~ /^\d+$/ && $to =~ /^\d+$/) {
61 my $bad = ($id !~ /^\d+$/) ? $id : $to;
62 $output = $r->path_info. "\n";
63 $output .= "Invalid ticket id: '$bad'.\n";
64 $status = "400 Bad Request";
67 unless (exists $fields{lc $rel}) {
68 $output = "Invalid relationship: '$rel'.\n";
69 $status = "400 Bad Request";
72 $rel = $fields{lc $rel};
75 unless ($ticket->Id) {
76 $output = "Couldn't load ticket id: '$id'.\n";
77 $status = "404 Ticket not found";
81 my $type = $lfields{$rel}->{Type};
82 my $mode = $lfields{$rel}->{Mode};
85 my $op = $del ? "DeleteLink" : "AddLink";
87 ($n, $output) = $ticket->$op(Type => $type, $mode => $to);
89 $status = "500 Error";
94 RT/<% $RT::VERSION %> <% $status %>