summaryrefslogtreecommitdiff
path: root/rt/html/REST/1.0/Forms/ticket
diff options
context:
space:
mode:
Diffstat (limited to 'rt/html/REST/1.0/Forms/ticket')
-rw-r--r--rt/html/REST/1.0/Forms/ticket/attachments17
-rwxr-xr-xrt/html/REST/1.0/Forms/ticket/comment152
-rw-r--r--rt/html/REST/1.0/Forms/ticket/default73
-rw-r--r--rt/html/REST/1.0/Forms/ticket/history27
-rw-r--r--rt/html/REST/1.0/Forms/ticket/links10
-rwxr-xr-xrt/html/REST/1.0/Forms/ticket/merge96
-rwxr-xr-xrt/html/REST/1.0/Forms/ticket/take135
7 files changed, 481 insertions, 29 deletions
diff --git a/rt/html/REST/1.0/Forms/ticket/attachments b/rt/html/REST/1.0/Forms/ticket/attachments
index ca75ce0d1..4ee409bdc 100644
--- a/rt/html/REST/1.0/Forms/ticket/attachments
+++ b/rt/html/REST/1.0/Forms/ticket/attachments
@@ -2,7 +2,7 @@
%#
%# COPYRIGHT:
%#
-%# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
%# <jesse@bestpractical.com>
%#
%# (Except where explicitly superseded by other copyright notices)
@@ -22,7 +22,9 @@
%#
%# You should have received a copy of the GNU General Public License
%# along with this program; if not, write to the Free Software
-%# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/copyleft/gpl.html.
%#
%#
%# CONTRIBUTION SUBMISSION POLICY:
@@ -49,7 +51,7 @@
$id
$args => undef
</%ARGS>
-<%perl>
+<%INIT>
my @data;
my ($c, $o, $k, $e) = ("", [], {}, "");
my $ticket = new RT::Ticket $session{CurrentUser};
@@ -80,7 +82,12 @@ if ($aid) {
return [ "# Invalid attachment id: $aid", [], {}, 1 ];
}
if ($content) {
- $c = $attachment->OriginalContent;
+ $c = $attachment->OriginalContent;
+ # if we're sending a binary attachment (and only the attachment)
+ # flag it so bin/rt knows to special case it
+ if ($attachment->ContentType !~ /^text\//) {
+ $r->content_type($attachment->ContentType);
+ }
} else {
my @data;
push @data, [ id => $attachment->Id ];
@@ -125,4 +132,4 @@ else {
}
return [ $c, $o, $k, $e ];
-</%perl>
+</%INIT>
diff --git a/rt/html/REST/1.0/Forms/ticket/comment b/rt/html/REST/1.0/Forms/ticket/comment
new file mode 100755
index 000000000..4ed2da8af
--- /dev/null
+++ b/rt/html/REST/1.0/Forms/ticket/comment
@@ -0,0 +1,152 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
+%# <jesse@bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/copyleft/gpl.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+%# REST/1.0/Forms/ticket/comment
+%#
+<%ARGS>
+$id
+%changes
+</%ARGS>
+<%INIT>
+use MIME::Entity;
+use LWP::MediaTypes;
+use RT::Interface::REST;
+use File::Temp qw(tempfile);
+
+$RT::Logger->debug("Got ticket id=$id for comment");
+$RT::Logger->debug("Got args @{[keys(%changes)]}.");
+
+my $ticket = new RT::Ticket $session{CurrentUser};
+my ($c, $o, $k, $e) = ("", [], {}, 0);
+
+# http://.../REST/1.0/ticket/1/comment
+$ticket->Load($id);
+if (!$ticket->Id) {
+ $e = 1;
+ $c = "# Ticket $id does not exist.";
+ goto OUTPUT;
+}
+
+my $action;
+($action = $changes{Action}) =~ s/^(.)(.*)$/\U$1\L$2\E/;
+unless ($action =~ /^(?:Comment|Correspond)$/) {
+ $e = 1;
+ $c = "# Invalid action: `$action'.";
+ goto OUTPUT;
+}
+
+my $text = $changes{Text};
+my @atts = @{ vsplit($changes{Attachment}) };
+
+if (!$changes{Text} && @atts == 0) {
+ $e = 1;
+ $c = "# Empty comment with no attachments submitted.";
+ goto OUTPUT;
+}
+
+my $cgi = $m->cgi_object;
+my $ent = MIME::Entity->build(Type => "multipart/mixed");
+$ent->attach(Data => $changes{Text}) if $changes{Text};
+
+my $i = 1;
+foreach my $att (@atts) {
+ local $/=undef;
+ my $file = $att;
+ $file =~ s#^.*[\\/]##;
+
+ my $fh = $cgi->upload("attachment_$i");
+ if ($fh) {
+ my $buf;
+ my ($w, $tmp) = tempfile();
+ my $info = $cgi->uploadInfo();
+
+ while (sysread($fh, $buf, 8192)) {
+ syswrite($w, $buf);
+ }
+
+ $ent->attach(
+ Path => $tmp,
+ Type => $info->{'Content-Type'} || guess_media_type($tmp),
+ Filename => $file,
+ Disposition => "attachment"
+ );
+ }
+ else {
+ $e = 1;
+ $c = "# No attachment for $att.";
+ goto OUTPUT;
+ }
+
+ $i++;
+}
+
+unless ($ticket->CurrentUserHasRight('ModifyTicket') ||
+ ($action eq "Comment" &&
+ $ticket->CurrentUserHasRight("CommentOnTicket")) ||
+ ($action eq "Correspond" &&
+ $ticket->CurrentUserHasRight("ReplyToTicket")))
+{
+ $e = 1;
+ $c = "# You are not allowed to $action on ticket $id.";
+ goto OUTPUT;
+}
+
+my $cc = join ", ", @{ vsplit($changes{Cc}) };
+my $bcc = join ", ", @{ vsplit($changes{Bcc}) };
+my ($n, $s) = $ticket->$action(MIMEObj => $ent,
+ CcMessageTo => $cc,
+ BccMessageTo => $bcc,
+ TimeTaken => $changes{TimeWorked} || 0);
+$c = "# ".$s;
+if ($changes{Status}) {
+ my ($status_n, $status_s) = $ticket->SetStatus($changes{'Status'} );
+ $c .= "\n# ".$status_s;
+}
+
+OUTPUT:
+return [ $c, $o, $k, $e ];
+</%INIT>
diff --git a/rt/html/REST/1.0/Forms/ticket/default b/rt/html/REST/1.0/Forms/ticket/default
index 78f6c9562..69e385f57 100644
--- a/rt/html/REST/1.0/Forms/ticket/default
+++ b/rt/html/REST/1.0/Forms/ticket/default
@@ -2,7 +2,7 @@
%#
%# COPYRIGHT:
%#
-%# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
%# <jesse@bestpractical.com>
%#
%# (Except where explicitly superseded by other copyright notices)
@@ -22,7 +22,9 @@
%#
%# You should have received a copy of the GNU General Public License
%# along with this program; if not, write to the Free Software
-%# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/copyleft/gpl.html.
%#
%#
%# CONTRIBUTION SUBMISSION POLICY:
@@ -49,15 +51,16 @@
$id
$changes => {}
$fields => undef
+$args => undef
</%ARGS>
-<%perl>
+<%INIT>
use MIME::Entity;
my @comments;
my ($c, $o, $k, $e) = ("", [], {}, 0);
my %data = %$changes;
my $ticket = new RT::Ticket $session{CurrentUser};
-my @dates = qw(Created Starts Started Due Resolved Told);
+my @dates = qw(Created Starts Started Due Resolved Told LastUpdated);
my @people = qw(Requestors Cc AdminCc);
my @create = qw(Queue Requestor Subject Cc AdminCc Owner Status Priority
InitialPriority FinalPriority TimeEstimated TimeWorked
@@ -83,7 +86,7 @@ if ($id ne 'new') {
}
}
else {
- if (%data == 0) {
+ if (!keys(%data)) {
# GET ticket/new: Return a suitable default form.
# We get defaults from queue/1 (XXX: What if it isn't there?).
my $due = new RT::Date $session{CurrentUser};
@@ -95,7 +98,7 @@ else {
$starts->SetToNow;
return [
- "# Required: Queue, Requestor, Subject",
+ "# Required: id, Queue",
[ qw(id Queue Requestor Subject Cc AdminCc Owner Status Priority
InitialPriority FinalPriority TimeEstimated Starts Due Text) ],
{
@@ -127,11 +130,26 @@ else {
if (exists $create{lc $k}) {
$v{$create{lc $k}} = delete $data{$k};
}
+ # Set custom field
+ elsif ($k =~ /^CF-/i) {
+ my $cf = RT::CustomField->new( $RT::SystemUser );
+ my $cfk = $k;
+ $cfk =~ s/^CF-//i;
+ unless($cf->LoadByName( Name => $cfk )) {
+ push @comments, "# Invalid custom field name ($cfk)";
+ delete $data{$k};
+ next;
+ }
+ $v{"CustomField-".$cf->Id()} = delete $data{$k};
+ }
elsif (lc $k eq 'text') {
$text = delete $data{$k};
}
}
+ # people fields allow multiple values
+ $v{$_} = vsplit($v{$_}) foreach ( grep $create{lc $_}, @people );
+
if ($text) {
$v{MIMEObj} =
MIME::Entity->build(
@@ -141,20 +159,23 @@ else {
);
}
- $ticket->Create(%v);
- unless ($ticket->Id) {
- return [ "# Could not create ticket.", [], {}, 1 ];
+ my($tid,$trid,$terr) = $ticket->Create(%v);
+ unless ($tid) {
+ push(@comments, "# Could not create ticket.");
+ push(@comments, "# " . $terr);
+ goto DONE;
}
delete $data{id};
$id = $ticket->Id;
push(@comments, "# Ticket $id created.");
- goto DONE if %data == 0;
+ # see if the hash is empty
+ goto DONE if ! keys(%data);
}
}
# Now we know we're dealing with an existing ticket.
-if (%data == 0) {
+if (!keys(%data)) {
my ($time, $key, $val, @data);
push @data, [ id => "ticket/".$ticket->Id ];
@@ -171,7 +192,7 @@ if (%data == 0) {
}
foreach $key (@people) {
- next unless (!%$fields || (exists $fields->{lc $key}));
+ next unless (!%$fields || (exists $fields->{lc $key}));
push @data, [ $key => [ $ticket->$key->MemberEmailAddresses ] ];
}
@@ -190,6 +211,18 @@ if (%data == 0) {
push @data, [ $key => $val ];
}
+ # Display custom fields
+ my $CustomFields = $ticket->QueueObj->TicketCustomFields();
+ while (my $cf = $CustomFields->Next()) {
+ next unless (!%$fields || (exists $fields->{"cf-".lc $cf->Name}));
+ my $vals = $ticket->CustomFieldValues($cf->Id());
+ my @out = ();
+ while (my $v = $vals->Next()) {
+ push @out, $v->Content;
+ }
+ push @data, [ 'CF-' . $cf->Name => join ',', @out ];
+ }
+
my %k = map {@$_} @data;
$o = [ map {$_->[0]} @data ];
$k = \%k;
@@ -271,6 +304,20 @@ else {
$s =~ s/^# //;
}
}
+ # Set custom field
+ elsif ($key =~ /^CF-/i) {
+ my $cf = RT::CustomField->new( $RT::SystemUser );
+ $key =~ s/^CF-//i;
+ if (not $cf->LoadByName( Name => $key )) {
+ $n = 0;
+ $s = "Unknown custom field.";
+ }
+ else {
+ ($n, $s) = $ticket->AddCustomFieldValue(
+ Field => $cf, Value => $val );
+ $s =~ s/^# // if defined $s;
+ }
+ }
elsif ($key ne 'id' && $key ne 'type' && $key ne 'creator') {
$n = 0;
$s = "Unknown field.";
@@ -295,4 +342,4 @@ DONE:
$c ||= join("\n", @comments) if @comments;
return [$c, $o, $k, $e];
-</%perl>
+</%INIT>
diff --git a/rt/html/REST/1.0/Forms/ticket/history b/rt/html/REST/1.0/Forms/ticket/history
index 4663e97ee..5dd7417d0 100644
--- a/rt/html/REST/1.0/Forms/ticket/history
+++ b/rt/html/REST/1.0/Forms/ticket/history
@@ -2,7 +2,7 @@
%#
%# COPYRIGHT:
%#
-%# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
%# <jesse@bestpractical.com>
%#
%# (Except where explicitly superseded by other copyright notices)
@@ -22,7 +22,9 @@
%#
%# You should have received a copy of the GNU General Public License
%# along with this program; if not, write to the Free Software
-%# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/copyleft/gpl.html.
%#
%#
%# CONTRIBUTION SUBMISSION POLICY:
@@ -51,7 +53,7 @@ $args => undef
$format => undef
$fields => undef
</%ARGS>
-<%perl>
+<%INIT>
my $ticket = new RT::Ticket $session{CurrentUser};
my ($c, $o, $k, $e) = ("", [], {}, "");
@@ -94,7 +96,19 @@ if ($type) {
if ($tid) {
my @data;
my $t = new RT::Transaction $session{CurrentUser};
- $t->Load($tid);
+
+ # this paragraph limits the transaction ID query to transactions on this ticket.
+ # Otherwise you can query any transaction from any ticket, which makes no sense.
+ my $Transactions = $ticket->Transactions;
+ my $tok=0;
+ while (my $T = $Transactions->Next()) {
+ $tok=1 if ($T->Id == $tid)
+ }
+ if ($tok) {
+ $t->Load($tid);
+ } else {
+ return [ "# Transaction $tid is not related to Ticket $id", [], {}, 1 ];
+ }
push @data, [ id => $t->Id ];
push @data, [ Ticket => $t->Ticket ]
@@ -168,8 +182,7 @@ if ($tid) {
$fieldstring .= $key;
}
my ($content, $forms);
-
- $m->subexec("$RT::WebPath/REST/1.0/show",
+ $m->subexec("/REST/1.0/show",
id => \@tid,
format => $format,
fields => $fieldstring);
@@ -184,4 +197,4 @@ if (!$c) {
return [ $c, $o, $k, $e ];
-</%perl>
+</%INIT>
diff --git a/rt/html/REST/1.0/Forms/ticket/links b/rt/html/REST/1.0/Forms/ticket/links
index 9f14da4e3..6b2ed222d 100644
--- a/rt/html/REST/1.0/Forms/ticket/links
+++ b/rt/html/REST/1.0/Forms/ticket/links
@@ -2,7 +2,7 @@
%#
%# COPYRIGHT:
%#
-%# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
%# <jesse@bestpractical.com>
%#
%# (Except where explicitly superseded by other copyright notices)
@@ -22,7 +22,9 @@
%#
%# You should have received a copy of the GNU General Public License
%# along with this program; if not, write to the Free Software
-%# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/copyleft/gpl.html.
%#
%#
%# CONTRIBUTION SUBMISSION POLICY:
@@ -50,7 +52,7 @@ $id
$format => 's'
$changes => undef
</%ARGS>
-<%perl>
+<%INIT>
my @data;
my $ticket = new RT::Ticket $session{CurrentUser};
@@ -167,4 +169,4 @@ else {
}
return [ $c, $o, $k, $e ];
-</%perl>
+</%INIT>
diff --git a/rt/html/REST/1.0/Forms/ticket/merge b/rt/html/REST/1.0/Forms/ticket/merge
new file mode 100755
index 000000000..69af6c8e1
--- /dev/null
+++ b/rt/html/REST/1.0/Forms/ticket/merge
@@ -0,0 +1,96 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
+%# <jesse@bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/copyleft/gpl.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+%# REST/1.0/Forms/ticket/merge
+%#
+<%ARGS>
+$id
+$args
+</%ARGS>
+<%INIT>
+use RT::Interface::REST;
+
+my $into = $args;
+
+my $ticket = new RT::Ticket $session{CurrentUser};
+my $ticket_into = new RT::Ticket $session{CurrentUser};
+my ($c, $o, $k, $e) = ("", [], {}, 0);
+
+# http://.../REST/1.0/ticket/1/merge/6 (merges ticket 1 into ticket 6)
+
+$ticket->Load($id);
+if (!$ticket->Id) {
+ $e = 1;
+ $c = "# Ticket $id does not exist.";
+ goto OUTPUT;
+}
+$ticket_into->Load($into);
+if (!$ticket_into->Id) {
+ $e = 1;
+ $c = "# Ticket $into does not exist.";
+ goto OUTPUT;
+}
+
+if (!$ticket->CurrentUserHasRight('ModifyTicket')) {
+ $e = 1;
+ $c = "# You are not allowed to modify ticket $id.";
+ goto OUTPUT;
+}
+
+my ($n, $s) = $ticket->MergeInto($into);
+
+if ($n == 0) {
+ $e = 1;
+ $c = "# Could not complete the merge.";
+}
+else {
+ $c = "# Merge completed.";
+}
+
+OUTPUT:
+return [ $c, $o, $k, $e ];
+</%INIT>
diff --git a/rt/html/REST/1.0/Forms/ticket/take b/rt/html/REST/1.0/Forms/ticket/take
new file mode 100755
index 000000000..35ee11fa7
--- /dev/null
+++ b/rt/html/REST/1.0/Forms/ticket/take
@@ -0,0 +1,135 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
+%# <jesse@bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/copyleft/gpl.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+%# REST/1.0/Forms/ticket/take
+%#
+<%ARGS>
+$id
+%changes
+</%ARGS>
+<%INIT>
+use RT::Interface::REST;
+
+my $ticket = new RT::Ticket $session{CurrentUser};
+my ($c, $o, $k, $e) = ("", [], {}, 0);
+
+# http://.../REST/1.0/ticket/1/take
+$ticket->Load( $id );
+unless ( $ticket->Id ) {
+ $e = 1;
+ $c = "# Ticket $id does not exist.";
+ goto OUTPUT;
+}
+
+my $action;
+
+my @comments;
+
+($action = $changes{Action}) =~ s/^(.)(.*)$/\U$1\L$2\E/;
+unless ($action =~ /^(?:Take|Steal|Untake)$/) {
+ $e = 1;
+ $c = "# Invalid action: `$action'.";
+ goto OUTPUT;
+}
+
+my ($status, $msg) = $ticket->$action();
+$c = "# $msg";
+$e = 1 unless $status;
+goto OUTPUT;
+
+#unless ($ticket->CurrentUserHasRight('ModifyTicket') ||
+# ( ($action eq "Take" || $action eq 'Untake') &&
+# $ticket->CurrentUserHasRight("TakeTicket")) ||
+# ($action eq "Steal" &&
+# $ticket->CurrentUserHasRight("StealTicket")))
+#{
+# $e = 1;
+# $c = "# You are not allowed to $action ticket $id.";
+# goto OUTPUT;
+#}
+
+#if ( keys %changes ) {
+#}
+#else {
+# # process the form data structure
+# my ($key, $val);
+#
+# foreach $key (keys %data) {
+# $val = $data{$key};
+#
+# if ($key =~ /^force$/i) {
+# if ($val !~ /^(?:0|1)$/) {
+# push(@comments, "# invalid value for 'force': $val");
+# goto DONE;
+# }
+# my ($ret_id, $msg);
+#
+# ### take
+# if ($val == 0) {
+# ($ret_id, $msg) = $ticket->Take;
+# if (!$ret_id) {
+# push(@comments, "# Couldn't take ticket $id: $msg");
+# goto DONE;
+# }
+# push(@comments, "# Ticket $id taken.");
+# }
+# ### steal
+# else {
+# ($ret_id, $msg) = $ticket->Steal;
+# if (!$ret_id) {
+# push(@comments, "# Couldn't steal ticket $id: $msg");
+# goto DONE;
+# }
+# push(@comments, "# Ticket $id stolen.");
+# }
+# }
+# }
+#}
+
+OUTPUT:
+return [ $c, $o, $k, $e ];
+</%INIT>