User.pm 26.2 KB
Newer Older
1 2 3
# 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/.
4
#
5 6
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
7 8 9

package Bugzilla::WebService::User;

10
use 5.10.1;
11
use strict;
12

13
use parent qw(Bugzilla::WebService);
14

15
use Bugzilla::Constants;
16
use Bugzilla::Error;
17
use Bugzilla::Group;
18
use Bugzilla::User;
19
use Bugzilla::Util qw(trim detaint_natural);
20
use Bugzilla::WebService::Util qw(filter filter_wants validate translate params_to_objects);
21

22
use List::Util qw(first min);
23

24 25 26 27 28 29
# Don't need auth to login
use constant LOGIN_EXEMPT => {
    login => 1,
    offer_account_by_email => 1,
};

30 31 32 33
use constant READ_ONLY => qw(
    get
);

34 35 36 37 38 39 40 41 42 43 44 45 46 47
use constant MAPPED_FIELDS => {
    email => 'login',
    full_name => 'name',
    login_denied_text => 'disabledtext',
    email_enabled => 'disable_mail'
};

use constant MAPPED_RETURNS => {
    login_name => 'email',
    realname => 'full_name',
    disabledtext => 'login_denied_text',
    disable_mail => 'email_enabled'
};

48 49 50
##############
# User Login #
##############
51 52

sub login {
53
    my ($self, $params) = @_;
54 55 56

    # Username and password params are required 
    foreach my $param ("login", "password") {
57
        defined $params->{$param} 
58 59 60
            || ThrowCodeError('param_required', { param => $param });
    }

61 62 63 64 65 66
    # Make sure the CGI user info class works if necessary.
    my $input_params = Bugzilla->input_params;
    $input_params->{'Bugzilla_login'} =  $params->{login};
    $input_params->{'Bugzilla_password'} = $params->{password};
    $input_params->{'Bugzilla_restrictlogin'} = $params->{restrict_login};

67 68 69 70
    my $user = Bugzilla->login();

    my $result = { id => $self->type('int', $user->id) };

71 72
    if ($user->{_login_token}) {
        $result->{'token'} = $user->id . "-" . $user->{_login_token};
73 74 75
    }

    return $result;
76 77 78 79 80 81 82
}

sub logout {
    my $self = shift;
    Bugzilla->logout;
}

83 84 85 86 87 88 89 90 91 92 93
sub valid_login {
    my ($self, $params) = @_;
    defined $params->{login}
        || ThrowCodeError('param_required', { param => 'login' });
    Bugzilla->login();
    if (Bugzilla->user->id && Bugzilla->user->login eq $params->{login}) {
        return $self->type('boolean', 1);
    }
    return $self->type('boolean', 0);
}

94 95 96 97 98 99 100 101 102 103
#################
# User Creation #
#################

sub offer_account_by_email {
    my $self = shift;
    my ($params) = @_;
    my $email = trim($params->{email})
        || ThrowCodeError('param_required', { param => 'email' });

104 105
    Bugzilla->user->check_account_creation_enabled;
    Bugzilla->user->check_and_send_account_creation_confirmation($email);
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    return undef;
}

sub create {
    my $self = shift;
    my ($params) = @_;

    Bugzilla->user->in_group('editusers') 
        || ThrowUserError("auth_failure", { group  => "editusers",
                                            action => "add",
                                            object => "users"});

    my $email = trim($params->{email})
        || ThrowCodeError('param_required', { param => 'email' });
    my $realname = trim($params->{full_name});
    my $password = trim($params->{password}) || '*';

    my $user = Bugzilla::User->create({
        login_name    => $email,
        realname      => $realname,
        cryptpassword => $password
    });

129
    return { id => $self->type('int', $user->id) };
130 131
}

132 133 134 135 136 137

