chg: [user] log last_api_access hourly if MISP.store_api_access_time is not set

pull/9098/head
Christophe Vandeplas 2023-05-21 20:12:44 +02:00
parent acb258cc52
commit a5f5a4e113
3 changed files with 8 additions and 7 deletions

View File

@ -439,10 +439,7 @@ class AppController extends Controller
);
$this->Log->save($log);
}
$storeAPITime = Configure::read('MISP.store_api_access_time');
if (!empty($storeAPITime) && $storeAPITime) {
$this->User->updateAPIAccessTime($user);
}
$this->Session->renew();
$this->Session->write(AuthComponent::$sessionKey, $user);
$this->isApiAuthed = true;

View File

@ -1414,6 +1414,8 @@ class User extends AppModel
/**
* Updates `last_api_access` time in database.
* Always update when MISP.store_api_access_time is set.
* Only update every hour when it isn't set
*
* @param array $user
* @return array|bool
@ -1424,9 +1426,12 @@ class User extends AppModel
if (!isset($user['id'])) {
throw new InvalidArgumentException("Invalid user object provided.");
}
$storeAPITime = Configure::read('MISP.store_api_access_time');
if ((!empty($storeAPITime) && $storeAPITime) || $user['last_api_access'] < time() - 60*60) {
$user['last_api_access'] = time();
return $this->save($user, true, array('id', 'last_api_access'));
}
}
/**
* Update field in user model and also set `date_modified`

View File

@ -229,7 +229,6 @@
'element' => 'datetime',
'class' => 'short',
'data_path' => 'User.last_api_access',
'requirement' => !empty(Configure::read('MISP.store_api_access_time')),
),
array(
'name' => (Configure::read('Plugin.CustomAuth_name') ? Configure::read('Plugin.CustomAuth_name') : __('External Auth')),