5.7.75. Bugzilla::User¶
5.7.75.1. NAME¶
Bugzilla::User - Object for a Bugzilla user
5.7.75.2. SYNOPSIS¶
use Bugzilla::User;
my $user = new Bugzilla::User($id);
my @get_selectable_classifications =
$user->get_selectable_classifications;
# Class Functions
$user = Bugzilla::User->create({
login_name => $username,
realname => $realname,
cryptpassword => $plaintext_password,
disabledtext => $disabledtext,
disable_mail => 0});
5.7.75.3. DESCRIPTION¶
This package handles Bugzilla users. Data obtained from here is read-only; there is currently no way to modify a user from this package.
Note that the currently logged in user (if any) is available via Bugzilla->user|Bugzilla/"user".
Bugzilla::User
is an implementation of Bugzilla::Object, and thus
provides all the methods of Bugzilla::Object in addition to the
methods listed below.
5.7.75.4. CONSTANTS¶
USER_MATCH_MULTIPLE
Returned bymatch_field()
when at least one field matched more than one user, but no matches failed.
USER_MATCH_FAILED
Returned bymatch_field()
when at least one field failed to match anything.
USER_MATCH_SUCCESS
Returned bymatch_field()
when all fields successfully matched only one user.
MATCH_SKIP_CONFIRM
Passed in to match_field to tell match_field to never display a confirmation screen.
5.7.75.5. METHODS¶
Constructors¶
super_user
Returns a user who is in all groups, but who does not really exist in the database. Used for non-web scripts like checksetup that need to make database changes and so on.
Saved Recent Bug Lists¶
recent_searches
Returns an arrayref of Bugzilla::Search::Recent objects containing the user's recent searches.
recent_search_containing(bug_id)
Returns a Bugzilla::Search::Recent object that contains the most recent search by the user for the specified bug id. Retuns undef if no match is found.
recent_search_for(bug)
Returns a Bugzilla::Search::Recent object that contains a search by the user. Uses the list_id of the current loaded page, or the referrer page, and the bug id if that fails. Finally it will check the BUGLIST cookie, and create an object based on that, or undef if it does not exist.
save_last_search
Saves the users most recent search in the database if logged in, or in the BUGLIST cookie if not logged in. Parameters are bug_ids, order, vars and list_id.
Account Lockout¶
account_is_locked_out
Returns1
if the account has failed to log in too many times recently, and thus is locked out for a period of time. Returns0
otherwise.
account_ip_login_failures
Returns an arrayref of hashrefs, that contains information about the recent times that this account has failed to log in from the current remote IP. The hashes containip_addr
,login_time
, anduser_id
.
note_login_failure
This notes that this account has failed to log in, and stores the fact in the database. The storing happens immediately, it does not wait for you to callupdate
.
set_email_enabled
bool
- Setsdisable_mail
to the inverse of the boolean provided.
Other Methods¶
id
Returns the userid for this user.
login
Returns the login name for this user.
email
Returns the user's email address. Currently this is the same value as the login.
name
Returns the 'real' name for this user, if any.
showmybugslink
Returns1
if the user has set their preference to show the 'My Bugs' link in the page footer, and0
otherwise.
identity
Returns a string for the identity of the user. This will be of the formname <email>
if the user has specified a name, and
nick
Returns a user "nickname" -- i.e. a shorter, not-necessarily-unique name by which to identify the user. Currently the part of the user's email address before the at sign (@), but that could change, especially if we implement usernames not dependent on email address.
authorizer
This is the Bugzilla::Auth object that the User logged in with. If the user hasn't logged in yet, a new, empty Bugzilla::Auth() object is returned.
set_authorizer($authorizer)
Sets the Bugzilla::Auth object to be returned byauthorizer()
. Should only be called byBugzilla::Auth::login
, for the most part.
disabledtext
Returns the disable text of the user, if any.
reports
Returns an arrayref of the user's own saved reports. The array contains Bugzilla::Reports objects.
flush_reports_cache
Some code modifies the set of stored reports. BecauseBugzilla::User
does not handle these modifications, but does cache the result of callingreports
internally, such code must call this method to flush the cached result.
settings
Returns a hash of hashes which holds the user's settings. The first key is the name of the setting, as found in setting.name. The second key is one of: is_enabled - true if the user is allowed to set the preference themselves;
false to force the site defaults for themselves or must accept the global site default valuedefault_value - the global site default for this setting value - the value of this setting for this user. Will be the same
as the default_value if the user is not logged in, or if is_default is true.
- is_default - a boolean to indicate whether the user has chosen to make
- a preference for themself or use the site default.
setting(name)
Returns the value for the specified setting.
timezone
Returns the timezone used to display dates and times to the user, as a DateTime::TimeZone object.
groups
Returns an arrayref of Bugzilla::Group objects representing groups that this user is a member of.
groups_as_string
Returns a string containing a comma-separated list of numeric group ids. If the user is not a member of any groups, returns "-1". This is most often used within an SQL IN() function.
groups_in_sql
This returns anIN
clause for SQL, containing either all of the groups the user is in, or-1
if the user is in no groups. This takes one argument--the name of the SQL field that should be on the left-hand-side of theIN
statement, which defaults togroup_id
if not specified.
in_group($group_name, $product_id)
Determines whether or not a user is in the given group by name. If $product_id is given, it also checks for local privileges for this product.
in_group_id
Determines whether or not a user is in the given group by id.
bless_groups
Returns an arrayref of Bugzilla::Group objects.
The arrayref consists of the groups the user can bless, taking into account that having editusers permissions means that you can bless all groups, and that you need to be able to see a group in order to bless it.
get_products_by_permission($group)
Returns a list of product objects for which the user has $group privileges and which they can access. $group must be one of the groups defined in PER_PRODUCT_PRIVILEGES.
can_see_user(user)
Returns 1 if the specified user account exists and is visible to the user, 0 otherwise.
can_edit_product(prod_id)
Determines if, given a product id, the user can edit bugs in this product at all.
visible_bugs($bugs)
Description: Determines if a list of bugs are visible to the user. Params:$bugs
- An arrayref of Bugzilla::Bug objects or bug ids Returns: An arrayref of the bug ids that the user can see
can_see_bug(bug_id)
Determines if the user can see the specified bug.
can_see_product(product_name)
Returns 1 if the user can access the specified product, and 0 if the user should not be aware of the existence of the product.
derive_regexp_groups
Bugzilla allows for group inheritance. When data about the user (or any of the groups) changes, the database must be updated. Handling updated groups is taken care of by the constructor. However, when updating the email address, the user may be placed into different groups, based on a new email regexp. This method should be called in such a case to force reresolution of these groups.
clear_product_cache
Clears the stored values for `get_selectable_products`_, `get_enterable_products`_, etc. so that their data will be read from the database again. Used mostly by Bugzilla::Product.
get_selectable_products
Description: Returns all products the user is allowed to access. This list is restricted to some given classification if $classification_id is given. Params: $classification_id - (optional) The ID of the classification the products belong to. Returns: An array of product objects, sorted by the product name.
get_selectable_classifications
Description: Returns all classifications containing at least one product the user is allowed to view. Params: none Returns: An array of Bugzilla::Classification objects, sorted by the classification name.
can_enter_product($product_name, $warn)
Description: Returns a product object if the user can enter bugs into the specified product. If the user cannot enter bugs into the product, the behavior of this method depends on the value of $warn: - if $warn is false (or not given), a 'false' value is returned; - if $warn is true, an error is thrown. Params: $product_name - a product name. $warn - optional parameter, indicating whether an error must be thrown if the user cannot enter bugs into the specified product. Returns: A product object if the user can enter bugs into the product, 0 if the user cannot enter bugs into the product and if $warn is false (an error is thrown if $warn is true).
get_enterable_products
Description: Returns an array of product objects into which the user is allowed to enter bugs. Params: none Returns: an array of product objects.
can_access_product($product)
Returns 1 if the user can search or enter bugs into the specified product (either a Bugzilla::Product or a product name), and 0 if the user should not be aware of the existence of the product.
get_accessible_products
Description: Returns an array of product objects the user can search or enter bugs against. Params: none Returns: an array of product objects.
can_administer
Returns 1 if the user can see the admin menu. Otherwise, returns 0
check_can_admin_product($product_name)
Description: Checks whether the user is allowed to administrate the product. Params: $product_name - a product name. Returns: On success, a product object. On failure, an error is thrown.
check_can_admin_flagtype($flagtype_id)
Description: Checks whether the user is allowed to edit properties of the flag type. If the flag type is also used by some products for which the user hasn't editcomponents privs, then the user is only allowed to edit the inclusion and exclusion lists for products they can administrate. Params: $flagtype_id - a flag type ID. Returns: On success, a flag type object. On failure, an error is thrown. In list context, a boolean indicating whether the user can edit all properties of the flag type is also returned. The boolean is false if the user can only edit the inclusion and exclusions lists.
can_request_flag($flag_type)
Description: Checks whether the user can request flags of the given type. Params: $flag_type - a Bugzilla::FlagType object. Returns: 1 if the user can request flags of the given type, 0 otherwise.
can_set_flag($flag_type)
Description: Checks whether the user can set flags of the given type. Params: $flag_type - a Bugzilla::FlagType object. Returns: 1 if the user can set flags of the given type, 0 otherwise.
get_userlist
Returns a reference to an array of users. The array is populated with hashrefs containing the login, identity and visibility. Users that are not visible to this user will have 'visible' set to zero.
visible_groups_inherited
Returns a list of all groups whose members should be visible to this user. Since this list is flattened already, there is no need for all users to be have derived groups up-to-date to select the users meeting this criteria.
visible_groups_direct
Returns a list of groups that the user is aware of.
visible_groups_as_string
Returns the result ofvisible_groups_inherited
as a string (a comma-separated list).
product_responsibilities
Retrieve user's product responsibilities as a list of component objects. Each object is a component the user has a responsibility for.
can_bless
When called with no arguments: Returns
1
if the user can bless at least one group, returns0
otherwise.When called with one argument: Returns
1
if the user can bless the group with that id, returns0
otherwise.
wants_bug_mail
Returns true if the user wants mail for a given bug change.
wants_mail
Returns true if the user wants mail for a given set of events. This method is more general thanwants_bug_mail
, allowing you to check e.g. permissions for flag mail.
is_insider
Returns true if the user can access private comments and attachments, i.e. if the 'insidergroup' parameter is set and the user belongs to this group.
is_global_watcher
Returns true if the user is a global watcher, i.e. if the 'globalwatchers' parameter contains the user.
can_tag_comments
Returns true if the user can attach tags to comments. i.e. if the 'comment_taggers_group' parameter is set and the user belongs to this group.
last_visited
Returns an arrayref Bugzilla::BugUserLastVisit objects.
is_involved_in_bug($bug)
Returns true if any of the following conditions are met, false otherwise.
*
User is the assignee of the bug*
User is the reporter of the bug*
User is the QA contact of the bug (if Bugzilla is configured to use a QA contact)*
User is in the cc list for the bug.
set_groups
hash
These specify the groups that this user is directly a member of. To set these, you should pass a hash as the value. The hash may contain the following fields:
add
An array ofint
s orstring
s. The group ids or group names that the user should be added to.
remove
An array ofint
s orstring
s. The group ids or group names that the user should be removed from.
set
An array ofint
s orstring
s. An exact set of group ids and group names that the user should be a member of. NOTE: This does not remove groups from the user where the person making the change does not have the bless privilege for.If you specifyset
, thenadd
andremove
will be ignored. A group in both theadd
andremove
list will be added. Specifying a group that the user making the change does not have bless rights will generate an error.
set_bless_groups
hash
- This is the same as set_groups, but affects what groups a user has direct membership to bless that group. It takes the same inputs as set_groups.
5.7.75.6. CLASS FUNCTIONS¶
These are functions that are not called on a User object, but instead are called "statically," just like a normal procedural function.
create
The same as Bugzilla::Object/create.
- Params: login_name - Required The login name for the new user.
realname - The full name for the new user. cryptpassword - Required The password for the new user.
Even though the name says "crypt", you should just specify a plain-text password. If you specify '*', the user will not be able to log in using DB authentication.
- disabledtext - The disable-text for the new user. If given, the user
- will be disabled, meaning they cannot log in. Defaults to an empty string.
- disable_mail - If 1, bug-related mail will not be sent to this user;
- if 0, mail will be sent depending on the user's email preferences.
check
Takes a username as its only argument. Throws an error if there is no user with that username. Returns aBugzilla::User
object.
check_account_creation_enabled
Checks that users can create new user accounts, and throws an error if user creation is disabled.
check_and_send_account_creation_confirmation($login)
If the user request for a new account passes validation checks, an email is sent to this user for confirmation. Otherwise an error is thrown indicating why the request has been rejected.
is_available_username
Returns a boolean indicating whether or not the supplied username is already taken in Bugzilla.
- Params: $username (scalar, string) - The full login name of the username
that you are checking.
- $old_username (scalar, string) - If you are checking an email-change
- token, insert the "old" username that the user is changing from, here. Then, as long as it's the right user for that token, they can change their username to $username. (That is, this function will return a boolean true value).
login_to_id($login, $throw_error)
Takes a login name of a Bugzilla user and changes that into a numeric ID for that user. This ID can then be passed to Bugzilla::User::new to create a new user.
If no valid user exists with that login name, then the function returns 0. However, if $throw_error is set, the function will throw a user error instead of returning.
This function can also be used when you want to just find out the userid of a user, but you don't want the full weight of Bugzilla::User.
However, consider using a Bugzilla::User object instead of this function if you need more information about the user than just their ID.
validate_password($passwd1, $passwd2)
Returns true if a password is valid (i.e. meets Bugzilla's requirements for length and content), else throws an error. Untaints
$passwd1
if successful.If a second password is passed in, this function also verifies that the two passwords match.
validate_password_check($passwd1, $passwd2)
This sub routine is similair to
validate_password
, except that it allows the calling code to handle its own errors.Returns undef and untaints
$passwd1
if a password is valid (i.e. meets Bugzilla's requirements for length and content), else returns the error.If a second password is passed in, this function also verifies that the two passwords match.
match_field($data, $fields, $behavior)
Description
Wrapper for thematch()
function.Params
$fields
- A hashref with field names as keys and a hash as values. Each hash is of the form { 'type' => 'single|multi' }, which specifies whether the field can take a single login name only or several.
$data
(optional) - A hashref with field names as keys and field values as values. If undefined,Bugzilla->input_params
is used.
$behavior
(optional) - If set toMATCH_SKIP_CONFIRM
, no confirmation screen is displayed. In that case, the fields which don't match a unique user are left undefined. If not set, a confirmation screen is displayed if at least one field doesn't match any login name or match more than one.Returns
If the third parameter is set to
MATCH_SKIP_CONFIRM
, the function returns eitherUSER_MATCH_SUCCESS
if all fields can be set unambiguously,USER_MATCH_FAILED
if at least one field doesn't match any user account, orUSER_MATCH_MULTIPLE
if some fields match more than one user account.If the third parameter is not set, then if all fields could be set unambiguously, nothing is returned, else a confirmation page is displayed.
Note
This function must be called early in a script, before anything external is done with the data.
5.7.75.7. SEE ALSO¶
Bugzilla|Bugzilla
5.7.75.8. Methods in need of POD¶
email_enabled
cryptpassword
clear_login_failures
set_disable_mail
has_audit_entries
groups_with_icon
check_login_name
set_extern_id
mail_settings
email_disabled
update
is_timetracker
is_enabled
queryshare_groups_as_string
set_login
set_password
last_seen_date
set_disabledtext
update_last_seen_date
set_name
DB_COLUMNS
extern_id
UPDATE_COLUMNS
This documentation undoubtedly has bugs; if you find some, please file them here.