summaryrefslogtreecommitdiff
path: root/rt/share/html/REST/1.0/Forms
diff options
context:
space:
mode:
Diffstat (limited to 'rt/share/html/REST/1.0/Forms')
-rw-r--r--rt/share/html/REST/1.0/Forms/group/default49
-rw-r--r--rt/share/html/REST/1.0/Forms/group/ns2
-rwxr-xr-xrt/share/html/REST/1.0/Forms/queue/default9
-rwxr-xr-xrt/share/html/REST/1.0/Forms/queue/ns2
-rwxr-xr-xrt/share/html/REST/1.0/Forms/ticket/attachments32
-rwxr-xr-xrt/share/html/REST/1.0/Forms/ticket/default105
-rwxr-xr-xrt/share/html/REST/1.0/Forms/ticket/history96
-rw-r--r--rt/share/html/REST/1.0/Forms/transaction/default109
-rwxr-xr-xrt/share/html/REST/1.0/Forms/user/default49
-rwxr-xr-xrt/share/html/REST/1.0/Forms/user/ns2
10 files changed, 232 insertions, 223 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.");
}