Closes #20834: Add support for enabling/disabling Tokens (#20864)
Some checks failed
CI / build (20.x, 3.12) (push) Has been cancelled
CI / build (20.x, 3.13) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, actions) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, python) (push) Has been cancelled

* feat(users): Add support for enabling/disabling Tokens

Introduce an `enabled` flag on the `Token` model to allow temporarily
revoking API tokens without deleting them. Update forms, serializers,
and views to expose the new field.
Enforce the `enabled` flag in token authentication.
Add model, API, and authentication tests for the new behavior.

Fixes #20834

* Fix authentication test

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
Martin Hauser
2025-11-26 23:15:14 +01:00
committed by GitHub
parent b5edfa5d53
commit 513b11450d
16 changed files with 143 additions and 29 deletions

View File

@@ -9,6 +9,13 @@ class Migration(migrations.Migration):
]
operations = [
# Add a new field to enable/disable tokens
migrations.AddField(
model_name='token',
name='enabled',
field=models.BooleanField(default=True),
),
# Rename the original key field to "plaintext"
migrations.RenameField(
model_name='token',
@@ -35,7 +42,7 @@ class Migration(migrations.Migration):
),
),
# Add version field to distinguish v1 and v2 tokens
# Add a version field to distinguish v1 and v2 tokens
migrations.AddField(
model_name='token',
name='version',