# function to return user information by passing either user ids or 
# login names or both together:
# $call = $rpc->call( 'User.get', { ids => [1,2,3], 
#         names => ['testusera@redhat.com', 'testuserb@redhat.com'] });
sub get {
138
    my ($self, $params) = validate(@_, 'names', 'ids', 'match', 'group_ids', 'groups');
139

140 141
    Bugzilla->switch_to_shadow_db();

142 143 144 145 146
    defined($params->{names}) || defined($params->{ids})
        || defined($params->{match})
        || ThrowCodeError('params_required', 
               { function => 'User.get', params => ['ids', 'names', 'match'] });

147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
    my @user_objects;
    @user_objects = map { Bugzilla::User->check($_) } @{ $params->{names} }
                    if $params->{names};

    # start filtering to remove duplicate user ids
    my %unique_users = map { $_->id => $_ } @user_objects;
    @user_objects = values %unique_users;
      
    my @users;

    # If the user is not logged in: Return an error if they passed any user ids.
    # Otherwise, return a limited amount of information based on login names.
    if (!Bugzilla->user->id){
        if ($params->{ids}){
            ThrowUserError("user_access_by_id_denied");
        }
163 164 165
        if ($params->{match}) {
            ThrowUserError('user_access_by_match_denied');
        }
166 167
        my $in_group = $self->_filter_users_by_group(
            \@user_objects, $params);
168
        @users = map { filter $params, {
169
                     id        => $self->type('int', $_->id),
170 171
                     real_name => $self->type('string', $_->name),
                     name      => $self->type('email', $_->login),
172
                 } } @$in_group;
173 174 175 176 177 178 179

        return { users => \@users };
    }

    my $obj_by_ids;
    $obj_by_ids = Bugzilla::User->new_from_list($params->{ids}) if $params->{ids};

180
    # obj_by_ids are only visible to the user if they can see
181
    # the otheruser, for non visible otheruser throw an error
182
    foreach my $obj (@$obj_by_ids) {
183
        if (Bugzilla->user->can_see_user($obj)){
184 185 186 187
            if (!$unique_users{$obj->id}) {
                push (@user_objects, $obj);
                $unique_users{$obj->id} = $obj;
            }
188 189 190 191 192 193 194 195
        }
        else {
            ThrowUserError('auth_failure', {reason => "not_visible",
                                            action => "access",
                                            object => "user",
                                            userid => $obj->id});
        }
    }
196

197
    # User Matching
198 199 200 201 202 203 204
    my $limit = Bugzilla->params->{maxusermatches};
    if ($params->{limit}) {
        detaint_natural($params->{limit})
            || ThrowCodeError('param_must_be_numeric',
                              { function => 'Bugzilla::WebService::User::match',
                                param    => 'limit' });
        $limit = $limit ? min($params->{limit}, $limit) : $params->{limit};
205
    }
206

207
    my $exclude_disabled = $params->{'include_disabled'} ? 0 : 1;
208
    foreach my $match_string (@{ $params->{'match'} || [] }) {
209
        my $matched = Bugzilla::User::match($match_string, $limit, $exclude_disabled);
210 211 212 213 214 215 216
        foreach my $user (@$matched) {
            if (!$unique_users{$user->id}) {
                push(@user_objects, $user);
                $unique_users{$user->id} = $user;
            }
        }
    }
217

218
    my $in_group = $self->_filter_users_by_group(\@user_objects, $params);
219
    foreach my $user (@$in_group) {
220
        my $user_info = filter $params, {
221 222
            id        => $self->type('int', $user->id),
            real_name => $self->type('string', $user->name),
223 224
            name      => $self->type('email', $user->login),
            email     => $self->type('email', $user->email),
225 226
            can_login => $self->type('boolean', $user->is_enabled ? 1 : 0),
        };
227

228 229 230 231
        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);
        }
232

