diff options
Diffstat (limited to 'rt/share/html/REST')
-rw-r--r-- | rt/share/html/REST/1.0/Forms/group/default | 49 | ||||
-rw-r--r-- | rt/share/html/REST/1.0/Forms/group/ns | 2 | ||||
-rwxr-xr-x | rt/share/html/REST/1.0/Forms/queue/default | 9 | ||||
-rwxr-xr-x | rt/share/html/REST/1.0/Forms/queue/ns | 2 | ||||
-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 | ||||
-rw-r--r-- | rt/share/html/REST/1.0/Forms/transaction/default | 109 | ||||
-rwxr-xr-x | rt/share/html/REST/1.0/Forms/user/default | 49 | ||||
-rwxr-xr-x | rt/share/html/REST/1.0/Forms/user/ns | 2 | ||||
-rwxr-xr-x | rt/share/html/REST/1.0/NoAuth/mail-gateway | 18 | ||||
-rwxr-xr-x | rt/share/html/REST/1.0/dhandler | 32 | ||||
-rwxr-xr-x | rt/share/html/REST/1.0/search/dhandler | 245 | ||||
-rwxr-xr-x | rt/share/html/REST/1.0/search/ticket | 165 |
14 files changed, 498 insertions, 417 deletions
diff --git a/rt/share/html/REST/1.0/Forms/group/default b/rt/share/html/REST/1.0/Forms/group/default index 58dae576a..3a872d067 100644 --- a/rt/share/html/REST/1.0/Forms/group/default +++ b/rt/share/html/REST/1.0/Forms/group/default @@ -58,7 +58,12 @@ my @comments; my ($c, $o, $k, $e) = ("", [], {}, 0); my %data = %$changes; my $group = RT::Group->new($session{CurrentUser}); -my @fields = qw(Name Description); + +my @fields = qw(Name Description Disabled); +if ( $fields && %$fields ) { + @fields = grep { exists $fields->{ lc $_ } } @fields; +} + my %fields = map { lc $_ => $_ } @fields; if ($id ne 'new') { @@ -109,31 +114,33 @@ if (%data == 0) { my @data; push @data, [ id => "group/".$group->Id ]; - push @data, [ Name => $group->Name ]; - push @data, [ Description => $group->Description ]; - + foreach my $key (@fields) { + push @data, [ $key => $group->$key ]; + } # Members - my $gms = []; - my $GroupMembers = $group->MembersObj(); - while ( my $mo = $GroupMembers->Next() ) { - if ( $mo->MemberObj->IsGroup ) { - my $us = $mo->MemberObj->Object->UserMembersObj(); - my @users; - while ( my $u = $us->Next() ) { - push @users, $u->RealName . ' <' . $u->EmailAddress . '>'; + unless ( $fields && !exists $fields->{members} ) { + my $gms = []; + my $GroupMembers = $group->MembersObj(); + while ( my $mo = $GroupMembers->Next() ) { + if ( $mo->MemberObj->IsGroup ) { + my $us = $mo->MemberObj->Object->UserMembersObj(); + my @users; + while ( my $u = $us->Next() ) { + push @users, $u->RealName . ' <' . $u->EmailAddress . '>'; + } + push @$gms, + 'GROUP [' + . $mo->MemberObj->Object->Name . ']' . ' (' + . join( ';', @users ) . ')'; + } elsif ( $mo->MemberObj->IsUser ) { + push @$gms, + $mo->MemberObj->Object->RealName . ' <' + . $mo->MemberObj->Object->EmailAddress . '>'; } - push @$gms, - 'GROUP [' - . $mo->MemberObj->Object->Name . ']' . ' (' - . join( ';', @users ) . ')'; - } elsif ( $mo->MemberObj->IsUser ) { - push @$gms, - $mo->MemberObj->Object->RealName . ' <' - . $mo->MemberObj->Object->EmailAddress . '>'; } + push @data, [ Members => $gms ]; } - push @data, [ Members => $gms ]; # Custom fields my $CustomFields = $group->CustomFields; diff --git a/rt/share/html/REST/1.0/Forms/group/ns b/rt/share/html/REST/1.0/Forms/group/ns index b02793459..7be8eaf92 100644 --- a/rt/share/html/REST/1.0/Forms/group/ns +++ b/rt/share/html/REST/1.0/Forms/group/ns @@ -54,7 +54,7 @@ $id use RT::Groups; my $groups = RT::Groups->new($session{CurrentUser}); -$groups->Limit(FIELD => 'Name', OPERATOR => '=', VALUE => $id); +$groups->Limit(FIELD => 'Name', OPERATOR => '=', VALUE => $id, CASESENSITIVE => 0); if ($groups->Count == 0) { return (0, "No group named $id exists."); } diff --git a/rt/share/html/REST/1.0/Forms/queue/default b/rt/share/html/REST/1.0/Forms/queue/default index bb8eb5f9e..a85b05792 100755 --- a/rt/share/html/REST/1.0/Forms/queue/default +++ b/rt/share/html/REST/1.0/Forms/queue/default @@ -58,8 +58,13 @@ my @comments; my ($c, $o, $k, $e) = ("", [], {}, 0); my %data = %$changes; my $queue = RT::Queue->new($session{CurrentUser}); -my @fields = qw(Name Description CorrespondAddress CommentAddress - InitialPriority FinalPriority DefaultDueIn); + +my @fields = + qw(Name Description CorrespondAddress CommentAddress InitialPriority FinalPriority DefaultDueIn Disabled); +if ( $fields && %$fields ) { + @fields = grep { exists $fields->{ lc $_ } } @fields; +} + my %fields = map { lc $_ => $_ } @fields; if ($id ne 'new') { diff --git a/rt/share/html/REST/1.0/Forms/queue/ns b/rt/share/html/REST/1.0/Forms/queue/ns index 24bd86876..618acc057 100755 --- a/rt/share/html/REST/1.0/Forms/queue/ns +++ b/rt/share/html/REST/1.0/Forms/queue/ns @@ -54,7 +54,7 @@ $id use RT::Queues; my $queues = RT::Queues->new($session{CurrentUser}); -$queues->Limit(FIELD => 'Name', OPERATOR => '=', VALUE => $id); +$queues->Limit(FIELD => 'Name', OPERATOR => '=', VALUE => $id, CASESENSITIVE => 0 ); if ($queues->Count == 0) { return (0, "No queue named $id exists."); } 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 ]; } } diff --git a/rt/share/html/REST/1.0/Forms/transaction/default b/rt/share/html/REST/1.0/Forms/transaction/default index 27dcb3841..19387f3c1 100644 --- a/rt/share/html/REST/1.0/Forms/transaction/default +++ b/rt/share/html/REST/1.0/Forms/transaction/default @@ -65,54 +65,53 @@ if ($tid) { my $t = RT::Transaction->new($session{CurrentUser}); $t->Load($tid); if ($format eq "l") { - push @data, [ id => $t->Id ]; - push @data, [ Ticket => $t->Ticket ] - if (!%$fields || exists $fields->{lc 'Ticket'}); - push @data, [ TimeTaken => $t->TimeTaken ] - if (!%$fields || exists $fields->{lc 'TimeTaken'}); - push @data, [ Type => $t->Type ] - if (!%$fields || exists $fields->{lc 'Type'}); - push @data, [ Field => $t->Field ] - if (!%$fields || exists $fields->{lc 'Field'}); - push @data, [ OldValue => $t->OldValue ] - if (!%$fields || exists $fields->{lc 'OldValue'}); - push @data, [ NewValue => $t->NewValue ] - if (!%$fields || exists $fields->{lc 'NewValue'}); - push @data, [ Data => $t->Data ] - if (!%$fields || exists $fields->{lc 'Data'}); - push @data, [ Description => $t->Description ] - if (!%$fields || exists $fields->{lc 'Description'}); - push @data, [ Content => $t->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 ]; - } - push @data, [ Created => $t->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 $name = (defined $a->Filename and length $a->Filename) ? $a->Filename : "untitled"; - $attachlist .= "\n" . $a->Id.": $name ($size)"; - } - push @data, [Attachments => $attachlist]; - } - + push @data, [ id => $t->Id ]; + push @data, [ Ticket => $t->Ticket ] + if (!%$fields || exists $fields->{lc 'Ticket'}); + push @data, [ TimeTaken => $t->TimeTaken ] + if (!%$fields || exists $fields->{lc 'TimeTaken'}); + push @data, [ Type => $t->Type ] + if (!%$fields || exists $fields->{lc 'Type'}); + push @data, [ Field => $t->Field ] + if (!%$fields || exists $fields->{lc 'Field'}); + push @data, [ OldValue => $t->OldValue ] + if (!%$fields || exists $fields->{lc 'OldValue'}); + push @data, [ NewValue => $t->NewValue ] + if (!%$fields || exists $fields->{lc 'NewValue'}); + push @data, [ Data => $t->Data ] + if (!%$fields || exists $fields->{lc 'Data'}); + push @data, [ Description => $t->Description ] + if (!%$fields || exists $fields->{lc 'Description'}); + push @data, [ Content => $t->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 ]; + } + push @data, [ Created => $t->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 $name = (defined $a->Filename and length $a->Filename) ? $a->Filename : "untitled"; + $attachlist .= "\n" . $a->Id.": $name ($size)"; + } + push @data, [Attachments => $attachlist]; + } } else { - push @data, [ id => $t->Id ]; - push @data, [ Description => $t->Description ]; + push @data, [ id => $t->Id ]; + push @data, [ Description => $t->Description ]; } my %k = map {@$_} @data; @@ -125,14 +124,14 @@ 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; +# } # } #} diff --git a/rt/share/html/REST/1.0/Forms/user/default b/rt/share/html/REST/1.0/Forms/user/default index 227fc8133..53d0e28ae 100755 --- a/rt/share/html/REST/1.0/Forms/user/default +++ b/rt/share/html/REST/1.0/Forms/user/default @@ -51,17 +51,25 @@ $id $format => 's' $changes => {} +$fields => undef </%ARGS> <%perl> my @comments; my ($c, $o, $k, $e) = ("", [], {}, 0); my %data = %$changes; my $user = RT::User->new($session{CurrentUser}); -my @fields = qw(RealName NickName Gecos Organization Address1 Address2 City - State Zip Country HomePhone WorkPhone MobilePhone PagerPhone - FreeformContactInfo Comments Signature Lang EmailEncoding - WebEncoding ExternalContactInfoId ContactInfoSystem - ExternalAuthId AuthSystem Privileged Disabled); + +my @fields = + qw(Name EmailAddress RealName NickName Gecos Organization Address1 + Address2 City State Zip Country HomePhone WorkPhone MobilePhone PagerPhone + FreeformContactInfo Comments Signature Lang EmailEncoding + WebEncoding ExternalContactInfoId ContactInfoSystem + ExternalAuthId AuthSystem Privileged Disabled); + +if ( $fields && %$fields ) { + @fields = grep { exists $fields->{ lc $_ } } @fields; +} + my %fields = map { lc $_ => $_ } @fields; if ($id ne 'new') { @@ -117,19 +125,38 @@ if (keys %data == 0) { my @data; push @data, [ id => "user/".$user->Id ]; - push @data, [ Name => $user->Name ]; - push @data, [ Password => '********' ]; - push @data, [ EmailAddress => $user->EmailAddress ]; - foreach my $key (@fields) { - my $val = $user->$key; + unless ( $fields && %$fields && !exists $fields->{'password'} ) { + push @data, [ Password => '********' ]; + } - if ( (defined ($format) && $format eq 'l') || (defined $val && $val ne '')) { + for my $key (@fields) { + my $val = $user->$key; + if ( ( $fields && exists $fields->{ lc $key } ) + || ( defined $format && $format eq 'l' ) + || ( defined $val && $val ne '' ) ) + { $key = "ContactInfo" if $key eq 'FreeformContactInfo'; push @data, [ $key => $val ]; } } + # Custom fields + my $CustomFields = $user->CustomFields; + while ( my $CustomField = $CustomFields->Next() ) { + # show cf unless there are specified fields that don't include it + next + unless ( !%$fields + || exists $fields->{ lc "CF-" . $CustomField->Name } ); + next unless $CustomField->CurrentUserHasRight('SeeCustomField'); + my $CFvalues = $user->CustomFieldValues( $CustomField->Id ); + my @CFvalues; + while ( my $CFvalue = $CFvalues->Next() ) { + push @CFvalues, $CFvalue->Content; + } + push @data, [ "CF-" . $CustomField->Name => \@CFvalues ]; + } + my %k = map {@$_} @data; $o = [ map {$_->[0]} @data ]; $k = \%k; diff --git a/rt/share/html/REST/1.0/Forms/user/ns b/rt/share/html/REST/1.0/Forms/user/ns index 4c459b4a2..76f446e90 100755 --- a/rt/share/html/REST/1.0/Forms/user/ns +++ b/rt/share/html/REST/1.0/Forms/user/ns @@ -57,7 +57,7 @@ my $field = "Name"; $field = "EmailAddress" if $id =~ /\@/; my $users = RT::Users->new($session{CurrentUser}); -$users->Limit(FIELD => $field, OPERATOR => '=', VALUE => $id); +$users->Limit(FIELD => $field, OPERATOR => '=', VALUE => $id, CASESENSITIVE => 0); if ($users->Count == 0) { return (0, "No user named $id exists."); } diff --git a/rt/share/html/REST/1.0/NoAuth/mail-gateway b/rt/share/html/REST/1.0/NoAuth/mail-gateway index 43ca16578..0f70880bb 100755 --- a/rt/share/html/REST/1.0/NoAuth/mail-gateway +++ b/rt/share/html/REST/1.0/NoAuth/mail-gateway @@ -60,24 +60,24 @@ $r->content_type('text/plain; charset=utf-8'); $m->error_format('text'); my ( $status, $error, $Ticket ) = RT::Interface::Email::Gateway( \%ARGS ); if ( $status == 1 ) { - $m->out('ok'); + $m->out("ok\n"); if ( $Ticket && $Ticket->Id ) { - $m->out( 'Ticket: ' . ($Ticket->Id || '') ); - $m->out( 'Queue: ' . ($Ticket->QueueObj->Name || '') ); - $m->out( 'Owner: ' . ($Ticket->OwnerObj->Name || '') ); - $m->out( 'Status: ' . ($Ticket->Status || '') ); - $m->out( 'Subject: ' . ($Ticket->Subject || '') ); + $m->out( 'Ticket: ' . ($Ticket->Id || '') . "\n" ); + $m->out( 'Queue: ' . ($Ticket->QueueObj->Name || '') . "\n" ); + $m->out( 'Owner: ' . ($Ticket->OwnerObj->Name || '') . "\n" ); + $m->out( 'Status: ' . ($Ticket->Status || '') . "\n" ); + $m->out( 'Subject: ' . ($Ticket->Subject || '') . "\n" ); $m->out( - 'Requestor: ' . ($Ticket->Requestors->MemberEmailAddressesAsString || '') ); + 'Requestor: ' . ($Ticket->Requestors->MemberEmailAddressesAsString || '') . "\n" ); } } else { $RT::Logger->error( "Could not record email: " . $error ); if ( $status == -75 ) { - $m->out( "temporary failure - " . $error ); + $m->out( "temporary failure - $error\n" ); } else { - $m->out( 'not ok - ' . $error ); + $m->out( "not ok - $error\n" ); } } $m->abort(); diff --git a/rt/share/html/REST/1.0/dhandler b/rt/share/html/REST/1.0/dhandler index 2243376f5..ef5a354d2 100755 --- a/rt/share/html/REST/1.0/dhandler +++ b/rt/share/html/REST/1.0/dhandler @@ -100,22 +100,22 @@ if ($object eq 'show' || # $REST/show if (my ($type, $oids, $extra) = ($id =~ m#^($name)/($list|$labels)(?:(/.*))?$#o)) { - $extra ||= ''; - my ($attr, $args) = $extra =~ m{^(?:/($name)(?:/(.*))?)?$}o; - my $tids; - if ($attr and $attr eq 'history' and $args) { - ($tids) = $args =~ m#id/(\d.*)#o; - } - # expand transaction and attachment range specifications - # (if applicable) - foreach my $oid (expand_list($oids)) { - if ($tids) { - push(@objects, "$type/$oid/$attr/id/$_") for expand_list($tids); - } else { - push(@objects, "$type/$oid$extra"); - } - } - } + $extra ||= ''; + my ($attr, $args) = $extra =~ m{^(?:/($name)(?:/(.*))?)?$}o; + my $tids; + if ($attr and $attr eq 'history' and $args) { + ($tids) = $args =~ m#id/(\d.*)#o; + } + # expand transaction and attachment range specifications + # (if applicable) + foreach my $oid (expand_list($oids)) { + if ($tids) { + push(@objects, "$type/$oid/$attr/id/$_") for expand_list($tids); + } else { + push(@objects, "$type/$oid$extra"); + } + } + } else { $status = "400 Bad Request"; $output = "Invalid object ID specified: '$id'"; diff --git a/rt/share/html/REST/1.0/search/dhandler b/rt/share/html/REST/1.0/search/dhandler index b81c56c6d..d8a07291e 100755 --- a/rt/share/html/REST/1.0/search/dhandler +++ b/rt/share/html/REST/1.0/search/dhandler @@ -47,10 +47,247 @@ %# END BPS TAGGED BLOCK }}} %# REST/1.0/search/dhandler %# +<%ARGS> +$query +$format => undef +$orderby => undef +$fields => undef +</%ARGS> <%INIT> -my $status = "500 Server Error"; -my $output = "Unsupported object type."; +my $type = $m->dhandler_arg; +my ( $status, $output ); + +if ( $type =~ /^(ticket|queue|user|group)$/i ) { + $status = "200 Ok"; + $output = ''; + my $type = lc $1; + + if ( + $type eq 'user' + && !$session{CurrentUser}->HasRight( + Object => $RT::System, + Right => 'AdminUsers', + ) + ) + { + + $status = "403 Forbidden"; + $output = "Permission denied"; + goto OUTPUT; + } + + my $class = 'RT::' . ucfirst $type . 's'; + my $objects = $class->new( $session{CurrentUser} ); + + # Parse and validate any field specifications. + require RT::Interface::REST; + my $field = RT::Interface::REST->field_spec; + my ( %fields, @fields ); + if ($fields) { + $format ||= "l"; + unless ( $fields =~ /^(?:$field,)*$field$/ ) { + $status = "400 Bad Request"; + $output = "Invalid field specification: $fields"; + goto OUTPUT; + } + @fields = map lc, split /\s*,\s*/, $fields; + @fields{@fields} = (); + unless ( exists $fields{id} ) { + unshift @fields, "id"; + $fields{id} = (); + } + } + + $format ||= "s"; + if ( $format !~ /^[isl]$/ ) { + $status = "400 Bad request"; + $output = "Unknown listing format: $format. (Use i, s, or l.)\n"; + goto OUTPUT; + } + + my ( $n, $s ); + $n = 0; + my @output; + + + if ( $type eq 'group' ) { + $objects->LimitToUserDefinedGroups; + } + + if ( defined $query && length $query ) { + if ( $type eq 'ticket' ) { + my ( $n, $s ); + eval { ( $n, $s ) = $objects->FromSQL($query); }; + if ( $@ || $n == 0 ) { + $s ||= $@; + $status = "400 Bad request"; + $output = "Invalid query: '$s'.\n"; + goto OUTPUT; + } + } + else { + require Text::ParseWords; + my ( $field, $op, $value ) = Text::ParseWords::shellwords($query); + if ( $op !~ + /^(?:[!<>]?=|[<>]|(NOT )?LIKE|STARTSWITH|ENDSWITH|MATCHES)$/i ) + { + $status = "400 Bad Request"; + $output = "Invalid operator specification: $op"; + goto OUTPUT; + } + + if ( ! $search_whitelist{$type}{lc $field} ) { + $status = "400 Bad Request"; + $output = "Invalid field specification: $field"; + goto OUTPUT; + } + + + if ( $field && $op && defined $value ) { + if ( $field eq 'Disabled' ) { + if ($value) { + if ( $type eq 'queue' ) { + $objects->FindAllRows; + $objects->Limit( + FIELD => $field, + OPERATOR => uc $op, + VALUE => $value + ); + } + else { + $objects->LimitToDeleted; + } + } + else { + if ( $type eq 'queue' ) { + $objects->UnLimit; + } + else { + $objects->LimitToEnabled; + } + } + } + else { + $objects->Limit( + FIELD => $field, + OPERATOR => uc $op, + VALUE => $value, + CASESENSITIVE => 0, + ); + } + } + else { + $output = "Invalid query specification: $query"; + goto OUTPUT; + } + } + } + else { + if ( $type eq 'queue' ) { + $objects->UnLimit; + } + elsif ( $type eq 'user' ) { + $objects->LimitToPrivileged; + } + } + + if ($orderby) { + my ( $order, $field ) = $orderby =~ /^([\+\-])?(.+)/; + $order = $order && $order eq '-' ? 'DESC' : 'ASC'; + $objects->OrderBy( FIELD => $field, ORDER => $order ); + } + + while ( my $object = $objects->Next ) { + next if $type eq 'user' && ( $object->id == RT->SystemUser->id || $object->id == RT->Nobody->id ); + $n++; + + my $id = $object->Id; + if ( $format eq "i" ) { + $output .= "$type/" . $id . "\n"; + } + elsif ( $format eq "s" ) { + if ($fields) { + my $result = $m->comp( + "/REST/1.0/Forms/$type/default", + id => $id, + format => $format, + fields => \%fields + ); + my ( $notes, $order, $key_values, $errors ) = @$result; + + # If it's the first time through, add our header + if ( $n == 1 ) { + $output .= join( "\t", @$order ) . "\n"; + } + + # Cut off the annoying $type/ before the id; + $key_values->{'id'} = $id; + $output .= join( + "\t", + map { + ref $key_values->{$_} eq 'ARRAY' + ? join( ', ', @{ $key_values->{$_} } ) + : $key_values->{$_} + } @$order + ) . "\n"; + } + else { + if ( $type eq 'ticket' ) { + $output .= $object->Id . ": " . $object->Subject . "\n"; + } + else { + $output .= $object->Id . ": " . $object->Name . "\n"; + } + } + } + else { + my $d = $m->comp( + "/REST/1.0/Forms/$type/default", + id => $id, + format => $format, + fields => \%fields + ); + my ( $c, $o, $k, $e ) = @$d; + push @output, [ $c, $o, $k ]; + } + } + if ( $n == 0 && $format ne "i" ) { + $output = "No matching results.\n"; + } + + $output = form_compose( \@output ) if @output; +} +else { + $status = "500 Server Error"; + $output = "Unsupported object type."; + goto OUTPUT; +} + +OUTPUT: +$m->out("RT/". $RT::VERSION . " " . $status ."\n\n"); +$m->out($output ); </%INIT> -RT/<% $RT::VERSION %> <% $status %> -<% $output |n %> +<%ONCE> +my %search_whitelist = ( + queue => { + map { lc $_ => 1 } + grep { $RT::Record::_TABLE_ATTR->{'RT::Queue'}{$_}{read} } + keys %{ $RT::Record::_TABLE_ATTR->{'RT::Queue'} } + }, + user => { + disabled => 1, + map { lc $_ => 1 } + grep { $RT::Record::_TABLE_ATTR->{'RT::User'}{$_}{read} } + keys %{ $RT::Record::_TABLE_ATTR->{'RT::User'} } + }, + group => { + disabled => 1, + map { lc $_ => 1 } + grep { $RT::Record::_TABLE_ATTR->{'RT::Group'}{$_}{read} } + keys %{ $RT::Record::_TABLE_ATTR->{'RT::Group'} } + } +); + +</%ONCE> + diff --git a/rt/share/html/REST/1.0/search/ticket b/rt/share/html/REST/1.0/search/ticket deleted file mode 100755 index f022b0330..000000000 --- a/rt/share/html/REST/1.0/search/ticket +++ /dev/null @@ -1,165 +0,0 @@ -%# BEGIN BPS TAGGED BLOCK {{{ -%# -%# COPYRIGHT: -%# -%# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC -%# <sales@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/licenses/old-licenses/gpl-2.0.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/search/ticket -%# -<%ARGS> -$query -$format => undef -$orderby => undef -$fields => undef -</%ARGS> -<%INIT> -use RT::Interface::REST; -my $output = ""; -my $status = "200 Ok"; -my $tickets = RT::Tickets->new($session{CurrentUser}); - -# Parse and validate any field specifications. -my $field = RT::Interface::REST->field_spec; -my (%fields, @fields); -if ($fields) { - $format ||= "l"; - unless ($fields =~ /^(?:$field,)*$field$/) { - $status = "400 Bad Request"; - $output = "Invalid field specification: $fields"; - goto OUTPUT; - } - @fields = map lc, split /\s*,\s*/, $fields; - @fields{@fields} = (); - unless (exists $fields{id}) { - unshift @fields, "id"; - $fields{id} = (); - } -} - -$format ||= "s"; -if ($format !~ /^[isl]$/) { - $status = "400 Bad request"; - $output = "Unknown listing format: $format. (Use i, s, or l.)\n"; - goto OUTPUT; -} - -my ($n, $s); -eval { - ($n, $s) = $tickets->FromSQL($query); -}; - -if ($orderby) { - my %args; - - my $order = substr($orderby, 0, 1); - if ($order eq '+' || $order eq '-') { - # remove the +/- sorting sigil - substr($orderby, 0, 1, ''); - - if ($order eq '+') { - $args{ORDER} = 'ASC'; - } - elsif ($order eq '-') { - $args{ORDER} = 'DESC'; - } - } - - $tickets->OrderBy( - FIELD => $orderby, - %args, - ); -} - -if ($@ || $n == 0) { - $s ||= $@; - $status = "400 Bad request"; - $output = "Invalid query: '$s'.\n"; - goto OUTPUT; -} - -$n = 0; -my @output; -while (my $ticket = $tickets->Next) { - $n++; - - my $id = $ticket->Id; - if ($format eq "i") { - $output .= "ticket/" . $id . "\n"; - } - elsif ($format eq "s") { - if ($fields) { - my $result = $m->comp("/REST/1.0/Forms/ticket/default", id => $id, format => $format, fields => \%fields); - my ($notes, $order, $key_values, $errors) = @$result; - # If it's the first time through, add our header - if ($n == 1) { - $output .= join("\t",@$order)."\n"; - } - # Cut off the annoying ticket/ before the id; - $key_values->{'id'} = $id; - $output .= join("\t", map { ref $key_values->{$_} eq 'ARRAY' ? -join( ', ', @{$key_values->{$_}} ) : $key_values->{$_} } @$order)."\n"; - - - } else { - $output .= $ticket->Id . ": ". $ticket->Subject . "\n"; - } - } - else { - my $d = $m->comp("/REST/1.0/Forms/ticket/default", id => $id, format => $format, fields => \%fields); - my ($c, $o, $k, $e) = @$d; - push @output, [ $c, $o, $k ]; - } -} -if ($n == 0 && $format ne "i") { - $output = "No matching results.\n"; -} - -$output = form_compose(\@output) if @output; - -OUTPUT: -$m->out("RT/". $RT::VERSION . " " . $status ."\n\n"); - -$m->out($output ); -return(); -</%INIT> |