summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2014-02-06 07:44:21 +0100
committerByron Jones <bjones@mozilla.com>2014-02-06 07:44:21 +0100
commita03987f1d0d7fe615b0c632cf2079b4c0a791a4a (patch)
tree1ebc84df86f365bb10e1ca9e4d0cbe714f76d803 /Bugzilla
parente944ebab1ef01993751c75d5fd25ec6b590cb858 (diff)
downloadbugzilla-a03987f1d0d7fe615b0c632cf2079b4c0a791a4a.tar.gz
bugzilla-a03987f1d0d7fe615b0c632cf2079b4c0a791a4a.tar.xz
Bug 967607: User.get shouldn't load data that requires extra database queries unless required
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/WebService/User.pm64
1 files changed, 36 insertions, 28 deletions
diff --git a/Bugzilla/WebService/User.pm b/Bugzilla/WebService/User.pm
index 7aa1a626b..c84d2e07b 100644
--- a/Bugzilla/WebService/User.pm
+++ b/Bugzilla/WebService/User.pm
@@ -28,7 +28,7 @@ use Bugzilla::Error;
use Bugzilla::Group;
use Bugzilla::User;
use Bugzilla::Util qw(trim);
-use Bugzilla::WebService::Util qw(filter validate);
+use Bugzilla::WebService::Util qw(filter filter_wants validate);
use Bugzilla::Hook;
use List::Util qw(first);
@@ -224,33 +224,41 @@ sub get {
}
}
- my $in_group = $self->_filter_users_by_group(
- \@user_objects, $params);
- if (Bugzilla->user->in_group('editusers')) {
- @users =
- map {filter $params, {
- id => $self->type('int', $_->id),
- real_name => $self->type('string', $_->name),
- name => $self->type('email', $_->login),
- email => $self->type('email', $_->email),
- can_login => $self->type('boolean', $_->is_enabled ? 1 : 0),
- groups => $self->_filter_bless_groups($_->groups),
- email_enabled => $self->type('boolean', $_->email_enabled),
- login_denied_text => $self->type('string', $_->disabledtext),
- saved_searches => [map { $self->_query_to_hash($_) } @{ $_->queries }],
- }} @$in_group;
- }
- else {
- @users =
- map {filter $params, {
- id => $self->type('int', $_->id),
- real_name => $self->type('string', $_->name),
- name => $self->type('email', $_->login),
- email => $self->type('email', $_->email),
- can_login => $self->type('boolean', $_->is_enabled ? 1 : 0),
- groups => $self->_filter_bless_groups($_->groups),
- saved_searches => [map { $self->_query_to_hash($_) } @{ $_->queries }],
- }} @$in_group;
+ my $in_group = $self->_filter_users_by_group(\@user_objects, $params);
+ foreach my $user (@$in_group) {
+ my $user_info = {
+ id => $self->type('int', $user->id),
+ real_name => $self->type('string', $user->name),
+ name => $self->type('email', $user->login),
+ email => $self->type('email', $user->email),
+ can_login => $self->type('boolean', $user->is_enabled ? 1 : 0),
+ };
+
+ if (Bugzilla->user->in_group('editusers')) {
+ $user_info->{email_enabled} = $self->type('boolean', $user->email_enabled);
+ $user_info->{login_denied_text} = $self->type('string', $user->disabledtext);
+ }
+
+ if (Bugzilla->user->id == $user->id) {
+ if (filter_wants($params, 'saved_searches')) {
+ $user_info->{saved_searches} = [
+ map { $self->_query_to_hash($_) } @{ $user->queries }
+ ];
+ }
+ }
+
+ if (filter_wants($params, 'groups')) {
+ if (Bugzilla->user->id == $user->id || Bugzilla->user->in_group('editusers')) {
+ $user_info->{groups} = [
+ map { $self->_group_to_hash($_) } @{ $user->groups }
+ ];
+ }
+ else {
+ $user_info->{groups} = $self->_filter_bless_groups($user->groups);
+ }
+ }
+
+ push(@users, filter($params, $user_info));
}
Bugzilla::Hook::process('webservice_user_get',