my $_user;
sub user {
my $class = shift;
+
+ if (not defined $_user) {
+ $_user = new Bugzilla::User;
+ }
+
return $_user;
}
sub logout {
my ($class, $option) = @_;
- if (! $_user) {
- # If we're not logged in, go away
- return;
- }
- $option = LOGOUT_CURRENT unless defined $option;
+ # If we're not logged in, go away
+ return unless user->id;
+
+ $option = LOGOUT_CURRENT unless defined $option;
Bugzilla::Auth::Login::WWW->logout($_user, $option);
}
# Avoid double-logins, which may confuse the auth code
# (double cookies, odd compat code settings, etc)
- if (defined $user) {
- return $user;
- }
+ return $user if $user->id;
$type = LOGIN_NORMAL unless defined $type;
use Bugzilla;
my @movers = map { trim $_ } split(",", Param("movers"));
- my $canmove = Param("move-enabled") && Bugzilla->user &&
+ my $canmove = Param("move-enabled") && Bugzilla->user->id &&
(lsearch(\@movers, Bugzilla->user->login) != -1);
# In the below, if the person hasn't logged in, then we treat them
# Display everything as if they have all the permissions in the
# world; their permissions will get checked when they log in and
# actually try to make the change.
- my $privileged = (!Bugzilla->user)
+ my $privileged = (!Bugzilla->user->id)
|| Bugzilla->user->in_group("editbugs")
|| Bugzilla->user->id == $self->{'assigned_to'}{'id'}
|| (Param('useqacontact') && $self->{'qa_contact'} &&
Bugzilla->user->id == $self->{'qa_contact'}{'id'});
- my $isreporter = Bugzilla->user &&
+ my $isreporter = Bugzilla->user->id &&
Bugzilla->user->id == $self->{'reporter'}{'id'};
my $canedit = $privileged || $isreporter;
$mesg .= "\n[$$] " . time2str("%D %H:%M:%S ", time());
$mesg .= "$name $error ";
$mesg .= "$ENV{REMOTE_ADDR} " if $ENV{REMOTE_ADDR};
- $mesg .= Bugzilla->user->login if Bugzilla->user;
+ $mesg .= Bugzilla->user->login;
$mesg .= "\n";
my %params = Bugzilla->cgi->Vars;
$Data::Dumper::Useqq = 1;
" LEFT JOIN bug_group_map " .
" ON bug_group_map.bug_id = bugs.bug_id ";
- if ($user) {
+ if ($user->id) {
if (%{$user->groups}) {
$query .= " AND bug_group_map.group_id NOT IN (" . join(',', values(%{$user->groups})) . ") ";
}
$query .= " WHERE " . join(' AND ', (@wherepart, @andlist)) .
" AND ((bug_group_map.group_id IS NULL)";
- if ($user) {
+ if ($user->id) {
my $userid = $user->id;
$query .= " OR (bugs.reporter_accessible = 1 AND bugs.reporter = $userid) " .
" OR (bugs.cclist_accessible = 1 AND cc.who IS NOT NULL) " .
sub pronoun {
my ($noun, $user) = (@_);
if ($noun eq "%user%") {
- if ($user) {
+ if ($user->id) {
return $user->id;
} else {
ThrowUserError('login_required_for_pronoun');
# Rights Reserved.
#
# Contributor(s): Myk Melez <myk@mozilla.org>
-# Erik Stambaugh <not_erik@dasbistro.com>
+# Erik Stambaugh <erik@dasbistro.com>
# Bradley Baetz <bbaetz@acm.org>
# Joel Peshkin <bugreport@peshkin.net>
sub new {
my $invocant = shift;
+ if (scalar @_ == 0) {
+ return $invocant->_create;
+ }
return $invocant->_create("userid=?", @_);
}
my $cond = shift;
my $val = shift;
+ # Allow invocation with no parameters to create a blank object
+ my $self = {
+ 'id' => 0,
+ 'name' => '',
+ 'login' => '',
+ 'showmybugslink' => 0,
+ };
+ bless ($self, $class);
+ return $self unless $cond;
+
# We're checking for validity here, so any value is OK
trick_taint($val);
return undef unless defined $id;
- my $self = { id => $id,
- name => $name,
- login => $login,
- showmybugslink => $mybugslink,
- };
-
- bless ($self, $class);
+ $self->{'id'} = $id;
+ $self->{'name'} = $name;
+ $self->{'login'} = $login;
+ $self->{'showmybugslink'} = $mybugslink;
# Now update any old group information if needed
my $result = $dbh->selectrow_array(q{SELECT 1
sub identity {
my $self = shift;
+ return "" unless $self->id;
+
if (!defined $self->{identity}) {
$self->{identity} =
$self->{name} ? "$self->{name} <$self->{login}>" : $self->{login};
sub nick {
my $self = shift;
+ return "" unless $self->id;
+
if (!defined $self->{nick}) {
$self->{nick} = (split(/@/, $self->{login}, 2))[0];
}
my $self = shift;
return $self->{queries} if defined $self->{queries};
+ return [] unless $self->id;
my $dbh = Bugzilla->dbh;
my $sth = $dbh->prepare(q{ SELECT name, query, linkinfooter
my $self = shift;
return $self->{groups} if defined $self->{groups};
+ return {} unless $self->id;
my $dbh = Bugzilla->dbh;
my $groups = $dbh->selectcol_arrayref(q{SELECT DISTINCT groups.name, group_id
# If we already have the info, just return it.
return defined($self->{groups}->{$group}) if defined $self->{groups};
+ return 0 unless $self->id;
# Otherwise, go check for it
sub visible_groups_inherited {
my $self = shift;
return $self->{visible_groups_inherited} if defined $self->{visible_groups_inherited};
+ return [] unless $self->id;
my @visgroups = @{$self->visible_groups_direct};
@visgroups = flatten_group_membership(@visgroups);
$self->{visible_groups_inherited} = \@visgroups;
my $self = shift;
my @visgroups = ();
return $self->{visible_groups_direct} if defined $self->{visible_groups_direct};
+ return [] unless $self->id;
my $dbh = Bugzilla->dbh;
my $glist = join(',',(-1,values(%{$self->groups})));
my ($self, $already_locked) = @_;
my $id = $self->id;
+ return unless $id;
my $dbh = Bugzilla->dbh;
my $self = shift;
return $self->{can_bless} if defined $self->{can_bless};
+ return 0 unless $self->id;
my $dbh = Bugzilla->dbh;
# First check if the user can explicitly bless a group
# Get or set (not implemented) the user's email notification preferences.
my $self = shift;
+ return {} unless $self->id;
# If the calling code is setting the email preferences, update the object
# but don't do anything else. This needs to write email preferences back
=item C<new($userid)>
-Creates a new C<Bugzilla::User> object for the given user id. Returns
-C<undef> if no matching user is found.
+Creates a new C{Bugzilla::User> object for the given user id. If no user
+id was given, a blank object is created with no user attributes.
+
+If an id was given but there was no matching user found, undef is returned.
=begin undocumented
sub LookupNamedQuery {
my ($name) = @_;
Bugzilla->login(LOGIN_REQUIRED);
- my $userid = DBNameToIdAndCheck(Bugzilla->user->login);
+ my $userid = Bugzilla->user->id;
my $qname = SqlQuote($name);
SendSQL("SELECT query FROM namedqueries WHERE userid = $userid AND name = $qname");
my $result = FetchOneColumn();
}
elsif ($::FORM{'remaction'} eq "forget") {
Bugzilla->login(LOGIN_REQUIRED);
- my $userid = DBNameToIdAndCheck(Bugzilla->user->login);
+ my $userid = Bugzilla->user->id;
my $qname = SqlQuote($::FORM{'namedcmd'});
SendSQL("DELETE FROM namedqueries WHERE userid = $userid AND name = $qname");
elsif (($::FORM{'cmdtype'} eq "doit") && $::FORM{'remtype'}) {
if ($::FORM{'remtype'} eq "asdefault") {
Bugzilla->login(LOGIN_REQUIRED);
- my $userid = DBNameToIdAndCheck(Bugzilla->user->login);
+ my $userid = Bugzilla->user->id;
my $qname = SqlQuote($::defaultqueryname);
my $qbuffer = SqlQuote($::buffer);
}
elsif ($::FORM{'remtype'} eq "asnamed") {
Bugzilla->login(LOGIN_REQUIRED);
- my $userid = DBNameToIdAndCheck(Bugzilla->user->login);
+ my $userid = Bugzilla->user->id;
my $name = trim($::FORM{'newqueryname'});
$name || ThrowUserError("query_name_missing");
$vars->{'order'} = $order;
# The user's login account name (i.e. email address).
-my $login = Bugzilla->user ? Bugzilla->user->login : "";
+my $login = Bugzilla->user->login;
$vars->{'caneditbugs'} = UserInGroup('editbugs');
if (AnyEntryGroups()) {
# OK, now only add products the user can see
- Bugzilla->login(LOGIN_REQUIRED) unless Bugzilla->user;
+ Bugzilla->login(LOGIN_REQUIRED);
foreach my $p (@::legal_product) {
if (CanEnterProduct($p)) {
$products{$p} = $::proddesc{$p};
- Use Bugzilla->user->login in place of $::COOKIE{Bugzilla_login}
- You can tell if there's a user logged in or not by checking if
- Bugzilla->user exists rather than looking for $::userid==0
+ Bugzilla->user->id != 0 rather than looking for $::userid != 0
Recommended Practice for the Upgrade
my $query = "SELECT group_id FROM group_control_map " .
"WHERE product_id = $productid " .
"AND canedit != 0 ";
- if (defined Bugzilla->user && %{Bugzilla->user->groups}) {
+ if (%{Bugzilla->user->groups}) {
$query .= "AND group_id NOT IN(" .
join(',', values(%{Bugzilla->user->groups})) . ") ";
}
"LEFT JOIN group_control_map " .
"ON group_control_map.product_id = products.id " .
"AND group_control_map.entry != 0 ";
- if (defined Bugzilla->user && %{Bugzilla->user->groups}) {
+ if (%{Bugzilla->user->groups}) {
$query .= "AND group_id NOT IN(" .
join(',', values(%{Bugzilla->user->groups})) . ") ";
}
$query .= "AND group_control_map.membercontrol = " .
CONTROLMAPMANDATORY . " ";
}
- if (defined Bugzilla->user && %{Bugzilla->user->groups}) {
+ if (%{Bugzilla->user->groups}) {
$query .= "AND group_id NOT IN(" .
join(',', values(%{Bugzilla->user->groups})) . ") ";
}
die "UserInGroup no longer takes a second parameter.";
}
- return defined Bugzilla->user && defined Bugzilla->user->groups->{$_[0]};
+ return defined Bugzilla->user->groups->{$_[0]};
}
sub UserCanBlessGroup {
Bugzilla->login();
}
-my $user = Bugzilla->user;
-my $userid = $user ? $user->id : 0;
+my $userid = Bugzilla->user->id;
# Backwards compatibility hack -- if there are any of the old QUERY_*
# cookies around, and we are logged in, then move them into the database
# and nuke the cookie. This is required for Bugzilla 2.8 and earlier.
-if ($user) {
+if ($userid) {
my @oldquerycookies;
foreach my $i ($cgi->cookie()) {
if ($i =~ /^QUERY_(.*)$/) {
}
if ($::FORM{'nukedefaultquery'}) {
- if ($user) {
+ if ($userid) {
SendSQL("DELETE FROM namedqueries " .
"WHERE userid = $userid AND name = '$::defaultqueryname'");
}
}
my $userdefaultquery;
-if ($user) {
+if ($userid) {
SendSQL("SELECT query FROM namedqueries " .
"WHERE userid = $userid AND name = '$::defaultqueryname'");
$userdefaultquery = FetchOneColumn();
$default{'charts'} = \@charts;
# Named queries
-if ($user) {
+if ($userid) {
my @namedqueries;
SendSQL("SELECT name FROM namedqueries " .
"WHERE userid = $userid AND name != '$::defaultqueryname' " .
<bugzilla version="[% VERSION %]"
urlbase="[% Param('urlbase') %]"
maintainer="[% Param('maintainer') FILTER xml %]"
-[% IF user %]
+[% IF user.id %]
exporter="[% user.login FILTER xml %]"
[% END %]
>
<a href="report.cgi">Reports</a>
- [% IF user %]
+ [% IF user.id %]
[% email = user.login FILTER url_quote %]
| <a href="request.cgi?requester=[% email %]&requestee=[% email %]&do_union=1&group=type">My Requests</a>
[% ELSE %]
| <a href="request.cgi">Requests</a>
[% END %]
- [% IF user && Param('usevotes') %]
+ [% IF user.id && Param('usevotes') %]
| <a href="votes.cgi?action=show_user">My Votes</a>
[% END %]
<text class="text-link" onclick="load_relative_url('enter_bug.cgi')" value="new [% terms.bug %]"/>
<separator class="thin"/>
-[% IF user %]
+[% IF user.id %]
<text class="text-link" onclick="load_relative_url('userprefs.cgi')" value="edit prefs"/>
[%- IF user.groups.tweakparams %]
<text class="text-link" onclick="load_relative_url('editparams.cgi')" value="edit params"/>
my $name = $cgi->param('user') || Bugzilla->user->login;
my $who = DBNameToIdAndCheck($name);
- my $userid = Bugzilla->user ? Bugzilla->user->id : 0;
+ my $userid = Bugzilla->user->id;
- my $canedit = 1 if (Bugzilla->user &&
- $name eq Bugzilla->user->login);
+ my $canedit = 1 if ($userid && $name eq Bugzilla->user->login);
SendSQL("LOCK TABLES bugs READ, products READ, votes WRITE,
cc READ, bug_group_map READ, user_group_map READ,