233
        if (Bugzilla->user->id == $user->id) {
234 235 236 237 238 239 240 241 242 243
            if (filter_wants($params, 'saved_searches')) {
                $user_info->{saved_searches} = [
                    map { $self->_query_to_hash($_) } @{ $user->queries }
                ];
            }
            if (filter_wants($params, 'saved_reports')) {
                $user_info->{saved_reports}  = [
                    map { $self->_report_to_hash($_) } @{ $user->reports }
                ];
            }
244
        }
245

246 247 248 249 250 251 252 253 254
        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);
            }
255 256
        }

257
        push(@users, $user_info);
Frédéric Buclin's avatar
Frédéric Buclin committed
258
    }
259 260 261 262

    return { users => \@users };
}

263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
###############
# User Update #
###############

sub update {
    my ($self, $params) = @_;

    my $dbh = Bugzilla->dbh;

    my $user = Bugzilla->login(LOGIN_REQUIRED);

    # Reject access if there is no sense in continuing.
    $user->in_group('editusers')
        || ThrowUserError("auth_failure", {group  => "editusers",
                                           action => "edit",
                                           object => "users"});

    defined($params->{names}) || defined($params->{ids})
        || ThrowCodeError('params_required', 
               { function => 'User.update', params => ['ids', 'names'] });

    my $user_objects = params_to_objects($params, 'Bugzilla::User');

    my $values = translate($params, MAPPED_FIELDS);

    # We delete names and ids to keep only new values to set.
    delete $values->{names};
    delete $values->{ids};

    $dbh->bz_start_transaction();
    foreach my $user (@$user_objects){
        $user->set_all($values);
    }

    my %changes;
    foreach my $user (@$user_objects){
        my $returned_changes = $user->update();
        $changes{$user->id} = translate($returned_changes, MAPPED_RETURNS);    
    }
    $dbh->bz_commit_transaction();

    my @result;
    foreach my $user (@$user_objects) {
        my %hash = (
            id      => $user->id,
            changes => {},
        );

        foreach my $field (keys %{ $changes{$user->id} }) {
            my $change = $changes{$user->id}->{$field};
            # We normalize undef to an empty string, so that the API
            # stays consistent for things that can become empty.
            $change->[0] = '' if !defined $change->[0];
            $change->[1] = '' if !defined $change->[1];
            $hash{changes}{$field} = {
                removed => $self->type('string', $change->[0]),
                added   => $self->type('string', $change->[1]) 
            };
        }

        push(@result, \%hash);
    }

    return { users => \@result };
}

329 330 331 332 333 334 335
sub _filter_users_by_group {
    my ($self, $users, $params) = @_;
    my ($group_ids, $group_names) = @$params{qw(group_ids groups)};

    # If no groups are specified, we return all users.
    return $users if (!$group_ids and !$group_names);

336 337 338 339 340 341 342 343 344 345 346 347 348
    my $user = Bugzilla->user;
    my (@groups, %groups);

    if ($group_ids) {
        @groups = map { Bugzilla::Group->check({ id => $_ }) } @$group_ids;
        $groups{$_->id} = $_ foreach @groups;
    }
    if ($group_names) {
        foreach my $name (@$group_names) {
            my $group = Bugzilla::Group->check({ name => $name, _error => 'invalid_group_name' });
            $user->in_group($group) || ThrowUserError('invalid_group_name', { name => $name });
            $groups{$group->id} = $group;
        }
349
    }
350
    @groups = values %groups;
351

352
    my @in_group = grep { $self->_user_in_any_group($_, \@groups) } @$users;
353 354 355 356 357 358 359 360 361 362 363
    return \@in_group;
}

sub _user_in_any_group {
    my ($self, $user, $groups) = @_;
    foreach my $group (@$groups) {
        return 1 if $user->in_group($group);
    }
    return 0;
}

364 365 366 367 368 369
sub _filter_bless_groups {
    my ($self, $groups) = @_;
    my $user = Bugzilla->user;

    my @filtered_groups;
    foreach my $group (@$groups) {
370
        next unless $user->can_bless($group->id);
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
        push(@filtered_groups, $self->_group_to_hash($group));
    }

    return \@filtered_groups;
}

