NAME

BZ::Client::User - Creates and edits user accounts in Bugzilla

VERSION

version 4.4004

SYNOPSIS

This class provides methods for accessing information about the Bugzilla servers installation.

my $client = BZ::Client->new( url      => $url,
                              user     => $user,
                              password => $password );

my $ok    = BZ::Client::User->offer_account_by_email( $client, 'email@address' );
my $users = BZ::Client::User->get( $client, \%params );
my $id    = BZ::Client::User->create( $client, \%params );
my $users = BZ::Client::User->update( $client, \%params );

CLASS METHODS

This section lists the class methods, which are available in this module.

offer_account_by_email

my $ok = BZ::Client::User->offer_account_by_email( $client, 'email@address' );
my $ok = BZ::Client::User->offer_account_by_email( $client, \%params );

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.

This is the recommended way to create a Bugzilla account.

Parameters

email

email (string) The email address to send the offer to.

Note: email can be provided as the single option as a scalar as shown above.

Returns

nothing if successful

Errors

50 - Email parameter missing

The email parameter was not provided.

500 - Account Already Exists

An account with that email address already exists in Bugzilla.

501 - Illegal Email Address

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

get

my $users = BZ::Client::User->get( $client, \%params );

Gets information about user accounts in Bugzilla.

History

Added in Bugzilla 3.4

Parameters

Note: At least one of "ids", "names", or "match" must be specified.

Note: Users will only appear once in the returned list, even if that user is matched by more than one search argument.

In addition to the parameters below, this method also accepts the standard "include_fields" in BZ::Client::Bug and "exclude_fields" in BZ::Client::Bug arguments.

ids (array)

An array of integers, representing user ID's.

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

names (array)

An array of login names (strings).

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 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.)

limit (int)

Limit the number of users matched by the "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 "match" parameter is being performed.

group_ids (array)

group_ids is an array of numeric ids for groups that a user can be in. If this is specified, it limits the return value to users who are in any of the groups specified.

Added in Bugzilla 4.0

groups (array)

groups is an array of names of groups that a user can be in. If this is specified, it limits the return value to users who are in any of the groups specified.

Added in Bugzilla 4.0

include_disabled (boolean)

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

Added in Bugzilla 4.0, default behaviour for "match" was then changed to exclude disabled users.

Returns

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

id

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

real_name

real_name (string) The actual name of the user. May be blank.

email

email (string) The email address of the user.

name

name (string) The login name of the user. Note that in some situations this is different than their email.

can_login

can_login (boolean) A boolean value to indicate if the user can login into bugzilla.

email_enabled

email_enabled (boolean) A boolean value to indicate if bug-related mail will be sent to the user or not.

login_denied_text

login_denied_text (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.

groups

groups (array) An array of group hashes the user is a member of. If the currently logged in user is querying his own account or is a member of the editusers 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:

Added in Bugzilla 4.4

id

id (int) The group ID

name

name (string) The name of the group

description

description (string) The description for the group

saved_searches

saved_searches (array) An array of hashes, each of which represents a user's saved search and has the following keys:

Added in Bugzilla 4.4

id

id (int) An integer ID uniquely identifying the saved search.

name

name (string) The name of the saved search.

query

query (string) The CGI parameters for the saved search.

saved_reports

saved_reports (array) An array of hashes, each of which represents a user's saved report and has the following keys:

Added in Bugzilla 4.4

id

id (int) An integer ID uniquely identifying the saved report.

name

name (string) The name of the saved report.

query

query (string) The CGI parameters for the saved report.

Note: If you are not logged in to Bugzilla when you call this function, you will only be returned the id, name, and real_name items. If you are logged in and not in editusers group, you will only be returned the id, name, real_name, email, can_login, and groups items. The groups returned are filtered based on your permission to bless each group. The "saved_searches" and "saved_reports" items are only returned if you are querying your own account, even if you are in the editusers group.

Errors

51 - Bad Login Name or Group ID

You passed an invalid login name in the "names" array or a bad group ID in the "group_ids" argument.

52 - Invalid Parameter

The value used must be an integer greater then zero.

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.

505 - User Access By Id or User-Matching Denied

Logged-out users cannot use the ids or match arguments to this function.

804 - Invalid Group Name

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

Added in Bugzilla 4.0.9 and 4.2.4, when it also became illegal to pass a group name you don't belong to.

new

my $user = BZ::Client::User->new( id => $id );

Creates a new instance with the given ID.

create

my $id = BZ::Client::User->create( $client, \%params );

Creates a user account directly in Bugzilla, password and all. Instead of this, you should use "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.

You must be logged in and have the editusers privilege in order to call this function.

Params:

email

email (string) - The email address for the new user.

Required.

full_name

full_name (string) The user's full name. Will be set to empty if not specified.

password

password (string) 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.

Returns

The numeric ID of the user that was created.

Errors

The same as "offer_account_by_email". If a password is specified, the function may also throw:

502 - Password Too Short

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

503 - Password Too Long

Removed in Bugzilla 3.6

update

my $users = BZ::Client::User->update( $client, \%params );

Updates user accounts in Bugzilla.

Parameters

ids

array Contains ID's of user to update.

names

array Contains email/login of user to update.

full_name

full_name (string) The new name of the user.

email

email (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.)

password

password (string) The password of the user.

email_enabled

email_enabled (boolean) A boolean value to enable/disable sending bug-related mail to the user.

login_denied_text

login_denied_text (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.

Returns

An array of hashes with the following fields:

id

id (int) The ID of the user that was updated.

changes

changes (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:

added

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

removed

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

Errors

51 - Bad Login Name

You passed an invalid login name in the names array.

304 - Authorization Required

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

EXCEPTION HANDLING

See BZ::Client::Exception

SEE ALSO

BZ::Client, BZ::Client::API, Bugzilla API

AUTHORS

  • Dean Hamstead <dean@bytefoundry.com.au>

  • Jochen Wiedmann <jochen.wiedmann@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2021 by Dean Hamstad.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.