diff options
author | Dave Lawrence <dlawrence@mozilla.com> | 2013-08-23 20:38:56 +0200 |
---|---|---|
committer | Dave Lawrence <dlawrence@mozilla.com> | 2013-08-23 20:38:56 +0200 |
commit | e2c1157cf6bbb98deff0990efa2d8a829370fdf5 (patch) | |
tree | cca3e2afdbd33ebda36e5e5da147706780c50f4e | |
parent | 1f870a8b3f88cc77319dec50380fc4554f34793e (diff) | |
download | bugzilla-e2c1157cf6bbb98deff0990efa2d8a829370fdf5.tar.gz bugzilla-e2c1157cf6bbb98deff0990efa2d8a829370fdf5.tar.xz |
Bug 903387 - Backport bug 240437 (last_seen_date column) to BMO 4.2
-rw-r--r-- | Bugzilla.pm | 6 | ||||
-rw-r--r-- | Bugzilla/DB/Schema.pm | 1 | ||||
-rw-r--r-- | Bugzilla/Install/DB.pm | 3 | ||||
-rw-r--r-- | Bugzilla/User.pm | 43 | ||||
-rwxr-xr-x | editusers.cgi | 3 | ||||
-rw-r--r-- | template/en/default/admin/users/edit.html.tmpl | 11 | ||||
-rw-r--r-- | template/en/default/admin/users/list.html.tmpl | 3 |
7 files changed, 59 insertions, 11 deletions
diff --git a/Bugzilla.pm b/Bugzilla.pm index 586e031ff..9a3b75756 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -376,6 +376,12 @@ sub login { $class->set_user($authenticated_user); } + if (Bugzilla->sudoer) { + Bugzilla->sudoer->update_last_seen_date(); + } else { + $class->user->update_last_seen_date(); + } + return $class->user; } diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm index 2040d0c0a..ffab77e15 100644 --- a/Bugzilla/DB/Schema.pm +++ b/Bugzilla/DB/Schema.pm @@ -897,6 +897,7 @@ use constant ABSTRACT_SCHEMA => { extern_id => {TYPE => 'varchar(64)'}, is_enabled => {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'TRUE'}, + last_seen_date => {TYPE => 'DATETIME'}, ], INDEXES => [ profiles_login_name_idx => {FIELDS => ['login_name'], diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm index db3b8e3a3..ad68e94c4 100644 --- a/Bugzilla/Install/DB.pm +++ b/Bugzilla/Install/DB.pm @@ -660,6 +660,9 @@ sub update_table_definitions { # 2011-10-11 miketosh - Bug 690173 _on_delete_set_null_for_audit_log_userid(); + # 2011-11-01 glob@mozilla.com - Bug 240437 + $dbh->bz_add_column('profiles', 'last_seen_date', {TYPE => 'DATETIME'}); + # 2011-11-28 dkl@mozilla.com - Bug 685611 _fix_notnull_defaults(); diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm index 9261bd780..87714011c 100644 --- a/Bugzilla/User.pm +++ b/Bugzilla/User.pm @@ -92,16 +92,21 @@ use constant DB_TABLE => 'profiles'; # that you passed in for "name" to new(). That's because historically # Bugzilla::User used "name" for the realname field. This should be # fixed one day. -use constant DB_COLUMNS => ( - 'profiles.userid', - 'profiles.login_name', - 'profiles.realname', - 'profiles.mybugslink AS showmybugslink', - 'profiles.disabledtext', - 'profiles.disable_mail', - 'profiles.extern_id', - 'profiles.is_enabled', -); +sub DB_COLUMNS { + my $dbh = Bugzilla->dbh; + return ( + 'profiles.userid', + 'profiles.login_name', + 'profiles.realname', + 'profiles.mybugslink AS showmybugslink', + 'profiles.disabledtext', + 'profiles.disable_mail', + 'profiles.extern_id', + 'profiles.is_enabled', + $dbh->sql_date_format('last_seen_date', '%Y-%m-%d') . ' AS last_seen_date', + ), +} + use constant NAME_FIELD => 'login_name'; use constant ID_FIELD => 'userid'; use constant LIST_ORDER => NAME_FIELD; @@ -286,6 +291,23 @@ sub set_disabledtext { $_[0]->set('is_enabled', $_[1] ? 0 : 1); } +sub update_last_seen_date { + my $self = shift; + return unless $self->id; + my $dbh = Bugzilla->dbh; + my $date = $dbh->selectrow_array( + 'SELECT ' . $dbh->sql_date_format('NOW()', '%Y-%m-%d')); + + if (!$self->last_seen_date or $date ne $self->last_seen_date) { + $self->{last_seen_date} = $date; + # We don't use the normal update() routine here as we only + # want to update the last_seen_date column, not any other + # pending changes + $dbh->do("UPDATE profiles SET last_seen_date = ? WHERE userid = ?", + undef, $date, $self->id); + } +} + ################################################################################ # Methods ################################################################################ @@ -300,6 +322,7 @@ sub is_enabled { $_[0]->{'is_enabled'} ? 1 : 0; } sub showmybugslink { $_[0]->{showmybugslink}; } sub email_disabled { $_[0]->{disable_mail}; } sub email_enabled { !($_[0]->{disable_mail}); } +sub last_seen_date { $_[0]->{last_seen_date}; } sub cryptpassword { my $self = shift; # We don't store it because we never want it in the object (we diff --git a/editusers.cgi b/editusers.cgi index bd643e893..a6a93c41e 100755 --- a/editusers.cgi +++ b/editusers.cgi @@ -80,7 +80,8 @@ if ($action eq 'search') { my $matchstr = trim($cgi->param('matchstr')); my $matchtype = $cgi->param('matchtype'); my $grouprestrict = $cgi->param('grouprestrict') || '0'; - my $query = 'SELECT DISTINCT userid, login_name, realname, is_enabled ' . + my $query = 'SELECT DISTINCT userid, login_name, realname, is_enabled, ' . + $dbh->sql_date_format('last_seen_date', '%Y-%m-%d') . ' AS last_seen_date ' . 'FROM profiles'; my @bindValues; my $nextCondition; diff --git a/template/en/default/admin/users/edit.html.tmpl b/template/en/default/admin/users/edit.html.tmpl index 010cacb73..8eced20f7 100644 --- a/template/en/default/admin/users/edit.html.tmpl +++ b/template/en/default/admin/users/edit.html.tmpl @@ -107,6 +107,17 @@ [% END %] </td> </tr> + + <tr> + <th>Last Login:</th> + <td> + [% IF otheruser.last_seen_date %] + [% otheruser.last_seen_date FILTER html %] + [% ELSE %] + <em>never</em> + [% END %] + </td> + </tr> </table> <p> diff --git a/template/en/default/admin/users/list.html.tmpl b/template/en/default/admin/users/list.html.tmpl index 4d1d35c95..3ebfc2970 100644 --- a/template/en/default/admin/users/list.html.tmpl +++ b/template/en/default/admin/users/list.html.tmpl @@ -42,6 +42,9 @@ {name => 'realname' heading => 'Real name' } + {name => 'last_seen_date' + heading => 'Last Login' + } {heading => 'Account History' content => 'View' contentlink => 'editusers.cgi?action=activity' _ |