sub _group_to_hash {
    my ($self, $group) = @_;
    my $item = {
        id          => $self->type('int', $group->id), 
        name        => $self->type('string', $group->name), 
        description => $self->type('string', $group->description), 
    };
    return $item;
}

387 388 389
sub _query_to_hash {
    my ($self, $query) = @_;
    my $item = {
390 391 392
        id    => $self->type('int', $query->id),
        name  => $self->type('string', $query->name),
        query => $self->type('string', $query->url),
393
    };
394 395
    return $item;
}
396

397 398 399 400 401 402 403
sub _report_to_hash {
    my ($self, $report) = @_;
    my $item = {
        id    => $self->type('int', $report->id),
        name  => $self->type('string', $report->name),
        query => $self->type('string', $report->query),
    };
404 405 406
    return $item;
}

407
1;
408 409 410 411 412 413 414 415 416

__END__

=head1 NAME

Bugzilla::Webservice::User - The User Account and Login API

=head1 DESCRIPTION

417 418
This part of the Bugzilla API allows you to create User Accounts and
log in/out using an existing account.
419 420 421

=head1 METHODS

422 423
See L<Bugzilla::WebService> for a description of how parameters are passed,
and what B<STABLE>, B<UNSTABLE>, and B<EXPERIMENTAL> mean.
424

425 426 427 428
Although the data input and output is the same for JSONRPC, XMLRPC and REST,
the directions for how to access the data via REST is noted in each method
where applicable.

429
=head1 Logging In and Out
430

431
=head2 login
432 433

B<STABLE>
434 435 436 437 438 439 440 441 442 443 444 445 446

=over

=item B<Description>

Logging in, with a username and password, is required for many
Bugzilla installations, in order to search for bugs, post new bugs,
etc. This method logs in an user.

=item B<Params>

=over

447
=item C<login> (string) - The user's login name.
448 449 450

=item C<password> (string) - The user's password.

451 452 453
=item C<restrict_login> (bool) B<Optional> - If set to a true value,
the token returned by this method will only be valid from the IP address
which called this method.
454 455 456 457 458

=back

=item B<Returns>

459 460
On success, a hash containing two items, C<id>, the numeric id of the
user that was logged in, and a C<token> which can be passed in
461
the parameters as authentication in other calls. The token can be sent
462
along with any future requests to the webservice, for the duration of the
463
session, i.e. till L<User.logout|/logout> is called.
464 465 466 467 468 469 470 471 472

=item B<Errors>

=over

=item 300 (Invalid Username or Password)

The username does not exist, or the password is wrong.

473
=item 301 (Login Disabled)
474

475 476
The ability to login with this account has been disabled.  A reason may be
specified with the error.
477

478 479 480
=item 305 (New Password Required)

The current password is correct, but the user is asked to change
481
their password.
482

483 484 485 486
=item 50 (Param Required)

A login or password parameter was not provided.

487 488
=back

489 490 491 492 493 494 495 496 497 498 499 500 501
=item B<History>

=over

=item C<remember> was removed in Bugzilla B<5.0> as this method no longer
creates a login cookie.

=item C<restrict_login> was added in Bugzilla B<5.0>.

=item C<token> was added in Bugzilla B<5.0>.

=back

502 503
=back

504
=head2 logout
505 506

B<STABLE>
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521

=over

=item B<Description>

Log out the user. Does nothing if there is no user logged in.

=item B<Params> (none)

=item B<Returns> (nothing)

=item B<Errors> (none)

=back

522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
=head2 valid_login

B<UNSTABLE>

=over

=item B<Description>

This method will verify whether a client's cookies or current login
token is still valid or have expired. A valid username must be provided
as well that matches.

=item B<Params>

=over

