[PR #20864] [MERGED] Closes #20834: Add support for enabling/disabling Tokens #16073

Closed
opened 2025-12-30 00:25:38 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/20864
Author: @pheus
Created: 11/21/2025
Status: Merged
Merged: 11/26/2025
Merged by: @jeremystretch

Base: featureHead: 20834-add-token-enabled-field


📝 Commits (2)

  • ef89933 feat(users): Add support for enabling/disabling Tokens
  • 37d8f45 Fix authentication test

📊 Changes

16 files changed (+143 additions, -29 deletions)

View changed files

📝 netbox/netbox/api/authentication.py (+8 -4)
📝 netbox/netbox/tests/test_authentication.py (+26 -0)
📝 netbox/templates/users/token.html (+4 -0)
📝 netbox/users/api/serializers_/tokens.py (+3 -3)
📝 netbox/users/filtersets.py (+2 -1)
📝 netbox/users/forms/bulk_edit.py (+6 -1)
📝 netbox/users/forms/bulk_import.py (+1 -1)
📝 netbox/users/forms/filtersets.py (+8 -1)
📝 netbox/users/forms/model_forms.py (+2 -2)
📝 netbox/users/migrations/0014_users_token_v2.py (+8 -1)
📝 netbox/users/models/tokens.py (+21 -6)
📝 netbox/users/tables.py (+6 -3)
📝 netbox/users/tests/test_api.py (+8 -2)
📝 netbox/users/tests/test_filtersets.py (+9 -0)
📝 netbox/users/tests/test_models.py (+26 -0)
📝 netbox/users/tests/test_views.py (+5 -4)

📄 Description

Fixes: #20834

This PR introduces an enabled field on the Token model to allow API tokens to be temporarily disabled without being deleted.

Key changes:

  • Add an enabled Boolean field to Token (defaulting to True for backwards compatibility)
  • Enforce the enabled flag in token authentication so disabled tokens are rejected
  • Expose the new field in token forms, bulk edit, and tables to make it easy to toggle status from the UI
  • Expose enabled via the token API serializers (including provisioning), allowing tokens to be created and managed in a disabled state
  • Add tests for the Token model, API, and authentication to cover the new behavior

Existing tokens remain enabled by default, so there is no change in behavior until a token is explicitly disabled.

Thanks in advance for reviewing!


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/20864 **Author:** [@pheus](https://github.com/pheus) **Created:** 11/21/2025 **Status:** ✅ Merged **Merged:** 11/26/2025 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `feature` ← **Head:** `20834-add-token-enabled-field` --- ### 📝 Commits (2) - [`ef89933`](https://github.com/netbox-community/netbox/commit/ef89933e5875e96449540edb29b2fd828df8b80c) feat(users): Add support for enabling/disabling Tokens - [`37d8f45`](https://github.com/netbox-community/netbox/commit/37d8f4518803cf8d3cc3e8d5573e6fbb03114619) Fix authentication test ### 📊 Changes **16 files changed** (+143 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `netbox/netbox/api/authentication.py` (+8 -4) 📝 `netbox/netbox/tests/test_authentication.py` (+26 -0) 📝 `netbox/templates/users/token.html` (+4 -0) 📝 `netbox/users/api/serializers_/tokens.py` (+3 -3) 📝 `netbox/users/filtersets.py` (+2 -1) 📝 `netbox/users/forms/bulk_edit.py` (+6 -1) 📝 `netbox/users/forms/bulk_import.py` (+1 -1) 📝 `netbox/users/forms/filtersets.py` (+8 -1) 📝 `netbox/users/forms/model_forms.py` (+2 -2) 📝 `netbox/users/migrations/0014_users_token_v2.py` (+8 -1) 📝 `netbox/users/models/tokens.py` (+21 -6) 📝 `netbox/users/tables.py` (+6 -3) 📝 `netbox/users/tests/test_api.py` (+8 -2) 📝 `netbox/users/tests/test_filtersets.py` (+9 -0) 📝 `netbox/users/tests/test_models.py` (+26 -0) 📝 `netbox/users/tests/test_views.py` (+5 -4) </details> ### 📄 Description ### Fixes: #20834 This PR introduces an `enabled` field on the `Token` model to allow API tokens to be temporarily disabled without being deleted. Key changes: - Add an `enabled` Boolean field to `Token` (defaulting to `True` for backwards compatibility) - Enforce the `enabled` flag in token authentication so disabled tokens are rejected - Expose the new field in token forms, bulk edit, and tables to make it easy to toggle status from the UI - Expose `enabled` via the token API serializers (including provisioning), allowing tokens to be created and managed in a disabled state - Add tests for the Token model, API, and authentication to cover the new behavior Existing tokens remain enabled by default, so there is no change in behavior until a token is explicitly disabled. Thanks in advance for reviewing! --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:25:38 +01:00
adam closed this issue 2025-12-30 00:25:38 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#16073