diff options
-rw-r--r-- | Bugzilla/BugMail.pm | 8 | ||||
-rw-r--r-- | Bugzilla/User.pm | 19 | ||||
-rwxr-xr-x | contrib/bug_email.pl | 4 | ||||
-rwxr-xr-x | editproducts.cgi | 5 | ||||
-rw-r--r-- | globals.pl | 22 | ||||
-rwxr-xr-x | process_bug.cgi | 14 |
6 files changed, 34 insertions, 38 deletions
diff --git a/Bugzilla/BugMail.pm b/Bugzilla/BugMail.pm index af0bf9027..2c6f6af3e 100644 --- a/Bugzilla/BugMail.pm +++ b/Bugzilla/BugMail.pm @@ -186,10 +186,10 @@ sub ProcessOneBug { # 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'}); @@ -635,7 +635,7 @@ sub sendMail { } 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); diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm index 7bafd688a..c26f64332 100644 --- a/Bugzilla/User.pm +++ b/Bugzilla/User.pm @@ -51,7 +51,7 @@ use Bugzilla::Field; 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 @@ -1416,6 +1416,17 @@ sub login_to_id { } } +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) = @_; @@ -1841,6 +1852,12 @@ 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. +=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 diff --git a/contrib/bug_email.pl b/contrib/bug_email.pl index 66a87d038..546c08dc5 100755 --- a/contrib/bug_email.pl +++ b/contrib/bug_email.pl @@ -38,7 +38,7 @@ # # 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) @@ -1081,7 +1081,7 @@ END $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 ); diff --git a/editproducts.cgi b/editproducts.cgi index ea7430755..b21ceb8fd 100755 --- a/editproducts.cgi +++ b/editproducts.cgi @@ -44,6 +44,7 @@ use Bugzilla::Product; 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. @@ -907,7 +908,7 @@ if ($action eq 'update') { 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}); @@ -960,7 +961,7 @@ if ($action eq 'update') { 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}); diff --git a/globals.pl b/globals.pl index b4c71a28e..a1e87eec2 100644 --- a/globals.pl +++ b/globals.pl @@ -138,28 +138,6 @@ sub GetVersionTable { $::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 { diff --git a/process_bug.cgi b/process_bug.cgi index 3541650f3..ca72015a2 100755 --- a/process_bug.cgi +++ b/process_bug.cgi @@ -1587,8 +1587,8 @@ foreach my $id (@idlist) { $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}; @@ -2085,16 +2085,16 @@ foreach my $id (@idlist) { # 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; } @@ -2154,7 +2154,7 @@ foreach my $id (@idlist) { || !$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); |