[Rt-commit] rt branch, 4.2/user-info-via-ajax, created. rt-4.1.5-11-gf8b4436

Thomas Sibley trs at bestpractical.com
Mon Dec 10 16:37:59 EST 2012


The branch, 4.2/user-info-via-ajax has been created
        at  f8b443684ac0653960bc7d83cbf4956cb0e4136a (commit)

- Log -----------------------------------------------------------------
commit f8b443684ac0653960bc7d83cbf4956cb0e4136a
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Dec 10 13:33:14 2012 -0800

    Add an AJAX endpoint for requesting basic user information
    
    Javascript which may want to display a formatted user now has a way to
    fetch the preferred format, as well as retrieve user details.

diff --git a/share/html/Helpers/UserInfo b/share/html/Helpers/UserInfo
new file mode 100644
index 0000000..046ac8b
--- /dev/null
+++ b/share/html/Helpers/UserInfo
@@ -0,0 +1,29 @@
+<%args>
+$id
+</%args>
+<%init>
+my %users;
+
+$id = [$id] unless ref($id) eq 'ARRAY';
+
+for my $uid (@$id) {
+    next if exists $users{$uid};
+
+    my $user = RT::User->new($session{'CurrentUser'});
+    $user->Load($uid);
+
+    unless ($user->id) {
+        $users{$uid} = undef;
+        next;
+    }
+
+    my %user = map { $_ => $user->$_ }
+                   qw(id Name EmailAddress RealName);
+    $user{Privileged} = $user->Privileged ? JSON::true : JSON::false;
+    $user{_formatted} = $m->scomp('/Elements/ShowUser', User => $user, NoEscape => 1);
+    $users{$uid} = \%user;
+}
+$r->content_type('application/json; charset=utf-8');
+$m->out( JSON(\%users) );
+$m->abort;
+</%init>

-----------------------------------------------------------------------


More information about the Rt-commit mailing list