diff options
author | Dylan William Hardison <dylan@hardison.net> | 2015-08-11 19:37:29 +0200 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2015-08-11 19:37:29 +0200 |
commit | a2a7527675ee7d6c40bf5c5e71a2b6f46f7734ee (patch) | |
tree | 5601808c662172bd54d935b7b5e9f0392bc30677 | |
parent | fa7ae98d1b2e83e88b2861f0826dc89e5b3bbd63 (diff) | |
download | bugzilla-a2a7527675ee7d6c40bf5c5e71a2b6f46f7734ee.tar.gz bugzilla-a2a7527675ee7d6c40bf5c5e71a2b6f46f7734ee.tar.xz |
Bug 1192688 - add ip to last used api key information
-rw-r--r-- | Bugzilla/DB/Schema.pm | 1 | ||||
-rw-r--r-- | Bugzilla/Install/DB.pm | 3 | ||||
-rw-r--r-- | Bugzilla/User/APIKey.pm | 7 | ||||
-rw-r--r-- | template/en/default/account/prefs/apikey.html.tmpl | 4 |
4 files changed, 12 insertions, 3 deletions
diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm index 67d7891b3..975fa7067 100644 --- a/Bugzilla/DB/Schema.pm +++ b/Bugzilla/DB/Schema.pm @@ -1764,6 +1764,7 @@ use constant ABSTRACT_SCHEMA => { revoked => {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'}, last_used => {TYPE => 'DATETIME'}, + last_used_ip => {TYPE => 'varchar(40)'}, app_id => {TYPE => 'varchar(64)'}, ], INDEXES => [ diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm index e288cb4c3..02777d7f1 100644 --- a/Bugzilla/Install/DB.pm +++ b/Bugzilla/Install/DB.pm @@ -736,6 +736,9 @@ sub update_table_definitions { $dbh->bz_alter_column('logincookies', 'cookie', {TYPE => 'varchar(22)', NOTNULL => 1, PRIMARYKEY => 1}); + $dbh->bz_add_column('user_api_keys', 'last_used_ip', + {TYPE => 'varchar(40)'}); + ################################################################ # New --TABLE-- changes should go *** A B O V E *** this point # ################################################################ diff --git a/Bugzilla/User/APIKey.pm b/Bugzilla/User/APIKey.pm index c37cccb92..d89203e68 100644 --- a/Bugzilla/User/APIKey.pm +++ b/Bugzilla/User/APIKey.pm @@ -13,7 +13,7 @@ use strict; use parent qw(Bugzilla::Object); use Bugzilla::User; -use Bugzilla::Util qw(generate_random_password trim); +use Bugzilla::Util qw(generate_random_password trim remote_ip); use Bugzilla::Error; ##################################################################### @@ -29,9 +29,10 @@ use constant DB_COLUMNS => qw( description revoked last_used + last_used_ip ); -use constant UPDATE_COLUMNS => qw(description revoked last_used); +use constant UPDATE_COLUMNS => qw(description revoked last_used last_used_ip); use constant VALIDATORS => { api_key => \&_check_api_key, app_id => \&_check_app_id, @@ -55,6 +56,7 @@ sub app_id { return $_[0]->{app_id} } sub description { return $_[0]->{description} } sub revoked { return $_[0]->{revoked} } sub last_used { return $_[0]->{last_used} } +sub last_used_ip { return $_[0]->{last_used_ip} } # Helpers sub user { @@ -68,6 +70,7 @@ sub update_last_used { my $timestamp = shift || Bugzilla->dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); $self->set('last_used', $timestamp); + $self->set('last_used_ip', remote_ip()); $self->update; } diff --git a/template/en/default/account/prefs/apikey.html.tmpl b/template/en/default/account/prefs/apikey.html.tmpl index ff9ed697a..8b740cf1e 100644 --- a/template/en/default/account/prefs/apikey.html.tmpl +++ b/template/en/default/account/prefs/apikey.html.tmpl @@ -41,7 +41,9 @@ here.</p> value="[% api_key.description FILTER html %]"> </td> [% IF api_key.last_used %] - <td>[% api_key.last_used FILTER time %]</td> + <td>[% api_key.last_used FILTER time %] + [% IF api_key.last_used_ip %] ([% api_key.last_used_ip FILTER html %]) [% END %] + </td> [% ELSE %] <td class="center"><i>never used</i></td> [% END %] |