bugzilla-4intranet/docs/en/html/api/Bugzilla/User.html

541 lines
22 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>
Bugzilla::User</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" title="style" type="text/css" href=".././../../../style.css" media="all" >
</head>
<body id="pod">
<p class="backlinktop"><b><a name="___top" href="../index.html" accesskey="1" title="All Documents">&lt;&lt;</a></b></p>
<h1>Bugzilla::User</h1>
<div class='indexgroup'>
<ul class='indexList indexList1'>
<li class='indexItem indexItem1'><a href='#NAME'>NAME</a>
<li class='indexItem indexItem1'><a href='#SYNOPSIS'>SYNOPSIS</a>
<li class='indexItem indexItem1'><a href='#DESCRIPTION'>DESCRIPTION</a>
<li class='indexItem indexItem1'><a href='#CONSTANTS'>CONSTANTS</a>
<li class='indexItem indexItem1'><a href='#METHODS'>METHODS</a>
<ul class='indexList indexList2'>
<li class='indexItem indexItem2'><a href='#Saved_and_Shared_Queries'>Saved and Shared Queries</a>
<li class='indexItem indexItem2'><a href='#Other_Methods'>Other Methods</a>
</ul>
<li class='indexItem indexItem1'><a href='#CLASS_FUNCTIONS'>CLASS FUNCTIONS</a>
<li class='indexItem indexItem1'><a href='#SEE_ALSO'>SEE ALSO</a>
</ul>
</div>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="NAME"
>NAME</a></h1>
<p>Bugzilla::User - Object for a Bugzilla user</p>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="SYNOPSIS"
>SYNOPSIS</a></h1>
<pre class="code"> use Bugzilla::User;
my $user = new Bugzilla::User($id);
my @get_selectable_classifications =
$user-&#62;get_selectable_classifications;
# Class Functions
$user = Bugzilla::User-&#62;create({
login_name =&#62; $username,
realname =&#62; $realname,
cryptpassword =&#62; $plaintext_password,
disabledtext =&#62; $disabledtext,
disable_mail =&#62; 0});</pre>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="DESCRIPTION"
>DESCRIPTION</a></h1>
<p>This package handles Bugzilla users. Data obtained from here is read-only; there is currently no way to modify a user from this package.</p>
<p>Note that the currently logged in user (if any) is available via <a href="../Bugzilla.html#user" class="podlinkpod"
>Bugzilla-&#62;user</a>.</p>
<p><code class="code">Bugzilla::User</code> is an implementation of <a href="../Bugzilla/Object.html" class="podlinkpod"
>Bugzilla::Object</a>, and thus provides all the methods of <a href="../Bugzilla/Object.html" class="podlinkpod"
>Bugzilla::Object</a> in addition to the methods listed below.</p>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="CONSTANTS"
>CONSTANTS</a></h1>
<dl>
<dt><a name="USER_MATCH_MULTIPLE"
><code class="code">USER_MATCH_MULTIPLE</code></a></dt>
<dd>
<p>Returned by <code class="code">match_field()</code> when at least one field matched more than one user, but no matches failed.</p>
<dt><a name="USER_MATCH_FAILED"
><code class="code">USER_MATCH_FAILED</code></a></dt>
<dd>
<p>Returned by <code class="code">match_field()</code> when at least one field failed to match anything.</p>
<dt><a name="USER_MATCH_SUCCESS"
><code class="code">USER_MATCH_SUCCESS</code></a></dt>
<dd>
<p>Returned by <code class="code">match_field()</code> when all fields successfully matched only one user.</p>
<dt><a name="MATCH_SKIP_CONFIRM"
><code class="code">MATCH_SKIP_CONFIRM</code></a></dt>
<dd>
<p>Passed in to match_field to tell match_field to never display a confirmation screen.</p>
</dd>
</dl>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="METHODS"
>METHODS</a></h1>
<h2><a class='u' href='#___top' title='click to go to top of document'
name="Saved_and_Shared_Queries"
>Saved and Shared Queries</a></h2>
<dl>
<dt><a name="queries"
><code class="code">queries</code></a></dt>
<dd>
<p>Returns an arrayref of the user&#39;s own saved queries, sorted by name. The array contains <a href="../Bugzilla/Search/Saved.html" class="podlinkpod"
>Bugzilla::Search::Saved</a> objects.</p>
<dt><a name="queries_subscribed"
><code class="code">queries_subscribed</code></a></dt>
<dd>
<p>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 <a href="../Bugzilla/Search/Saved.html" class="podlinkpod"
>Bugzilla::Search::Saved</a> objects.</p>
<dt><a name="queries_available"
><code class="code">queries_available</code></a></dt>
<dd>
<p>Returns an arrayref of all queries to which the user could possibly subscribe. This includes the contents of <a href="#queries_subscribed" class="podlinkpod"
>&#34;queries_subscribed&#34;</a>. An array of <a href="../Bugzilla/Search/Saved.html" class="podlinkpod"
>Bugzilla::Search::Saved</a> objects.</p>
<dt><a name="flush_queries_cache"
><code class="code">flush_queries_cache</code></a></dt>
<dd>
<p>Some code modifies the set of stored queries. Because <code class="code">Bugzilla::User</code> does not handle these modifications, but does cache the result of calling <code class="code">queries</code> internally, such code must call this method to flush the cached result.</p>
<dt><a name="queryshare_groups"
><code class="code">queryshare_groups</code></a></dt>
<dd>
<p>An arrayref of group ids. The user can share their own queries with these groups.</p>
</dd>
</dl>
<h2><a class='u' href='#___top' title='click to go to top of document'
name="Other_Methods"
>Other Methods</a></h2>
<dl>
<dt><a name="id"
><code class="code">id</code></a></dt>
<dd>
<p>Returns the userid for this user.</p>
<dt><a name="login"
><code class="code">login</code></a></dt>
<dd>
<p>Returns the login name for this user.</p>
<dt><a name="email"
><code class="code">email</code></a></dt>
<dd>
<p>Returns the user&#39;s email address. Currently this is the same value as the login.</p>
<dt><a name="name"
><code class="code">name</code></a></dt>
<dd>
<p>Returns the &#39;real&#39; name for this user, if any.</p>
<dt><a name="showmybugslink"
><code class="code">showmybugslink</code></a></dt>
<dd>
<p>Returns <code class="code">1</code> if the user has set his preference to show the &#39;My Bugs&#39; link in the page footer, and <code class="code">0</code> otherwise.</p>
<dt><a name="identity"
><code class="code">identity</code></a></dt>
<dd>
<p>Returns a string for the identity of the user. This will be of the form <code class="code">name &#60;email&#62;</code> if the user has specified a name, and <code class="code">email</code> otherwise.</p>
<dt><a name="nick"
><code class="code">nick</code></a></dt>
<dd>
<p>Returns a user &#34;nickname&#34; -- i.e. a shorter, not-necessarily-unique name by which to identify the user. Currently the part of the user&#39;s email address before the at sign (@), but that could change, especially if we implement usernames not dependent on email address.</p>
<dt><a name="authorizer"
><code class="code">authorizer</code></a></dt>
<dd>
<p>This is the <a href="../Bugzilla/Auth.html" class="podlinkpod"
>Bugzilla::Auth</a> object that the User logged in with. If the user hasn&#39;t logged in yet, a new, empty Bugzilla::Auth() object is returned.</p>
<dt><a name="set_authorizer($authorizer)"
><code class="code">set_authorizer($authorizer)</code></a></dt>
<dd>
<p>Sets the <a href="../Bugzilla/Auth.html" class="podlinkpod"
>Bugzilla::Auth</a> object to be returned by <code class="code">authorizer()</code>. Should only be called by <code class="code">Bugzilla::Auth::login</code>, for the most part.</p>
<dt><a name="disabledtext"
><code class="code">disabledtext</code></a></dt>
<dd>
<p>Returns the disable text of the user, if any.</p>
<dt><a name="settings"
><code class="code">settings</code></a></dt>
<dd>
<p>Returns a hash of hashes which holds the user&#39;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.</p>
<dt><a name="timezone"
><code class="code">timezone</code></a></dt>
<dd>
<p>Returns the timezone used to display dates and times to the user, as a DateTime::TimeZone object.</p>
<dt><a name="groups"
><code class="code">groups</code></a></dt>
<dd>
<p>Returns an arrayref of <a href="../Bugzilla/Group.html" class="podlinkpod"
>Bugzilla::Group</a> objects representing groups that this user is a member of.</p>
<dt><a name="groups_as_string"
><code class="code">groups_as_string</code></a></dt>
<dd>
<p>Returns a string containing a comma-separated list of numeric group ids. If the user is not a member of any groups, returns &#34;-1&#34;. This is most often used within an SQL IN() function.</p>
<dt><a name="in_group($group_name,_$product_id)"
><code class="code">in_group($group_name, $product_id)</code></a></dt>
<dd>
<p>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.</p>
<dt><a name="in_group_id"
><code class="code">in_group_id</code></a></dt>
<dd>
<p>Determines whether or not a user is in the given group by id.</p>
<dt><a name="bless_groups"
><code class="code">bless_groups</code></a></dt>
<dd>
<p>Returns an arrayref of <a href="../Bugzilla/Group.html" class="podlinkpod"
>Bugzilla::Group</a> objects.</p>
<p>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.</p>
<dt><a name="get_products_by_permission($group)"
><code class="code">get_products_by_permission($group)</code></a></dt>
<dd>
<p>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.</p>
<dt><a name="can_see_user(user)"
><code class="code">can_see_user(user)</code></a></dt>
<dd>
<p>Returns 1 if the specified user account exists and is visible to the user, 0 otherwise.</p>
<dt><a name="can_edit_product(prod_id)"
><code class="code">can_edit_product(prod_id)</code></a></dt>
<dd>
<p>Determines if, given a product id, the user can edit bugs in this product at all.</p>
<dt><a name="can_see_bug(bug_id)"
><code class="code">can_see_bug(bug_id)</code></a></dt>
<dd>
<p>Determines if the user can see the specified bug.</p>
<dt><a name="can_see_product(product_name)"
><code class="code">can_see_product(product_name)</code></a></dt>
<dd>
<p>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.</p>
<dt><a name="derive_regexp_groups"
><code class="code">derive_regexp_groups</code></a></dt>
<dd>
<p>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.</p>
<dt><a name="get_selectable_products"
><code class="code">get_selectable_products</code></a></dt>
<dd>
<pre class="code"> 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.</pre>
<dt><a name="get_selectable_classifications"
><code class="code">get_selectable_classifications</code></a></dt>
<dd>
<pre class="code"> 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.</pre>
<dt><a name="can_enter_product($product_name,_$warn)"
><code class="code">can_enter_product($product_name, $warn)</code></a></dt>
<dd>
<pre class="code"> 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 &#39;false&#39; 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).</pre>
<dt><a name="get_enterable_products"
><code class="code">get_enterable_products</code></a></dt>
<dd>
<pre class="code"> Description: Returns an array of product objects into which the user is
allowed to enter bugs.
Params: none
Returns: an array of product objects.</pre>
<dt><a name="can_access_product(product_name)"
><code class="code">can_access_product(product_name)</code></a></dt>
<dd>
<p>Returns 1 if the user can search or enter bugs into the specified product, and 0 if the user should not be aware of the existence of the product.</p>
<dt><a name="get_accessible_products"
><code class="code">get_accessible_products</code></a></dt>
<dd>
<pre class="code"> Description: Returns an array of product objects the user can search
or enter bugs against.
Params: none
Returns: an array of product objects.</pre>
<dt><a name="check_can_admin_product($product_name)"
><code class="code">check_can_admin_product($product_name)</code></a></dt>
<dd>
<pre class="code"> 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.</pre>
<dt><a name="can_request_flag($flag_type)"
><code class="code">can_request_flag($flag_type)</code></a></dt>
<dd>
<pre class="code"> 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.</pre>
<dt><a name="can_set_flag($flag_type)"
><code class="code">can_set_flag($flag_type)</code></a></dt>
<dd>
<pre class="code"> 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.</pre>
<dt><a name="get_userlist"
><code class="code">get_userlist</code></a></dt>
<dd>
<p>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 &#39;visible&#39; set to zero.</p>
<dt><a name="direct_group_membership"
><code class="code">direct_group_membership</code></a></dt>
<dd>
<p>Returns a reference to an array of group objects. Groups the user belong to by group inheritance are excluded from the list.</p>
<dt><a name="visible_groups_inherited"
><code class="code">visible_groups_inherited</code></a></dt>
<dd>
<p>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.</p>
<dt><a name="visible_groups_direct"
><code class="code">visible_groups_direct</code></a></dt>
<dd>
<p>Returns a list of groups that the user is aware of.</p>
<dt><a name="visible_groups_as_string"
><code class="code">visible_groups_as_string</code></a></dt>
<dd>
<p>Returns the result of <code class="code">visible_groups_inherited</code> as a string (a comma-separated list).</p>
<dt><a name="product_responsibilities"
><code class="code">product_responsibilities</code></a></dt>
<dd>
<p>Retrieve user&#39;s product responsibilities as a list of component objects. Each object is a component the user has a responsibility for.</p>
<dt><a name="can_bless"
><code class="code">can_bless</code></a></dt>
<dd>
<p>When called with no arguments: Returns <code class="code">1</code> if the user can bless at least one group, returns <code class="code">0</code> otherwise.</p>
<p>When called with one argument: Returns <code class="code">1</code> if the user can bless the group with that id, returns <code class="code">0</code> otherwise.</p>
<dt><a name="wants_bug_mail"
><code class="code">wants_bug_mail</code></a></dt>
<dd>
<p>Returns true if the user wants mail for a given bug change.</p>
<dt><a name="wants_mail"
><code class="code">wants_mail</code></a></dt>
<dd>
<p>Returns true if the user wants mail for a given set of events. This method is more general than <code class="code">wants_bug_mail</code>, allowing you to check e.g. permissions for flag mail.</p>
<dt><a name="is_mover"
><code class="code">is_mover</code></a></dt>
<dd>
<p>Returns true if the user is in the list of users allowed to move bugs to another database. Note that this method doesn&#39;t check whether bug moving is enabled.</p>
<dt><a name="is_insider"
><code class="code">is_insider</code></a></dt>
<dd>
<p>Returns true if the user can access private comments and attachments, i.e. if the &#39;insidergroup&#39; parameter is set and the user belongs to this group.</p>
<dt><a name="is_global_watcher"
><code class="code">is_global_watcher</code></a></dt>
<dd>
<p>Returns true if the user is a global watcher, i.e. if the &#39;globalwatchers&#39; parameter contains the user.</p>
</dd>
</dl>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="CLASS_FUNCTIONS"
>CLASS FUNCTIONS</a></h1>
<p>These are functions that are not called on a User object, but instead are called &#34;statically,&#34; just like a normal procedural function.</p>
<dl>
<dt><a name="create"
><code class="code">create</code></a></dt>
<dd>
<p>The same as <a href="../Bugzilla/Object.html#create" class="podlinkpod"
>&#34;create&#34; in Bugzilla::Object</a>.</p>
<p>Params: login_name - <b>Required</b> The login name for the new user. realname - The full name for the new user. cryptpassword - <b>Required</b> The password for the new user. Even though the name says &#34;crypt&#34;, you should just specify a plain-text password. If you specify &#39;*&#39;, 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&#39;s email preferences.</p>
<dt><a name="check"
><code class="code">check</code></a></dt>
<dd>
<p>Takes a username as its only argument. Throws an error if there is no user with that username. Returns a <code class="code">Bugzilla::User</code> object.</p>
<dt><a name="is_available_username"
><code class="code">is_available_username</code></a></dt>
<dd>
<p>Returns a boolean indicating whether or not the supplied username is already taken in Bugzilla.</p>
<p>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 &#34;old&#34; username that the user is changing from, here. Then, as long as it&#39;s the right user for that token, he can change his username to $username. (That is, this function will return a boolean true value).</p>
<dt><a name="login_to_id($login,_$throw_error)"
><code class="code">login_to_id($login, $throw_error)</code></a></dt>
<dd>
<p>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.</p>
<p>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.</p>
<p>This function can also be used when you want to just find out the userid of a user, but you don&#39;t want the full weight of Bugzilla::User.</p>
<p>However, consider using a Bugzilla::User object instead of this function if you need more information about the user than just their ID.</p>
<dt><a name="user_id_to_login($user_id)"
><code class="code">user_id_to_login($user_id)</code></a></dt>
<dd>
<p>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.</p>
<dt><a name="validate_password($passwd1,_$passwd2)"
><code class="code">validate_password($passwd1, $passwd2)</code></a></dt>
<dd>
<p>Returns true if a password is valid (i.e. meets Bugzilla&#39;s requirements for length and content), else returns false. Untaints <code class="code">$passwd1</code> if successful.</p>
<p>If a second password is passed in, this function also verifies that the two passwords match.</p>
</dd>
</dl>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="SEE_ALSO"
>SEE ALSO</a></h1>
<p><a href="../Bugzilla.html" class="podlinkpod"
>Bugzilla</a></p>
<p class="backlinkbottom"><b><a name="___bottom" href="../index.html" title="All Documents">&lt;&lt;</a></b></p>
<!-- end doc -->
</body></html>