}
else {
if ($user_id =~ /^\@/) {
- $user_id = &::DBname_to_id($user_id);
+ $user_id = login_to_id($user_id);
}
}
# 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;
# 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);
}
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);
}
}
use Bugzilla::Util;
use Bugzilla::Constants;
use Bugzilla::Group;
+use Bugzilla::User;
use Date::Format;
use Date::Parse;
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)
}
# Bradley Baetz <bbaetz@acm.org>
# Joel Peshkin <bugreport@peshkin.net>
# Byron Jones <bugzilla@glob.com.au>
+# Max Kanat-Alexander <mkanat@kerio.com>
################################################################################
# Module Initialization
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
sub is_available_username ($;$) {
my ($username, $old_username) = @_;
- if(&::DBname_to_id($username) != 0) {
+ if(login_to_id($username) != 0) {
return 0;
}
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__
=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>
#
# 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)
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
# 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=" .
}
-$Control{'reporter'} = DBname_to_id($Control{'reporter'});
+$Control{'reporter'} = login_to_id($Control{'reporter'});
if ( ! $Control{'reporter'} ) {
BugMailError( 1, "Could not resolve reporter !\n" );
}
#
# 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.
require "globals.pl";
use Bugzilla::BugMail;
+use Bugzilla::User;
sub usage {
print STDERR "Usage: $0 bug_id user_email\n";
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();
}
use Bugzilla::Config qw(:DEFAULT $datadir);
use Bugzilla::Series;
use Bugzilla::Util;
+use Bugzilla::User;
use vars qw($template $vars);
exit;
}
- my $initialownerid = DBname_to_id ($initialowner);
+ my $initialownerid = login_to_id ($initialowner);
if (!$initialownerid) {
ThrowUserError('component_need_valid_initialowner',
{'name' => $component});
}
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',
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',
}
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',
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) {
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) {
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
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.
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;
}
use Data::Dumper;
$Data::Dumper::Useqq = 1;
use Bugzilla::BugMail;
+use Bugzilla::User;
require "CGI.pl";
require "globals.pl";
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";
$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");
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) );
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 {
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) .")");
}
}