=item C<login>

The login name that matches the provided cookies or token.

=item C<token>

(string) Persistent login token current being used for authentication (optional).
Cookies passed by client will be used before the token if both provided.

=back

=item B<Returns>

Returns true/false depending on if the current cookies or token are valid
for the provided username.

=item B<Errors> (none)

=item B<History>

=over

=item Added in Bugzilla B<5.0>.

=back

=back

566
=head1 Account Creation and Modification
567

568
=head2 offer_account_by_email
569 570

B<STABLE>
571

572 573 574
=over

=item B<Description>
575

576 577 578
Sends an email to the user, offering to create an account.  The user
will have to click on a URL in the email, and choose their password
and real name.
579

580 581 582 583 584 585 586 587 588 589 590 591 592
This is the recommended way to create a Bugzilla account.

=item B<Param>

=over

=item C<email> (string) - the email to send the offer to.

=back

=item B<Returns> (nothing)

=item B<Errors>
593 594 595

=over

596
=item 500 (Account Already Exists)
597

598
An account with that email address already exists in Bugzilla.
599

600
=item 501 (Illegal Email Address)
601

602 603
This Bugzilla does not allow you to create accounts with the format of
email address you specified. Account creation may be entirely disabled.
604 605 606

=back

607 608
=back

609
=head2 create
610

611
B<STABLE>
612

613 614 615 616 617 618 619 620 621
=over

=item B<Description>

Creates a user account directly in Bugzilla, password and all.
Instead of this, you should use L</offer_account_by_email> when
possible, because that makes sure that the email address specified can
actually receive an email. This function does not check that.

622 623 624
You must be logged in and have the C<editusers> privilege in order to
call this function.

625 626
=item B<REST>

627
POST /rest/user
628 629 630 631

The params to include in the POST body as well as the returned data format,
are the same as below.

632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
=item B<Params>

=over

=item C<email> (string) - The email address for the new user.

=item C<full_name> (string) B<Optional> - The user's full name. Will
be set to empty if not specified.

=item C<password> (string) B<Optional> - The password for the new user
account, in plain text.  It will be stripped of leading and trailing
whitespace.  If blank or not specified, the newly created account will
exist in Bugzilla, but will not be allowed to log in using DB
authentication until a password is set either by the user (through
resetting their password) or by the administrator.

=back

=item B<Returns>

A hash containing one item, C<id>, the numeric id of the user that was
created.

=item B<Errors>

The same as L</offer_account_by_email>. If a password is specified,
the function may also throw:
659 660 661 662 663 664 665 666

=over

=item 502 (Password Too Short)

The password specified is too short. (Usually, this means the
password is under three characters.)

667 668 669 670 671
=back

=item B<History>

=over
672

673
=item Error 503 (Password Too Long) removed in Bugzilla B<3.6>.
674

675 676
=item REST API call added in Bugzilla B<5.0>.

677 678 679
=back

=back
680

681 682 683 684 685 686 687 688 689 690
=head2 update 

B<EXPERIMENTAL>

=over

=item B<Description>

Updates user accounts in Bugzilla.

691 692
=item B<REST>

693
PUT /rest/user/<user_id_or_name>
694 695 696 697 698

The params to include in the PUT body as well as the returned data format,
are the same as below. The C<ids> and C<names> params are overridden as they
are pulled from the URL path.

699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
=item B<Params>

=over

=item C<ids>

C<array> Contains ids of user to update.

=item C<names>

C<array> Contains email/login of user to update.

=item C<full_name>

C<string> The new name of the user.

=item C<email>

C<string> The email of the user. Note that email used to login to bugzilla.
Also note that you can only update one user at a time when changing the 
login name / email. (An error will be thrown if you try to update this field 
for multiple users at once.)

=item C<password>

C<string> The password of the user.

=item C<email_enabled>

C<boolean> A boolean value to enable/disable sending bug-related mail to the user.

