From df1b45f5f61f20c3eab5b4ed5065f5183049bbe2 Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 20 Apr 2026 14:28:34 +0200 Subject: [PATCH 1/2] improve(apikey): always log `last_used` --- backend/user/auth_apikey.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/user/auth_apikey.py b/backend/user/auth_apikey.py index 4f2d729..d7fc4c7 100644 --- a/backend/user/auth_apikey.py +++ b/backend/user/auth_apikey.py @@ -39,9 +39,9 @@ def authenticate(self, request): user.last_login = now user.save(update_fields=['last_login']) - if api_key.last_used is None or api_key.last_used < one_hour_ago: - api_key.last_used = now - api_key.save(update_fields=['last_used']) + # always update apikey last_used + api_key.last_used = now + api_key.save(update_fields=['last_used']) return (api_key.user, None) From f1c391cfe922acdc9d5ea878cc35dc511a322c6a Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 21 Apr 2026 09:56:28 +0200 Subject: [PATCH 2/2] fix(test): api key will always have `last_used` update --- backend/tests/user/test_auth_apikey.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/tests/user/test_auth_apikey.py b/backend/tests/user/test_auth_apikey.py index 404b82c..3c7ee5f 100644 --- a/backend/tests/user/test_auth_apikey.py +++ b/backend/tests/user/test_auth_apikey.py @@ -88,7 +88,8 @@ def test_timestamp_update_logic(self, auth, factory, user, offset_minutes, shoul assert api_key_obj.last_used != initial_time else: assert user.last_login == initial_time - assert api_key_obj.last_used == initial_time + # api key will always get the last_used update + assert api_key_obj.last_used != initial_time def test_authenticate_extract_from_header_format(self, auth, factory, user): _, plain_key = UserAPIKey.objects.create_key(name='test', user=user)