Bugzilla::User - Object for a Bugzilla user
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});
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
is an implementation of Bugzilla::Object, and thus provides all the methods of Bugzilla::Object in addition to the methods listed below.
USER_MATCH_MULTIPLE
Returned by match_field()
when at least one field matched more than one user, but no matches failed.
USER_MATCH_FAILED
Returned by match_field()
when at least one field failed to match anything.
USER_MATCH_SUCCESS
Returned by match_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.
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.
queries
Returns an arrayref of the user's own saved queries, sorted by name. The array contains Bugzilla::Search::Saved objects.
queries_subscribed
Returns an arrayref of shared queries that the user has subscribed to. That is, these are shared queries that the user sees in their footer. This array contains Bugzilla::Search::Saved objects.
queries_available
Returns an arrayref of all queries to which the user could possibly subscribe. This includes the contents of "queries_subscribed". An array of Bugzilla::Search::Saved objects.
flush_queries_cache
Some code modifies the set of stored queries. Because Bugzilla::User
does not handle these modifications, but does cache the result of calling queries
internally, such code must call this method to flush the cached result.
queryshare_groups
An arrayref of group ids. The user can share their own queries with these groups.
account_is_locked_out
Returns 1
if the account has failed to log in too many times recently, and thus is locked out for a period of time. Returns 0
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 contain ip_addr
, login_time
, and user_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 call update
.
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
Returns 1
if the user has set his preference to show the 'My Bugs' link in the page footer, and 0
otherwise.
identity
Returns a string for the identity of the user. This will be of the form name <email>
if the user has specified a name, and email
otherwise.
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 by authorizer()
. Should only be called by Bugzilla::Auth::login
, for the most part.
disabledtext
Returns the disable text of the user, if any.
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 value default_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.
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.
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 he 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.
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 1 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: 1 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.
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.
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.
direct_group_membership
Returns a reference to an array of group objects. Groups the user belong to by group inheritance are excluded from the list.
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 of visible_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, returns 0
otherwise.
When called with one argument: Returns 1
if the user can bless the group with that id, returns 0
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 than wants_bug_mail
, allowing you to check e.g. permissions for flag mail.
is_mover
Returns true if the user is in the list of users allowed to move bugs to another database. Note that this method doesn't check whether bug moving is enabled.
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.
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 "create" in Bugzilla::Object.
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 he 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 a Bugzilla::User
object.
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, he can change his 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.
user_id_to_login($user_id)
Returns the login name of the user account for the given user ID. If no valid user ID is given or the user has no entry in the profiles table, we return an empty string.
validate_password($passwd1, $passwd2)
Returns true if a password is valid (i.e. meets Bugzilla's requirements for length and content), else returns false. Untaints $passwd1
if successful.
If a second password is passed in, this function also verifies that the two passwords match.
match_field($data, $fields, $behavior)
Wrapper for the match()
function.
$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 to MATCH_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.If the third parameter is set to MATCH_SKIP_CONFIRM
, the function returns either USER_MATCH_SUCCESS
if all fields can be set unambiguously, USER_MATCH_FAILED
if at least one field doesn't match any user account, or USER_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.
This function must be called early in a script, before anything external is done with the data.