=item C<login_denied_text>

C<string> A text field that holds the reason for disabling a user from logging
into bugzilla, if empty then the user account is enabled otherwise it is
disabled/closed.

=back

=item B<Returns>

A C<hash> with a single field "users". This points to an array of hashes
with the following fields:

=over

=item C<id>

C<int> The id of the user that was updated.

=item C<changes>

C<hash> The changes that were actually done on this user. The keys are
the names of the fields that were changed, and the values are a hash
with two keys:

=over

=item C<added>

C<string> The values that were added to this field,
possibly a comma-and-space-separated list if multiple values were added.

=item C<removed>

C<string> The values that were removed from this field, possibly a 
comma-and-space-separated list if multiple values were removed.

=back

=back

=item B<Errors>

=over

=item 51 (Bad Login Name)

You passed an invalid login name in the "names" array.

=item 304 (Authorization Required)

Logged-in users are not authorized to edit other users.

=back

785 786 787 788 789 790 791 792
=item B<History>

=over

=item REST API call added in Bugzilla B<5.0>.

=back

793 794
=back

795
=head1 User Info
796

797
=head2 get
798

799
B<STABLE>
800 801 802 803 804 805 806

=over

=item B<Description>

Gets information about user accounts in Bugzilla.

807 808 809 810
=item B<REST>

To get information about a single user:

811
GET /rest/user/<user_id_or_name>
812 813 814

To search for users by name, group using URL params same as below:

815
GET /rest/user
816 817 818

The returned data format is the same as below.

819 820
=item B<Params>

821 822 823 824
B<Note>: At least one of C<ids>, C<names>, or C<match> must be specified.

B<Note>: Users will not be returned more than once, so even if a user 
is matched by more than one argument, only one user will be returned.
825

826 827 828 829
In addition to the parameters below, this method also accepts the
standard L<include_fields|Bugzilla::WebService/include_fields> and
L<exclude_fields|Bugzilla::WebService/exclude_fields> arguments.

830 831
=over

832 833 834 835
=item C<ids> (array) 

An array of integers, representing user ids.

836
Logged-out users cannot pass this parameter to this function. If they try,
837 838
they will get an error. Logged-in users will get an error if they specify
the id of a user they cannot see.
839

840 841 842
=item C<names> (array)

An array of login names (strings).
843

844 845 846 847 848 849 850 851 852 853 854 855
=item C<match> (array)

An array of strings. This works just like "user matching" in
Bugzilla itself. Users will be returned whose real name or login name
contains any one of the specified strings. Users that you cannot see will
not be included in the returned list.

Most installations have a limit on how many matches are returned for
each string, which defaults to 1000 but can be changed by the Bugzilla
administrator.

Logged-out users cannot use this argument, and an error will be thrown
856 857 858
if they try. (This is to make it harder for spammers to harvest email
addresses from Bugzilla, and also to enforce the user visibility
restrictions that are implemented on some Bugzillas.)
859

860 861 862 863 864 865 866
=item C<limit> (int)

Limit the number of users matched by the C<match> parameter. If value
is greater than the system limit, the system limit will be used. This
parameter is only used when user matching using the C<match> parameter
is being performed.

867 868 869 870 871 872 873 874 875
=item C<group_ids> (array)

=item C<groups> (array)

C<group_ids> is an array of numeric ids for groups that a user can be in.
C<groups> is an array of names of groups that a user can be in.
If these are specified, they limit the return value to users who are
in I<any> of the groups specified.

876 877 878
=item C<include_disabled> (boolean)

By default, when using the C<match> parameter, disabled users are excluded
879 880 881 882
from the returned results unless their full username is identical to the
match string. Setting C<include_disabled> to C<true> will include disabled
users in the returned results even if their username doesn't fully match
the input string.
883

884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
=back

=item B<Returns> 

A hash containing one item, C<users>, that is an array of
hashes. Each hash describes a user, and has the following items:

