Skip to content

Conversation

@pheus
Copy link
Contributor

@pheus pheus commented Nov 21, 2025

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!

@pheus
Copy link
Contributor Author

pheus commented Nov 21, 2025

I’ve opened this as a draft PR to get an initial round of feedback on the approach and implementation.

Once the changes from #20823 are merged from main into the feature branch, I’ll rebase this work to align with the updated code and reduce potential merge conflicts.

In the meantime, any early feedback on the model changes, API surface, or tests is very welcome. Thanks in advance for taking a look!

@jeremystretch jeremystretch self-requested a review November 24, 2025 14:35
@jeremystretch jeremystretch marked this pull request as ready for review November 25, 2025 13:47
@pheus pheus force-pushed the 20834-add-token-enabled-field branch from 8640d0e to d513cc8 Compare November 26, 2025 17:30
@pheus
Copy link
Contributor Author

pheus commented Nov 26, 2025

I’ve just rebased this PR onto the newly merged branch and resolved the merge conflicts. The changes are now up to date and ready for review.

Thank you very much for taking a look!

Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @pheus! Just had a few minor suggestions.

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 netbox-community#20834
@pheus pheus force-pushed the 20834-add-token-enabled-field branch from d513cc8 to ef89933 Compare November 26, 2025 21:28
@pheus
Copy link
Contributor Author

pheus commented Nov 26, 2025

Thank you very much for the thoughtful review and suggestions! I really appreciate you taking the time to go through this. Your feedback is super helpful and will definitely help me improve!

@pheus
Copy link
Contributor Author

pheus commented Nov 26, 2025

I’m really sorry about that. I ran the users tests locally but completely overlooked the authentication tests under netbox. I should have caught this earlier.

Thank you for pushing the fix and for your patience. I’ll make sure to run the full set of relevant tests next time. 🙏

@jeremystretch
Copy link
Member

No worries!

@jeremystretch jeremystretch merged commit 513b114 into netbox-community:feature Nov 26, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants