summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorbugreport%peshkin.net <>2004-07-31 11:27:23 +0200
committerbugreport%peshkin.net <>2004-07-31 11:27:23 +0200
commit4c1db37570469aef2c7cc9f2ad9f859560ca8851 (patch)
tree17a519e7f08a85993b710ecd6d809bd9e4b40211 /Bugzilla
parent1ffd632931b05caea45f9c48079b455d156086be (diff)
downloadbugzilla-4c1db37570469aef2c7cc9f2ad9f859560ca8851.tar.gz
bugzilla-4c1db37570469aef2c7cc9f2ad9f859560ca8851.tar.xz
Bug 253588: Change Bugzilla->user to be usable even for a logged-out user
patch by erik,joel r=kiko a=justdave
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Auth/Login/WWW.pm4
-rwxr-xr-xBugzilla/Bug.pm6
-rw-r--r--Bugzilla/Error.pm2
-rw-r--r--Bugzilla/Search.pm6
-rw-r--r--Bugzilla/User.pm44
5 files changed, 42 insertions, 20 deletions
diff --git a/Bugzilla/Auth/Login/WWW.pm b/Bugzilla/Auth/Login/WWW.pm
index d18c758d9..def68df63 100644
--- a/Bugzilla/Auth/Login/WWW.pm
+++ b/Bugzilla/Auth/Login/WWW.pm
@@ -43,9 +43,7 @@ sub login {
# 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;
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm
index 53b8bd193..8c0998217 100755
--- a/Bugzilla/Bug.pm
+++ b/Bugzilla/Bug.pm
@@ -390,7 +390,7 @@ sub user {
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
@@ -399,12 +399,12 @@ sub user {
# 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;
diff --git a/Bugzilla/Error.pm b/Bugzilla/Error.pm
index 548cbb24c..25527f599 100644
--- a/Bugzilla/Error.pm
+++ b/Bugzilla/Error.pm
@@ -47,7 +47,7 @@ sub _throw_error {
$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;
diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm
index 00b213d54..6cff2940e 100644
--- a/Bugzilla/Search.pm
+++ b/Bugzilla/Search.pm
@@ -1172,7 +1172,7 @@ sub init {
" 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})) . ") ";
}
@@ -1183,7 +1183,7 @@ sub init {
$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) " .
@@ -1338,7 +1338,7 @@ sub getSQL {
sub pronoun {
my ($noun, $user) = (@_);
if ($noun eq "%user%") {
- if ($user) {
+ if ($user->id) {
return $user->id;
} else {
ThrowUserError('login_required_for_pronoun');
diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm
index e9b7fe0c4..8396d183f 100644
--- a/Bugzilla/User.pm
+++ b/Bugzilla/User.pm
@@ -18,7 +18,7 @@
# 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>
@@ -43,6 +43,9 @@ use Bugzilla::Constants;
sub new {
my $invocant = shift;
+ if (scalar @_ == 0) {
+ return $invocant->_create;
+ }
return $invocant->_create("userid=?", @_);
}
@@ -69,6 +72,16 @@ sub _create {
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);
@@ -90,13 +103,10 @@ sub _create {
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
@@ -133,6 +143,8 @@ sub showmybugslink { $_[0]->{showmybugslink}; }
sub identity {
my $self = shift;
+ return "" unless $self->id;
+
if (!defined $self->{identity}) {
$self->{identity} =
$self->{name} ? "$self->{name} <$self->{login}>" : $self->{login};
@@ -144,6 +156,8 @@ sub identity {
sub nick {
my $self = shift;
+ return "" unless $self->id;
+
if (!defined $self->{nick}) {
$self->{nick} = (split(/@/, $self->{login}, 2))[0];
}
@@ -155,6 +169,7 @@ sub queries {
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
@@ -186,6 +201,7 @@ sub groups {
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
@@ -209,6 +225,7 @@ sub in_group {
# 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
@@ -232,6 +249,7 @@ sub in_group {
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;
@@ -244,6 +262,7 @@ sub visible_groups_direct {
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})));
@@ -265,6 +284,7 @@ sub derive_groups {
my ($self, $already_locked) = @_;
my $id = $self->id;
+ return unless $id;
my $dbh = Bugzilla->dbh;
@@ -352,6 +372,7 @@ sub can_bless {
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
@@ -729,6 +750,7 @@ sub email_prefs {
# 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
@@ -820,8 +842,10 @@ L<Bugzilla-E<gt>user|Bugzilla/"user">.
=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