=over

=item id

C<int> The unique integer ID that Bugzilla uses to represent this user. 
Even if the user's login name changes, this will not change.

=item real_name

C<string> The actual name of the user. May be blank.

=item email

C<string> The email address of the user.

=item name

C<string> The login name of the user. Note that in some situations this is 
different than their email.

=item can_login

C<boolean> A boolean value to indicate if the user can login into bugzilla. 

=item email_enabled

C<boolean> A boolean value to indicate if bug-related mail will be sent
to the user or not.

=item login_denied_text

C<string> A text field that holds the reason for disabling a user from logging
into bugzilla, if empty then the user account is enabled. Otherwise it is 
disabled/closed.

926 927
=item groups

928
C<array> An array of group hashes the user is a member of. If the currently
929
logged in user is querying their own account or is a member of the 'editusers'
930 931 932
group, the array will contain all the groups that the user is a
member of. Otherwise, the array will only contain groups that the logged in
user can bless. Each hash describes the group and contains the following items:
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949

=over

=item id

C<int> The group id

=item name

C<string> The name of the group

=item description

C<string> The description for the group

=back

950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
=item saved_searches

C<array> An array of hashes, each of which represents a user's saved search and has
the following keys:

=over

=item id

C<int> An integer id uniquely identifying the saved search.

=item name

C<string> The name of the saved search.

965
=item query
966 967 968 969 970

C<string> The CGI parameters for the saved search.

=back

971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991
=item saved_reports

C<array> An array of hashes, each of which represents a user's saved report and has
the following keys:

=over

=item id

C<int> An integer id uniquely identifying the saved report.

=item name

C<string> The name of the saved report.

=item query

C<string> The CGI parameters for the saved report.

=back

992 993 994
B<Note>: If you are not logged in to Bugzilla when you call this function, you
will only be returned the C<id>, C<name>, and C<real_name> items. If you are
logged in and not in editusers group, you will only be returned the C<id>, C<name>, 
995 996
C<real_name>, C<email>, C<can_login>, and C<groups> items. The groups returned are
filtered based on your permission to bless each group.
997 998
The C<saved_searches> and C<saved_reports> items are only returned if you are
querying your own account, even if you are in the editusers group.
999 1000 1001 1002 1003 1004 1005

=back

=item B<Errors>

=over

1006
=item 51 (Bad Login Name or Group ID)
1007

1008
You passed an invalid login name in the "names" array or a bad
1009
group ID in the C<group_ids> argument.
1010

1011 1012 1013 1014
=item 52 (Invalid Parameter)

The value used must be an integer greater than zero.

1015 1016 1017 1018 1019
=item 304 (Authorization Required)

You are logged in, but you are not authorized to see one of the users you
wanted to get information about by user id.

1020
=item 505 (User Access By Id or User-Matching Denied)
1021

1022 1023
Logged-out users cannot use the "ids" or "match" arguments to this 
function.
1024

1025 1026 1027 1028 1029
=item 804 (Invalid Group Name)

You passed a group name in the C<groups> argument which either does not
exist or you do not belong to it.

1030 1031
=back

1032 1033 1034 1035 1036 1037
=item B<History>

=over

=item Added in Bugzilla B<3.4>.

1038
=item C<group_ids> and C<groups> were added in Bugzilla B<4.0>.
1039

1040 1041
=item C<include_disabled> was added in Bugzilla B<4.0>. Default
behavior for C<match> was changed to only return enabled accounts.
1042

1043 1044 1045
=item Error 804 has been added in Bugzilla 4.0.9 and 4.2.4. It's now
illegal to pass a group name you don't belong to.

1046 1047
=item C<groups>, C<saved_searches>, and C<saved_reports> were added
in Bugzilla B<4.4>.
1048

1049 1050
=item REST API call added in Bugzilla B<5.0>.

1051 1052
=back

1053
=back