summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xBugzilla/Bug.pm2
-rw-r--r--Bugzilla/BugMail.pm2
-rw-r--r--Bugzilla/Flag.pm4
-rw-r--r--Bugzilla/Search.pm3
-rw-r--r--Bugzilla/User.pm34
-rwxr-xr-xcontrib/bug_email.pl7
-rw-r--r--contrib/sendbugmail.pl5
-rwxr-xr-xeditcomponents.cgi9
-rwxr-xr-xeditusers.cgi4
-rwxr-xr-xeditwhines.cgi2
-rw-r--r--globals.pl18
-rwxr-xr-ximportxml.pl13
12 files changed, 62 insertions, 41 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm
index 2f1df58bd..9092ddf89 100755
--- a/Bugzilla/Bug.pm
+++ b/Bugzilla/Bug.pm
@@ -131,7 +131,7 @@ sub initBug {
}
else {
if ($user_id =~ /^\@/) {
- $user_id = &::DBname_to_id($user_id);
+ $user_id = login_to_id($user_id);
}
}
diff --git a/Bugzilla/BugMail.pm b/Bugzilla/BugMail.pm
index bfe1c897e..df734ef6f 100644
--- a/Bugzilla/BugMail.pm
+++ b/Bugzilla/BugMail.pm
@@ -627,7 +627,7 @@ sub filterEmailGroup ($$$) {
# but the code that was here before I re-wrote it allows this),
# then we do not have any preferences for them, so assume the
# default preference is to receive all mail.
- my $userid = DBname_to_id($user);
+ my $userid = login_to_id($user);
if (!$userid) {
push(@recipients, $user);
next;
diff --git a/Bugzilla/Flag.pm b/Bugzilla/Flag.pm
index ffed79bde..4b5f76fb0 100644
--- a/Bugzilla/Flag.pm
+++ b/Bugzilla/Flag.pm
@@ -449,7 +449,7 @@ sub modify {
# Get the requestee, if any.
my $requestee_id = "NULL";
if ($requestee_email) {
- $requestee_id = &::DBname_to_id($requestee_email);
+ $requestee_id = login_to_id($requestee_email);
$flag->{'requestee'} = new Bugzilla::User($requestee_id);
}
@@ -531,7 +531,7 @@ sub FormToNewFlags {
if ($status eq "?") {
my $requestee = $data->{"requestee_type-$type_id"};
if ($requestee) {
- my $requestee_id = &::DBname_to_id($requestee);
+ my $requestee_id = login_to_id($requestee);
$flag->{'requestee'} = new Bugzilla::User($requestee_id);
}
}
diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm
index 8a08ef618..aedb2b2b4 100644
--- a/Bugzilla/Search.pm
+++ b/Bugzilla/Search.pm
@@ -41,6 +41,7 @@ use Bugzilla::Error;
use Bugzilla::Util;
use Bugzilla::Constants;
use Bugzilla::Group;
+use Bugzilla::User;
use Date::Format;
use Date::Parse;
@@ -1414,7 +1415,7 @@ sub ListIDsForEmail {
if ($type eq 'anyexact') {
foreach my $w (split(/,/, $email)) {
$w = trim($w);
- my $id = &::DBname_to_id($w);
+ my $id = login_to_id($w);
if ($id > 0) {
push(@list,$id)
}
diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm
index 0a67400b3..8809d80dd 100644
--- a/Bugzilla/User.pm
+++ b/Bugzilla/User.pm
@@ -22,6 +22,7 @@
# Bradley Baetz <bbaetz@acm.org>
# Joel Peshkin <bugreport@peshkin.net>
# Byron Jones <bugzilla@glob.com.au>
+# Max Kanat-Alexander <mkanat@kerio.com>
################################################################################
# Module Initialization
@@ -40,7 +41,9 @@ use Bugzilla::Constants;
use Bugzilla::Auth;
use base qw(Exporter);
-@Bugzilla::User::EXPORT = qw(insert_new_user is_available_username);
+@Bugzilla::User::EXPORT = qw(insert_new_user is_available_username
+ login_to_id
+);
################################################################################
# Functions
@@ -961,7 +964,7 @@ sub insert_new_user ($$) {
sub is_available_username ($;$) {
my ($username, $old_username) = @_;
- if(&::DBname_to_id($username) != 0) {
+ if(login_to_id($username) != 0) {
return 0;
}
@@ -992,6 +995,19 @@ sub is_available_username ($;$) {
return 1;
}
+sub login_to_id ($) {
+ my ($login) = (@_);
+ my $dbh = Bugzilla->dbh;
+ my $user_id = $dbh->selectrow_array(
+ "SELECT userid FROM profiles WHERE login_name = ?", undef, $login);
+ # $user_id should be a positive integer, this makes Taint mode happy
+ if (defined $user_id && detaint_natural($user_id)) {
+ return $user_id;
+ } else {
+ return 0;
+ }
+}
+
1;
__END__
@@ -1232,6 +1248,20 @@ Params: $username (scalar, string) - The full login name of the username
=back
+=item C<login_to_id($login)>
+
+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 will return 0.
+
+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.
+
=head1 SEE ALSO
L<Bugzilla|Bugzilla>
diff --git a/contrib/bug_email.pl b/contrib/bug_email.pl
index 7fb6b533c..ed7e8143a 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.24 2005/02/18 16:01:48 mkanat%kerio.com Exp $
+# $Id: bug_email.pl,v 1.25 2005/02/24 23:42:48 mkanat%kerio.com Exp $
###############################################################
# 02/12/2000 (SML)
@@ -94,6 +94,7 @@ use lib ".";
use lib "../";
use Bugzilla::Constants;
use Bugzilla::BugMail;
+use Bugzilla::User;
my @mailerrors = (); # Buffer for Errors in the mail
my @mailwarnings = (); # Buffer for Warnings found in the mail
@@ -920,7 +921,7 @@ $Control{'component'} = $Component;
# otherwise, retrieve it from the database.
if ( defined($Control{'assigned_to'})
&& $Control{'assigned_to'} !~ /^\s*$/ ) {
- $Control{'assigned_to'} = DBname_to_id($Control{'assigned_to'});
+ $Control{'assigned_to'} = login_to_id($Control{'assigned_to'});
} else {
SendSQL("select initialowner from components, products where " .
" components.product_id=products.id AND products.name=" .
@@ -940,7 +941,7 @@ if ( $Control{'assigned_to'} == 0 ) {
}
-$Control{'reporter'} = DBname_to_id($Control{'reporter'});
+$Control{'reporter'} = login_to_id($Control{'reporter'});
if ( ! $Control{'reporter'} ) {
BugMailError( 1, "Could not resolve reporter !\n" );
}
diff --git a/contrib/sendbugmail.pl b/contrib/sendbugmail.pl
index 8e00ff49c..ad9642895 100644
--- a/contrib/sendbugmail.pl
+++ b/contrib/sendbugmail.pl
@@ -4,7 +4,7 @@
#
# Nick Barnes, Ravenbrook Limited, 2004-04-01.
#
-# $Id: sendbugmail.pl,v 1.2 2004/11/20 12:35:17 jocuri%softhome.net Exp $
+# $Id: sendbugmail.pl,v 1.3 2005/02/24 23:42:48 mkanat%kerio.com Exp $
#
# Bugzilla email script for Bugzilla 2.17.4 and later. Invoke this to send
# bugmail for a bug which has been changed directly in the database.
@@ -18,6 +18,7 @@ use lib qw(.);
require "globals.pl";
use Bugzilla::BugMail;
+use Bugzilla::User;
sub usage {
print STDERR "Usage: $0 bug_id user_email\n";
@@ -53,7 +54,7 @@ if ($changer !~ /$match/) {
print STDERR "Changer \"$changer\" doesn't match email regular expression.\n";
usage();
}
-if(!DBname_to_id($changer)) {
+if(!login_to_id($changer)) {
print STDERR "\"$changer\" is not a login ID.\n";
usage();
}
diff --git a/editcomponents.cgi b/editcomponents.cgi
index 08cfab14c..12a25905d 100755
--- a/editcomponents.cgi
+++ b/editcomponents.cgi
@@ -35,6 +35,7 @@ use Bugzilla::Constants;
use Bugzilla::Config qw(:DEFAULT $datadir);
use Bugzilla::Series;
use Bugzilla::Util;
+use Bugzilla::User;
use vars qw($template $vars);
@@ -296,7 +297,7 @@ if ($action eq 'new') {
exit;
}
- my $initialownerid = DBname_to_id ($initialowner);
+ my $initialownerid = login_to_id ($initialowner);
if (!$initialownerid) {
ThrowUserError('component_need_valid_initialowner',
{'name' => $component});
@@ -304,7 +305,7 @@ if ($action eq 'new') {
}
my $initialqacontact = trim($cgi->param('initialqacontact') || '');
- my $initialqacontactid = DBname_to_id ($initialqacontact);
+ my $initialqacontactid = login_to_id ($initialqacontact);
if (Param('useqacontact')) {
if (!$initialqacontactid && $initialqacontact ne '') {
ThrowUserError('component_need_valid_initialqacontact',
@@ -600,7 +601,7 @@ if ($action eq 'update') {
if ($initialowner ne $initialownerold) {
- my $initialownerid = DBname_to_id($initialowner);
+ my $initialownerid = login_to_id($initialowner);
unless ($initialownerid) {
$dbh->bz_unlock_tables(UNLOCK_ABORT);
ThrowUserError('component_need_valid_initialowner',
@@ -618,7 +619,7 @@ if ($action eq 'update') {
}
if (Param('useqacontact') && $initialqacontact ne $initialqacontactold) {
- my $initialqacontactid = DBname_to_id($initialqacontact);
+ my $initialqacontactid = login_to_id($initialqacontact);
if (!$initialqacontactid && $initialqacontact ne '') {
$dbh->bz_unlock_tables(UNLOCK_ABORT);
ThrowUserError('component_need_valid_initialqacontact',
diff --git a/editusers.cgi b/editusers.cgi
index 9a6de0d17..c6b342efd 100755
--- a/editusers.cgi
+++ b/editusers.cgi
@@ -536,7 +536,7 @@ if ($action eq 'del') {
SendSQL("SELECT products.name, components.name " .
"FROM products, components " .
"WHERE products.id = components.product_id " .
- " AND initialowner=" . DBname_to_id($user));
+ " AND initialowner=" . login_to_id($user));
$found = 0;
while (MoreSQLData()) {
if ($found) {
@@ -561,7 +561,7 @@ if ($action eq 'del') {
SendSQL("SELECT products.name, components.name " .
"FROM products, components " .
"WHERE products.id = components.product_id " .
- " AND initialqacontact=" . DBname_to_id($user));
+ " AND initialqacontact=" . login_to_id($user));
$found = 0;
while (MoreSQLData()) {
if ($found) {
diff --git a/editwhines.cgi b/editwhines.cgi
index b9808941a..013ee0df4 100755
--- a/editwhines.cgi
+++ b/editwhines.cgi
@@ -248,7 +248,7 @@ if ($cgi->param('update')) {
my $emailregexp = Param('emailregexp');
$mailto =~ /($emailregexp)/;
$mailto =~ $1;
- $mailto_id = DBname_to_id($mailto);
+ $mailto_id = login_to_id($mailto);
}
elsif ($mailto_type == MAILTO_GROUP) {
# detaint the group parameter
diff --git a/globals.pl b/globals.pl
index 100c8fab6..2d01cb5f1 100644
--- a/globals.pl
+++ b/globals.pl
@@ -37,6 +37,7 @@ use Bugzilla::Util;
use Bugzilla::Config qw(:DEFAULT ChmodDataFile $localconfig $datadir);
use Bugzilla::BugMail;
use Bugzilla::Auth;
+use Bugzilla::User;
# Shut up misguided -w warnings about "used only once". For some reason,
# "use vars" chokes on me when I try it here.
@@ -654,24 +655,9 @@ sub DBID_to_name {
return $::cachedNameArray{$id};
}
-sub DBname_to_id {
- my ($name) = (@_);
- PushGlobalSQLState();
- SendSQL("select userid from profiles where login_name = @{[SqlQuote($name)]}");
- my $r = FetchOneColumn();
- PopGlobalSQLState();
- # $r should be a positive integer, this makes Taint mode happy
- if (defined $r && $r =~ m/^([1-9][0-9]*)$/) {
- return $1;
- } else {
- return 0;
- }
-}
-
-
sub DBNameToIdAndCheck {
my ($name) = (@_);
- my $result = DBname_to_id($name);
+ my $result = login_to_id($name);
if ($result > 0) {
return $result;
}
diff --git a/importxml.pl b/importxml.pl
index 3b3b24a17..9ff962635 100755
--- a/importxml.pl
+++ b/importxml.pl
@@ -67,6 +67,7 @@ use XML::Parser;
use Data::Dumper;
$Data::Dumper::Useqq = 1;
use Bugzilla::BugMail;
+use Bugzilla::User;
require "CGI.pl";
require "globals.pl";
@@ -202,7 +203,7 @@ unless ( Param("move-enabled") ) {
exit;
}
-my $exporterid = DBname_to_id($exporter);
+my $exporterid = login_to_id($exporter);
if ( ! $exporterid ) {
my $subject = "Bug import error: invalid exporter";
my $message = "The user <$tree->[1][0]->{'exporter'}> who tried to move\n";
@@ -504,7 +505,7 @@ for (my $k=1 ; $k <= $bugqty ; $k++) {
$err .= ". Setting to default severity \"normal\".\n";
}
- my $reporterid = DBname_to_id($bug_fields{'reporter'});
+ my $reporterid = login_to_id($bug_fields{'reporter'});
if ( ($bug_fields{'reporter'}) && ( $reporterid ) ) {
push (@values, SqlQuote($reporterid));
push (@query, "reporter");
@@ -523,8 +524,8 @@ for (my $k=1 ; $k <= $bugqty ; $k++) {
my $changed_owner = 0;
if ( ($bug_fields{'assigned_to'}) &&
- ( DBname_to_id($bug_fields{'assigned_to'})) ) {
- push (@values, SqlQuote(DBname_to_id($bug_fields{'assigned_to'})));
+ ( login_to_id($bug_fields{'assigned_to'})) ) {
+ push (@values, SqlQuote(login_to_id($bug_fields{'assigned_to'})));
push (@query, "assigned_to");
} else {
push (@values, SqlQuote($exporterid) );
@@ -587,7 +588,7 @@ for (my $k=1 ; $k <= $bugqty ; $k++) {
if (Param("useqacontact")) {
my $qa_contact;
if ( (defined $bug_fields{'qa_contact'}) &&
- ($qa_contact = DBname_to_id($bug_fields{'qa_contact'})) ){
+ ($qa_contact = login_to_id($bug_fields{'qa_contact'})) ){
push (@values, $qa_contact);
push (@query, "qa_contact");
} else {
@@ -615,7 +616,7 @@ for (my $k=1 ; $k <= $bugqty ; $k++) {
if (defined $bug_fields{'cc'}) {
foreach my $person (split(/[ ,]/, $bug_fields{'cc'})) {
my $uid;
- if ( ($person ne "") && ($uid = DBname_to_id($person)) ) {
+ if ( ($person ne "") && ($uid = login_to_id($person)) ) {
SendSQL("insert into cc (bug_id, who) values ($id, " . SqlQuote($uid) .")");
}
}