# Convert to names, for later display
$values{'changer'} = $changer;
$values{'changername'} = Bugzilla::User->new_from_login($changer)->name;
- $values{'assigned_to'} = &::DBID_to_name($values{'assigned_to'});
- $values{'reporter'} = &::DBID_to_name($values{'reporter'});
+ $values{'assigned_to'} = user_id_to_login($values{'assigned_to'});
+ $values{'reporter'} = user_id_to_login($values{'reporter'});
if ($values{'qa_contact'}) {
- $values{'qa_contact'} = &::DBID_to_name($values{'qa_contact'});
+ $values{'qa_contact'} = user_id_to_login($values{'qa_contact'});
}
$values{'cc'} = join(', ', @cc_login_names);
$values{'estimated_time'} = format_time_decimal($values{'estimated_time'});
}
push @headerrel, 'None' if !scalar(@headerrel);
push @watchingrel, 'None' if !scalar(@watchingrel);
- push @watchingrel, map { &::DBID_to_name($_) } @$watchingRef;
+ push @watchingrel, map { user_id_to_login($_) } @$watchingRef;
$substs{"reasonsheader"} = join(" ", @headerrel);
$substs{"reasonswatchheader"} = join(" ", @watchingrel);
use base qw(Exporter);
@Bugzilla::User::EXPORT = qw(insert_new_user is_available_username
- login_to_id validate_password
+ login_to_id user_id_to_login validate_password
UserInGroup
USER_MATCH_MULTIPLE USER_MATCH_FAILED USER_MATCH_SUCCESS
MATCH_SKIP_CONFIRM
}
}
+sub user_id_to_login {
+ my $user_id = shift;
+ my $dbh = Bugzilla->dbh;
+
+ return '' unless ($user_id && detaint_natural($user_id));
+
+ my $login = $dbh->selectrow_array('SELECT login_name FROM profiles
+ WHERE userid = ?', undef, $user_id);
+ return $login || '';
+}
+
sub validate_password {
my ($password, $matchpassword) = @_;
However, consider using a Bugzilla::User object instead of this function
if you need more information about the user than just their ID.
+=item C<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.
+
=item C<validate_password($passwd1, $passwd2)>
Returns true if a password is valid (i.e. meets Bugzilla's
#
# You need to work with bug_email.pl the MIME::Parser installed.
#
-# $Id: bug_email.pl,v 1.40 2006/06/19 16:25:02 vladd%bugzilla.org Exp $
+# $Id: bug_email.pl,v 1.41 2006/06/19 17:30:24 lpsolit%gmail.com Exp $
###############################################################
# 02/12/2000 (SML)
$val = $Control{ $field };
- $val = DBID_to_name( $val ) if( $field =~ /reporter|assigned_to|qa_contact/ );
+ $val = user_id_to_login( $val ) if( $field =~ /reporter|assigned_to|qa_contact/ );
$tmp_reply .= sprintf( " \@%-15s = %-15s\n", $field, $val );
use Bugzilla::Classification;
use Bugzilla::Milestone;
use Bugzilla::Group;
+use Bugzilla::User;
# Shut up misguided -w warnings about "used only once". "use vars" just
# doesn't work for me.
foreach my $msg (@$msgs) {
MessageToMTA($msg);
}
- my $name = DBID_to_name($who);
+ my $name = user_id_to_login($who);
push(@toomanyvotes_list,
{id => $id, name => $name});
foreach my $msg (@$msgs) {
MessageToMTA($msg);
}
- my $name = DBID_to_name($who);
+ my $name = user_id_to_login($who);
push(@toomanytotalvotes_list,
{id => $bug_id, name => $name});
$::VersionTableLoaded = 1;
}
-sub DBID_to_name {
- my ($id) = (@_);
- return "__UNKNOWN__" if !defined $id;
- # $id should always be a positive integer
- if ($id =~ m/^([1-9][0-9]*)$/) {
- $id = $1;
- } else {
- $::cachedNameArray{$id} = "__UNKNOWN__";
- }
- if (!defined $::cachedNameArray{$id}) {
- PushGlobalSQLState();
- SendSQL("SELECT login_name FROM profiles WHERE userid = $id");
- my $r = FetchOneColumn();
- PopGlobalSQLState();
- if (!defined $r || $r eq "") {
- $r = "__UNKNOWN__";
- }
- $::cachedNameArray{$id} = $r;
- }
- return $::cachedNameArray{$id};
-}
-
# Returns a list of all the legal values for a field that has a
# list of legal values, like rep_platform or resolution.
sub get_legal_field_values {
$vars->{'field'} = 'component';
} elsif ($col eq 'assigned_to' || $col eq 'qa_contact') {
# Display the assignee or QA contact email address
- $vars->{'oldvalue'} = DBID_to_name($oldhash{$col});
- $vars->{'newvalue'} = DBID_to_name($formhash{$col});
+ $vars->{'oldvalue'} = user_id_to_login($oldhash{$col});
+ $vars->{'newvalue'} = user_id_to_login($formhash{$col});
$vars->{'field'} = $col;
} else {
$vars->{'oldvalue'} = $oldhash{$col};
# the old assignee can be notified
#
if ($col eq 'assigned_to') {
- $old = ($old) ? DBID_to_name($old) : "";
- $new = ($new) ? DBID_to_name($new) : "";
+ $old = ($old) ? user_id_to_login($old) : "";
+ $new = ($new) ? user_id_to_login($new) : "";
$origOwner = $old;
}
# ditto for the old qa contact
#
if ($col eq 'qa_contact') {
- $old = ($old) ? DBID_to_name($old) : "";
- $new = ($new) ? DBID_to_name($new) : "";
+ $old = ($old) ? user_id_to_login($old) : "";
+ $new = ($new) ? user_id_to_login($new) : "";
$origQaContact = $old;
}
|| !$cgi->param('confirm_add_duplicate')) {
# The reporter is oblivious to the existence of the new bug and is permitted access
# ... add 'em to the cc (and record activity)
- LogActivityEntry($duplicate,"cc","",DBID_to_name($reporter),
+ LogActivityEntry($duplicate,"cc","",user_id_to_login($reporter),
$whoid,$timestamp);
$dbh->do(q{INSERT INTO cc (who, bug_id) VALUES (?, ?)},
undef, $reporter, $duplicate);