From a0256cf7a6d211d0b38a6fa158be2420275e63ff Mon Sep 17 00:00:00 2001 From: Frédéric Buclin Date: Mon, 5 Dec 2011 18:26:32 +0100 Subject: Bug 550299: User fields are left blank in buglists and whines when local user accounts are used (i.e. they have no @company.com suffix) r/a=mkanat --- Bugzilla/Search.pm | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'Bugzilla/Search.pm') diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm index 6bbf4ab42..77299ff38 100644 --- a/Bugzilla/Search.pm +++ b/Bugzilla/Search.pm @@ -55,6 +55,7 @@ use Bugzilla::Keyword; use Data::Dumper; use Date::Format; use Date::Parse; +use Scalar::Util qw(blessed); use List::MoreUtils qw(all part uniq); use POSIX qw(INT_MAX); use Storable qw(dclone); @@ -509,9 +510,14 @@ use constant COLUMN_JOINS => { # and we don't want it to happen at compile time, so we have it as a # subroutine. sub COLUMNS { + my $invocant = shift; + my $user = blessed($invocant) ? $invocant->_user : Bugzilla->user; my $dbh = Bugzilla->dbh; my $cache = Bugzilla->request_cache; - return $cache->{search_columns} if defined $cache->{search_columns}; + + if (defined $cache->{search_columns}->{$user->id}) { + return $cache->{search_columns}->{$user->id}; + } # These are columns that don't exist in fielddefs, but are valid buglist # columns. (Also see near the bottom of this function for the definition @@ -567,10 +573,7 @@ sub COLUMNS { foreach my $col (@email_fields) { my $sql = "map_${col}.login_name"; - # XXX This needs to be generated inside an accessor instead, - # probably, because it should use $self->_user to determine - # this, not Bugzilla->user. - if (!Bugzilla->user->id) { + if (!$user->id) { $sql = $dbh->sql_string_until($sql, $dbh->quote('@')); } $special_sql{$col} = $sql; @@ -610,7 +613,10 @@ sub COLUMNS { } sub REPORT_COLUMNS { - my $columns = dclone(COLUMNS); + my $invocant = shift; + my $user = blessed($invocant) ? $invocant->_user : Bugzilla->user; + + my $columns = dclone(blessed($invocant) ? $invocant->COLUMNS : COLUMNS); # There's no reason to support reporting on unique fields. # Also, some other fields don't make very good reporting axises, # or simply don't work with the current reporting system. @@ -625,7 +631,7 @@ sub REPORT_COLUMNS { # If you're not a time-tracker, you can't use time-tracking # columns. - if (!Bugzilla->user->is_timetracker) { + if (!$user->is_timetracker) { push(@no_report_columns, TIMETRACKING_FIELDS); } @@ -841,7 +847,7 @@ sub _sql_select { my $alias = $column; # Aliases cannot contain dots in them. We convert them to underscores. $alias =~ s/\./_/g; - my $sql = COLUMNS->{$column}->{name} . " AS $alias"; + my $sql = $self->COLUMNS->{$column}->{name} . " AS $alias"; push(@sql_fields, $sql); } return @sql_fields; @@ -1190,7 +1196,7 @@ sub _sql_group_by { my @extra_group_by; foreach my $column ($self->_select_columns) { next if $self->_skip_group_by->{$column}; - my $sql = COLUMNS->{$column}->{name}; + my $sql = $self->COLUMNS->{$column}->{name}; push(@extra_group_by, $sql); } @@ -2299,11 +2305,11 @@ sub _content_matches { # # We build the relevance SQL by modifying the COLUMNS list directly, # which is kind of a hack but works. - my $current = COLUMNS->{'relevance'}->{name}; + my $current = $self->COLUMNS->{'relevance'}->{name}; $current = $current ? "$current + " : ''; # For NOT searches, we just add 0 to the relevance. my $select_term = $operator =~ /not/ ? 0 : "($current$rterm1 + $rterm2)"; - COLUMNS->{'relevance'}->{name} = $select_term; + $self->COLUMNS->{'relevance'}->{name} = $select_term; } sub _long_descs_count { @@ -2353,13 +2359,13 @@ sub _work_time_changedbefore_after { sub _work_time { my ($self, $args) = @_; $self->_add_extra_column('actual_time'); - $args->{full_field} = COLUMNS->{actual_time}->{name}; + $args->{full_field} = $self->COLUMNS->{actual_time}->{name}; } sub _percentage_complete { my ($self, $args) = @_; - $args->{full_field} = COLUMNS->{percentage_complete}->{name}; + $args->{full_field} = $self->COLUMNS->{percentage_complete}->{name}; # We need actual_time in _select_columns, otherwise we can't use # it in the expression for searching percentage_complete. -- cgit v1.2.3-24-g4f1b From a6d120fa5359e423f855a04bbb698c2043eb2e0d Mon Sep 17 00:00:00 2001 From: Frédéric Buclin Date: Mon, 5 Dec 2011 18:51:18 +0100 Subject: Forgot to fix all occurences of $cache->{search_columns}->{$user->id}, see bug 550299 --- Bugzilla/Search.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Bugzilla/Search.pm') diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm index 77299ff38..736b1af6f 100644 --- a/Bugzilla/Search.pm +++ b/Bugzilla/Search.pm @@ -608,8 +608,8 @@ sub COLUMNS { Bugzilla::Hook::process('buglist_columns', { columns => \%columns }); - $cache->{search_columns} = \%columns; - return $cache->{search_columns}; + $cache->{search_columns}->{$user->id} = \%columns; + return $cache->{search_columns}->{$user->id}; } sub REPORT_COLUMNS { -- cgit v1.2.3-24-g4f1b