Putting 4.2.0 on top of 4.0.17
[usit-rt.git] / share / html / REST / 1.0 / Forms / ticket / history
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/Forms/ticket/history
49%#
50<%ARGS>
51$id
52$args => undef
53$format => undef
54$fields => undef
55</%ARGS>
56<%INIT>
57my $ticket = RT::Ticket->new($session{CurrentUser});
58my ($c, $o, $k, $e) = ("", [], {}, "");
59
60$ticket->Load($id);
61unless ($ticket->Id) {
62 return [ "# Ticket $id does not exist.", [], {}, 1 ];
63}
64
65my $trans = $ticket->Transactions();
66my $total = $trans->Count();
67
68if ( $args ) {
69 chomp $args;
70}
71else {
72 $args = '';
73}
74
75my @arglist = split('/', $args );
76my ($type, $tid);
77if (defined $arglist[0] && $arglist[0] eq 'type') {
78 $type = $arglist[1];
79} elsif ( defined $arglist[0] && $arglist[0] eq 'id') {
80 $tid = $arglist[1];
81} else {
82 $type = $args;
83}
84
85if ($type) {
86 # Create, Set, Status, Correspond, Comment, Give, Steal, Take, Told
87 # CustomField, AddLink, DeleteLink, AddWatcher, DelWatcher
88 if ($args =~ /^links?$/) {
89 $trans->Limit(FIELD => 'Type', OPERATOR => 'LIKE', VALUE => '%Link');
90 }
91 elsif ($args =~ /^watchers?$/) {
92 $trans->Limit(FIELD => 'Type', OPERATOR => 'LIKE', VALUE => '%Watcher');
93 }
94 else {
95 $trans->Limit(FIELD => 'Type', OPERATOR => '=', VALUE => $type);
96 }
97} elsif ($tid) {
98 $trans->Limit(FIELD => 'Id', OPERATOR => '=', VALUE => $tid);
99}
100
101if ($tid) {
102 my @data;
103 my $t = RT::Transaction->new($session{CurrentUser});
af59614d 104
84fb5b46
MKG
105 # this paragraph limits the transaction ID query to transactions on this ticket.
106 # Otherwise you can query any transaction from any ticket, which makes no sense.
107 my $Transactions = $ticket->Transactions;
108 my $tok=0;
109 while (my $T = $Transactions->Next()) {
af59614d 110 $tok=1 if ($T->Id == $tid)
84fb5b46
MKG
111 }
112 if ($tok) {
af59614d 113 $t->Load($tid);
84fb5b46 114 } else {
af59614d 115 return [ "# Transaction $tid is not related to Ticket $id", [], {}, 1 ];
84fb5b46
MKG
116 }
117
118 push @data, [ id => $t->Id ];
119 push @data, [ Ticket => $t->Ticket ]
af59614d 120 if (!%$fields || exists $fields->{lc 'Ticket'});
84fb5b46 121 push @data, [ TimeTaken => $t->TimeTaken ]
af59614d 122 if (!%$fields || exists $fields->{lc 'TimeTaken'});
84fb5b46 123 push @data, [ Type => $t->Type ]
af59614d 124 if (!%$fields || exists $fields->{lc 'Type'});
84fb5b46 125 push @data, [ Field => $t->Field ]
af59614d 126 if (!%$fields || exists $fields->{lc 'Field'});
84fb5b46 127 push @data, [ OldValue => $t->OldValue ]
af59614d 128 if (!%$fields || exists $fields->{lc 'OldValue'});
84fb5b46 129 push @data, [ NewValue => $t->NewValue ]
af59614d 130 if (!%$fields || exists $fields->{lc 'NewValue'});
84fb5b46 131 push @data, [ Data => $t->Data ]
af59614d 132 if (!%$fields || exists $fields->{lc 'Data'});
84fb5b46 133 push @data, [ Description => $t->Description ]
af59614d 134 if (!%$fields || exists $fields->{lc 'Description'});
84fb5b46 135 push @data, [ Content => $t->Content ]
af59614d 136 if (!%$fields || exists $fields->{lc 'Content'});
84fb5b46
MKG
137
138
af59614d
MKG
139 if (!%$fields || exists $fields->{lc 'Content'}) {
140 my $creator = RT::User->new($session{CurrentUser});
141 $creator->Load($t->Creator);
142 push @data, [ Creator => $creator->Name ];
84fb5b46
MKG
143 }
144 push @data, [ Created => $t->Created ]
af59614d 145 if (!%$fields || exists $fields->{lc 'Created'});
84fb5b46
MKG
146
147 if (!%$fields || exists $fields->{lc 'Attachments'}) {
af59614d
MKG
148 my $attachlist;
149 my $attachments = $t->Attachments;
150 while (my $a = $attachments->Next) {
151 my $size = length($a->Content||'');
152 if ($size > 1024) { $size = int($size/102.4)/10 . "k" }
153 else { $size .= "b" }
84fb5b46
MKG
154 my $name = (defined $a->Filename and length $a->Filename) ? $a->Filename : "untitled";
155 $attachlist .= "\n" . $a->Id.": $name ($size)";
af59614d
MKG
156 }
157
158 push @data, [Attachments => $attachlist];
84fb5b46
MKG
159 }
160
161 my %k = map {@$_} @data;
162 $o = [ map {$_->[0]} @data ];
163 $k = \%k;
164
165} else {
166 my (@data, $tids);
167 $format ||= "s";
168 $format = "l" if (%$fields);
169
170 while (my $t = $trans->Next) {
af59614d
MKG
171 my $tid = $t->Id;
172
173 if ($format eq "l") {
174 $tids .= "," if $tids;
175 $tids .= $tid;
176 } else {
177 push @$o, $tid;
178 $k->{$tid} = $t->Description;
179 }
84fb5b46
MKG
180 }
181
182 if ($format eq "l") {
af59614d
MKG
183 my @tid;
184 push @tid, "ticket/$id/history/id/$tids";
185 my $fieldstring;
186 foreach my $key (keys %$fields) {
187 $fieldstring .= "," if $fieldstring;
188 $fieldstring .= $key;
189 }
190 my ($content, $forms);
191 $m->subexec("/REST/1.0/show",
192 id => \@tid,
193 format => $format,
84fb5b46 194 fields => $fieldstring);
af59614d 195 return [ $c, $o, $k, $e ];
84fb5b46
MKG
196 }
197}
198
199if (!$c) {
200 my $sub = $trans->Count();
201 $c = "# $sub/$total ($args/total)";
202}
203
204return [ $c, $o, $k, $e ];
205
206</%INIT>