aboutsummaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
Diffstat (limited to 'Bugzilla')
-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
5 files changed, 38 insertions, 7 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>