summaryrefslogtreecommitdiffstats
path: root/extensions/BzAPI/lib/Resources/User.pm
diff options
context:
space:
mode:
authorDavid Lawrence <dkl@redhat.com>2014-06-16 17:15:35 +0200
committerDavid Lawrence <dkl@redhat.com>2014-06-16 17:15:35 +0200
commit0a2592d00b9d230f78b69c5808cbca108af54967 (patch)
tree6a0d72b2433b75c2ef8879ec23ff1ff507eb6165 /extensions/BzAPI/lib/Resources/User.pm
parentdd10df6857319589e15cc404ad8690cdf54a6768 (diff)
downloadbugzilla-0a2592d00b9d230f78b69c5808cbca108af54967.tar.gz
bugzilla-0a2592d00b9d230f78b69c5808cbca108af54967.tar.xz
Bug 880669 - Extend current BzAPI BMO extension to contain compatibility changes on top of native rest
r=glob
Diffstat (limited to 'extensions/BzAPI/lib/Resources/User.pm')
-rw-r--r--extensions/BzAPI/lib/Resources/User.pm79
1 files changed, 79 insertions, 0 deletions
diff --git a/extensions/BzAPI/lib/Resources/User.pm b/extensions/BzAPI/lib/Resources/User.pm
new file mode 100644
index 000000000..7fbcdb871
--- /dev/null
+++ b/extensions/BzAPI/lib/Resources/User.pm
@@ -0,0 +1,79 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+package Bugzilla::Extension::BzAPI::Resources::User;
+
+use 5.10.1;
+use strict;
+
+use Bugzilla::Extension::BzAPI::Util;
+
+sub rest_handlers {
+ my $rest_handlers = [
+ qr{/user$}, {
+ GET => {
+ response => \&get_users,
+ },
+ },
+ qr{/user/([^/]+)$}, {
+ GET => {
+ response => \&get_user,
+ },
+ }
+ ];
+ return $rest_handlers;
+}
+
+sub get_users {
+ my ($result) = @_;
+ my $rpc = Bugzilla->request_cache->{bzapi_rpc};
+ my $params = Bugzilla->input_params;
+
+ return if !exists $$result->{users};
+
+ my @users;
+ foreach my $user (@{$$result->{users}}) {
+ my $object = Bugzilla::User->new(
+ { id => $user->{id}, cache => 1 });
+
+ $user = fix_user($user, $object);
+
+ # Use userid instead of email for 'ref' for /user calls
+ $user->{'ref'} = $rpc->type('string', ref_urlbase . "/user/" . $object->id);
+
+ # Emails are not filtered even if user is not logged in
+ $user->{name} = $rpc->type('string', $object->login);
+
+ push(@users, filter($params, $user));
+ }
+
+ $$result->{users} = \@users;
+}
+
+sub get_user {
+ my ($result) = @_;
+ my $rpc = Bugzilla->request_cache->{bzapi_rpc};
+ my $params = Bugzilla->input_params;
+
+ return if !exists $$result->{users};
+ my $user = $$result->{users}->[0] || return;
+ my $object = Bugzilla::User->new({ id => $user->{id}, cache => 1 });
+
+ $user = fix_user($user, $object);
+
+ # Use userid instead of email for 'ref' for /user calls
+ $user->{'ref'} = $rpc->type('string', ref_urlbase . "/user/" . $object->id);
+
+ # Emails are not filtered even if user is not logged in
+ $user->{name} = $rpc->type('string', $object->login);
+
+ $user = filter($params, $user);
+
+ $$result = $user;
+}
+
+1;