1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

feat(accounts): API tokens show their last use, and a user has at most ten

The API Tokens tab gets a "Last used" column, so an unused token can be
told from one a script still needs. The token's last use is written when
it authenticates, at most once a minute (accounts.auth.TokenAuthentication,
knox's class with that one addition; the API schema describes it as
knox's).

A user has at most ten tokens; a new one is refused until one is
deleted. Expired tokens do not count, and are deleted when a new token is
made.
This commit is contained in:
catborise 2026-10-24 23:33:12 +03:00
parent d9088b410e
commit 6b51c30dd6
8 changed files with 85 additions and 2 deletions

View file

@ -87,7 +87,10 @@ class PermissionSet(models.Model):
class ApiToken(AbstractAuthToken):
"""A token for the REST API, kept as a digest (django-rest-knox); the
name says what uses it."""
LIMIT = 10 # per user, expired ones not counted
name = models.CharField(_("name"), max_length=64)
last_used = models.DateTimeField(_("last used"), null=True, blank=True)
class Meta:
ordering = ["-created"]