diff options
Diffstat (limited to 'rt/share/html/REST/1.0/Forms/ticket')
-rwxr-xr-x | rt/share/html/REST/1.0/Forms/ticket/attachments | 32 | ||||
-rwxr-xr-x | rt/share/html/REST/1.0/Forms/ticket/default | 105 | ||||
-rwxr-xr-x | rt/share/html/REST/1.0/Forms/ticket/history | 96 |
3 files changed, 102 insertions, 131 deletions
diff --git a/rt/share/html/REST/1.0/Forms/ticket/attachments b/rt/share/html/REST/1.0/Forms/ticket/attachments index b9e364782..b9619ecd2 100755 --- a/rt/share/html/REST/1.0/Forms/ticket/attachments +++ b/rt/share/html/REST/1.0/Forms/ticket/attachments @@ -89,23 +89,23 @@ if ($aid) { $r->content_type($attachment->ContentType); } } else { - my @data; - push @data, [ id => $attachment->Id ]; - push @data, [ Subject => $attachment->Subject ]; - push @data, [ Creator => $attachment->Creator ]; - push @data, [ Created => $attachment->Created ]; - push @data, [ Transaction => $attachment->TransactionId ]; - push @data, [ Parent => $attachment->Parent ]; - push @data, [ MessageId => $attachment->MessageId ]; - push @data, [ Filename => $attachment->Filename ]; - push @data, [ ContentType => $attachment->ContentType ]; - push @data, [ ContentEncoding => $attachment->ContentEncoding ]; - push @data, [ Headers => $attachment->Headers ]; - push @data, [ Content => $attachment->Content ]; + my @data; + push @data, [ id => $attachment->Id ]; + push @data, [ Subject => $attachment->Subject ]; + push @data, [ Creator => $attachment->Creator ]; + push @data, [ Created => $attachment->Created ]; + push @data, [ Transaction => $attachment->TransactionId ]; + push @data, [ Parent => $attachment->Parent ]; + push @data, [ MessageId => $attachment->MessageId ]; + push @data, [ Filename => $attachment->Filename ]; + push @data, [ ContentType => $attachment->ContentType ]; + push @data, [ ContentEncoding => $attachment->ContentEncoding ]; + push @data, [ Headers => $attachment->Headers ]; + push @data, [ Content => $attachment->Content ]; - my %k = map {@$_} @data; - $o = [ map {$_->[0]} @data ]; - $k = \%k; + my %k = map {@$_} @data; + $o = [ map {$_->[0]} @data ]; + $k = \%k; } } diff --git a/rt/share/html/REST/1.0/Forms/ticket/default b/rt/share/html/REST/1.0/Forms/ticket/default index a546af7b6..e60b6a679 100755 --- a/rt/share/html/REST/1.0/Forms/ticket/default +++ b/rt/share/html/REST/1.0/Forms/ticket/default @@ -99,12 +99,16 @@ else { 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 = RT::Date->new($session{CurrentUser}); my $queue = RT::Queue->new($session{CurrentUser}); - my $starts = RT::Date->new($session{CurrentUser}); $queue->Load(1); - $due->SetToNow; - $due->AddDays($queue->DefaultDueIn) if $queue->DefaultDueIn; + + my $due; + if ($queue->DefaultDueIn) { + $due = RT::Date->new($session{CurrentUser}); + $due->SetToNow; + $due->AddDays($queue->DefaultDueIn); + } + my $starts = RT::Date->new($session{CurrentUser}); $starts->SetToNow; return [ @@ -124,8 +128,8 @@ else { InitialPriority => $queue->InitialPriority, FinalPriority => $queue->FinalPriority, TimeEstimated => 0, - Starts => $starts->ISO, - Due => $due->ISO, + Starts => $starts->ISO(Timezone => 'user'), + Due => $due ? $due->ISO(Timezone => 'user') : undef, Attachment => '', Text => "", }, @@ -153,17 +157,21 @@ else { my $key = $1 || $2; my $cf = RT::CustomField->new( $session{CurrentUser} ); - $cf->LoadByName( Name => $key, Queue => $data{Queue} || $v{Queue} ); - unless ( $cf->id ) { - $cf->LoadByName( Name => $key, Queue => 0 ); - } + $cf->LoadByName( + Name => $key, + LookupType => RT::Ticket->CustomFieldLookupType, + ObjectId => $data{Queue} || $v{Queue}, + IncludeGlobal => 1, + ); if (not $cf->id) { push @comments, "# Invalid custom field name ($key)"; delete $data{$k}; next; } - $v{"CustomField-".$cf->Id()} = delete $data{$k}; + my $val = delete $data{$k}; + next unless defined $val && length $val; + $v{"CustomField-".$cf->Id()} = $cf->SingleValue ? $val : vsplit($val,1); } elsif (lc $k eq 'text') { $text = delete $data{$k}; @@ -228,15 +236,15 @@ if (!keys(%data)) { my ($time, $key, $val, @data); push @data, [ id => "ticket/".$ticket->Id ]; - push @data, [ Queue => $ticket->QueueObj->Name ] - if (!%$fields || exists $fields->{lc 'Queue'}); + push @data, [ Queue => $ticket->QueueObj->Name ] + if (!%$fields || exists $fields->{lc 'Queue'}); push @data, [ Owner => $ticket->OwnerObj->Name ] - if (!%$fields || exists $fields->{lc 'Owner'}); + if (!%$fields || exists $fields->{lc 'Owner'}); push @data, [ Creator => $ticket->CreatorObj->Name ] - if (!%$fields || exists $fields->{lc 'Creator'}); + if (!%$fields || exists $fields->{lc 'Creator'}); foreach (qw(Subject Status Priority InitialPriority FinalPriority)) { - next unless (!%$fields || (exists $fields->{lc $_})); + next unless (!%$fields || (exists $fields->{lc $_})); push @data, [$_ => $ticket->$_ ]; } @@ -247,14 +255,14 @@ if (!keys(%data)) { $time = RT::Date->new ($session{CurrentUser}); foreach $key (@dates) { - next unless (!%$fields || (exists $fields->{lc $key})); + next unless (!%$fields || (exists $fields->{lc $key})); $time->Set(Format => 'sql', Value => $ticket->$key); push @data, [ $key => $time->AsString ]; } $time = RT::Date->new ($session{CurrentUser}); foreach $key (qw(TimeEstimated TimeWorked TimeLeft)) { - next unless (!%$fields || (exists $fields->{lc $key})); + next unless (!%$fields || (exists $fields->{lc $key})); $val = $ticket->$key || 0; $val = "$val minutes" if $val; push @data, [ $key => $val ]; @@ -276,8 +284,8 @@ if (!keys(%data)) { else { while (my $v = $vals->Next()) { my $content = $v->Content; - $content =~ s/'/\\'/g; if ( $v->Content =~ /,/ ) { + $content =~ s/([\\'])/\\$1/g; push @out, q{'} . $content . q{'}; } else { @@ -380,10 +388,13 @@ else { $key = $1 || $2; my $cf = RT::CustomField->new( $session{CurrentUser} ); - $cf->LoadByName( Name => $key, Queue => $ticket->Queue ); - unless ( $cf->id ) { - $cf->LoadByName( Name => $key, Queue => 0 ); - } + $cf->ContextObject( $ticket ); + $cf->LoadByName( + Name => $key, + LookupType => RT::Ticket->CustomFieldLookupType, + ObjectId => $ticket->Queue, + IncludeGlobal => 1, + ); if (not $cf->id) { $n = 0; @@ -401,52 +412,12 @@ else { } } elsif ( $cf->SingleValue ) { - my $old = $vals->Next; - if ( $old ) { - if ( $val ne $old->Content ) { - ($n, $s) = $ticket->AddCustomFieldValue( - Field => $cf, Value => $val ); - $s =~ s/^# // if defined $s; - } - } - else { - ($n, $s) = $ticket->AddCustomFieldValue( - Field => $cf, Value => $val ); - $s =~ s/^# // if defined $s; - } + ($n, $s) = $ticket->AddCustomFieldValue( + Field => $cf, Value => $val ); + $s =~ s/^# // if defined $s; } else { - my @new; - my ( $a, $b ) = split /\s*,\s*/, $val, 2; - while ($a) { - no warnings 'uninitialized'; - if ( $a =~ /^'/ ) { - my $s = $a; - while ( $a !~ /'$/ || ( $a !~ /(\\\\)+'$/ - && $a =~ /(\\)+'$/ ) ) { - ( $a, $b ) = split /\s*,\s*/, $b, 2; - $s .= ',' . $a; - } - $s =~ s/^'//; - $s =~ s/'$//; - $s =~ s/\\'/'/g; - push @new, $s; - } - elsif ( $a =~ /^q\{/ ) { - my $s = $a; - while ( $a !~ /\}$/ ) { - ( $a, $b ) = split /\s*,\s*/, $b, 2; - $s .= ',' . $a; - } - $s =~ s/^q\{//; - $s =~ s/\}//; - push @new, $s; - } - else { - push @new, $a; - } - ( $a, $b ) = split /\s*,\s*/, $b, 2; - } + my @new = @{vsplit($val, 1)}; my %new; $new{$_}++ for @new; diff --git a/rt/share/html/REST/1.0/Forms/ticket/history b/rt/share/html/REST/1.0/Forms/ticket/history index 8bbb5b733..f5d2d2552 100755 --- a/rt/share/html/REST/1.0/Forms/ticket/history +++ b/rt/share/html/REST/1.0/Forms/ticket/history @@ -101,61 +101,61 @@ if ($type) { if ($tid) { my @data; my $t = RT::Transaction->new($session{CurrentUser}); - + # 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) + $tok=1 if ($T->Id == $tid) } if ($tok) { - $t->Load($tid); + $t->Load($tid); } else { - return [ "# Transaction $tid is not related to Ticket $id", [], {}, 1 ]; + return [ "# Transaction $tid is not related to Ticket $id", [], {}, 1 ]; } push @data, [ id => $t->Id ]; push @data, [ Ticket => $t->Ticket ] - if (!%$fields || exists $fields->{lc 'Ticket'}); + if (!%$fields || exists $fields->{lc 'Ticket'}); push @data, [ TimeTaken => $t->TimeTaken ] - if (!%$fields || exists $fields->{lc 'TimeTaken'}); + if (!%$fields || exists $fields->{lc 'TimeTaken'}); push @data, [ Type => $t->Type ] - if (!%$fields || exists $fields->{lc 'Type'}); + if (!%$fields || exists $fields->{lc 'Type'}); push @data, [ Field => $t->Field ] - if (!%$fields || exists $fields->{lc 'Field'}); + if (!%$fields || exists $fields->{lc 'Field'}); push @data, [ OldValue => $t->OldValue ] - if (!%$fields || exists $fields->{lc 'OldValue'}); + if (!%$fields || exists $fields->{lc 'OldValue'}); push @data, [ NewValue => $t->NewValue ] - if (!%$fields || exists $fields->{lc 'NewValue'}); + if (!%$fields || exists $fields->{lc 'NewValue'}); push @data, [ Data => $t->Data ] - if (!%$fields || exists $fields->{lc 'Data'}); + if (!%$fields || exists $fields->{lc 'Data'}); push @data, [ Description => $t->Description ] - if (!%$fields || exists $fields->{lc 'Description'}); + if (!%$fields || exists $fields->{lc 'Description'}); push @data, [ Content => $t->Content ] - if (!%$fields || exists $fields->{lc 'Content'}); + if (!%$fields || exists $fields->{lc 'Content'}); - if (!%$fields || exists $fields->{lc 'Content'}) { - my $creator = RT::User->new($session{CurrentUser}); - $creator->Load($t->Creator); - push @data, [ Creator => $creator->Name ]; + if (!%$fields || exists $fields->{lc 'Content'}) { + my $creator = RT::User->new($session{CurrentUser}); + $creator->Load($t->Creator); + push @data, [ Creator => $creator->Name ]; } push @data, [ Created => $t->Created ] - if (!%$fields || exists $fields->{lc 'Created'}); + if (!%$fields || exists $fields->{lc 'Created'}); if (!%$fields || exists $fields->{lc 'Attachments'}) { - my $attachlist; - my $attachments = $t->Attachments; - while (my $a = $attachments->Next) { - my $size = length($a->Content||''); - if ($size > 1024) { $size = int($size/102.4)/10 . "k" } - else { $size .= "b" } + my $attachlist; + my $attachments = $t->Attachments; + while (my $a = $attachments->Next) { + my $size = length($a->Content||''); + if ($size > 1024) { $size = int($size/102.4)/10 . "k" } + else { $size .= "b" } my $name = (defined $a->Filename and length $a->Filename) ? $a->Filename : "untitled"; $attachlist .= "\n" . $a->Id.": $name ($size)"; - } - - push @data, [Attachments => $attachlist]; + } + + push @data, [Attachments => $attachlist]; } my %k = map {@$_} @data; @@ -168,31 +168,31 @@ if ($tid) { $format = "l" if (%$fields); while (my $t = $trans->Next) { - my $tid = $t->Id; - - if ($format eq "l") { - $tids .= "," if $tids; - $tids .= $tid; - } else { - push @$o, $tid; - $k->{$tid} = $t->Description; - } + my $tid = $t->Id; + + if ($format eq "l") { + $tids .= "," if $tids; + $tids .= $tid; + } else { + push @$o, $tid; + $k->{$tid} = $t->Description; + } } if ($format eq "l") { - my @tid; - push @tid, "ticket/$id/history/id/$tids"; - my $fieldstring; - foreach my $key (keys %$fields) { - $fieldstring .= "," if $fieldstring; - $fieldstring .= $key; - } - my ($content, $forms); - $m->subexec("/REST/1.0/show", - id => \@tid, - format => $format, + my @tid; + push @tid, "ticket/$id/history/id/$tids"; + my $fieldstring; + foreach my $key (keys %$fields) { + $fieldstring .= "," if $fieldstring; + $fieldstring .= $key; + } + my ($content, $forms); + $m->subexec("/REST/1.0/show", + id => \@tid, + format => $format, fields => $fieldstring); - return [ $c, $o, $k, $e ]; + return [ $c, $o, $k, $e ]; } } |