mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-17 09:12:18 -06:00
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
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:
@@ -32,10 +32,10 @@ class TokenSerializer(ValidatedModelSerializer):
|
||||
model = Token
|
||||
fields = (
|
||||
'id', 'url', 'display_url', 'display', 'version', 'key', 'user', 'description', 'created', 'expires',
|
||||
'last_used', 'write_enabled', 'pepper_id', 'allowed_ips', 'token',
|
||||
'last_used', 'enabled', 'write_enabled', 'pepper_id', 'allowed_ips', 'token',
|
||||
)
|
||||
read_only_fields = ('key',)
|
||||
brief_fields = ('id', 'url', 'display', 'version', 'key', 'write_enabled', 'description')
|
||||
brief_fields = ('id', 'url', 'display', 'version', 'key', 'enabled', 'write_enabled', 'description')
|
||||
|
||||
def get_fields(self):
|
||||
fields = super().get_fields()
|
||||
@@ -79,7 +79,7 @@ class TokenProvisionSerializer(TokenSerializer):
|
||||
model = Token
|
||||
fields = (
|
||||
'id', 'url', 'display_url', 'display', 'version', 'user', 'key', 'created', 'expires', 'last_used', 'key',
|
||||
'write_enabled', 'description', 'allowed_ips', 'username', 'password', 'token',
|
||||
'enabled', 'write_enabled', 'description', 'allowed_ips', 'username', 'password', 'token',
|
||||
)
|
||||
|
||||
def validate(self, data):
|
||||
|
||||
Reference in New Issue
Block a user