[Rt-commit] rt branch, 4.2/rest-show-user-cf, created. rt-4.2.1-55-gd9dcc59
? sunnavy
sunnavy at bestpractical.com
Sun Dec 8 06:16:10 EST 2013
The branch, 4.2/rest-show-user-cf has been created
at d9dcc5962ca0d384871c70f695860efb460ee7b5 (commit)
- Log -----------------------------------------------------------------
commit e4ef107df36778970d75d3201e04ae05be2933ca
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed Jul 6 18:25:48 2011 +0800
restful support to show user cf
e.g. `bin/rt show user/12`
it's actually a code clone from restful queues and groups
diff --git a/share/html/REST/1.0/Forms/user/default b/share/html/REST/1.0/Forms/user/default
index c942132..676951b 100644
--- a/share/html/REST/1.0/Forms/user/default
+++ b/share/html/REST/1.0/Forms/user/default
@@ -141,6 +141,22 @@ if (keys %data == 0) {
}
}
+ # 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;
commit d9dcc5962ca0d384871c70f695860efb460ee7b5
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sun Dec 8 19:03:34 2013 +0800
restful user cf test
diff --git a/t/web/rest_user_cf.t b/t/web/rest_user_cf.t
new file mode 100644
index 0000000..d9f4ea3
--- /dev/null
+++ b/t/web/rest_user_cf.t
@@ -0,0 +1,26 @@
+use strict;
+use warnings;
+use RT::Interface::REST;
+
+use RT::Test tests => undef;
+
+my ( $baseurl, $m ) = RT::Test->started_ok;
+
+my $cf = RT::Test->load_or_create_custom_field(
+ Name => 'foo',
+ Type => 'Freeform',
+ LookupType => 'RT::User',
+);
+$cf->AddToObject(RT::User->new(RT->SystemUser));
+
+my $root = RT::User->new( RT->SystemUser );
+$root->Load('root');
+$root->AddCustomFieldValue( Field => 'foo', Value => 'blabla' );
+is( $root->FirstCustomFieldValue('foo'), 'blabla', 'cf is set' );
+
+ok( $m->login, 'logged in' );
+$m->post( "$baseurl/REST/1.0/show", [ id => 'user/12', ] );
+like( $m->content, qr/CF-foo: blabla/, 'found the cf' );
+
+undef $m;
+done_testing;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list