Final Django Admin Removal - #445
Merged
Merged
Conversation
Adds a superuser-only Token list + revoke view, replacing the only remaining reason to visit /admin/authtoken/tokenproxy/. Self-service token regeneration for one's own account already existed; this adds the "see/revoke anyone's token" admin-facing view. Part of the Django Admin removal effort (A1/5).
Superusers auditing/revoking tokens need the full key, not a masked prefix. Also add a "Tokens" tab on the User detail page so a token can be found starting from the user rather than only from the global list. Key the revoke URL on the token's owning user (Token.user is a OneToOneField) instead of the token's own key, so the secret never ends up in a URL and thus browser history / access logs.
Extends the existing read-only User list/detail with full superuser account management: create (unusable password until a reset email is sent), edit (username/email/name/flags/groups), deactivate/reactivate, hard delete, and a "send password reset email" action. The reset action is disabled for OIDC-linked accounts, which have no local password to reset. Replaces the last reason to visit /admin/auth/user/. Part of the Django Admin removal effort (A2/5).
Adds a superuser-only list/detail/create/edit/delete for django.contrib.auth.models.Group (name + permissions), for admin-app parity. Nothing in Orthos2's own authorization logic checks group membership today - this only replaces /admin/auth/group/ access. Part of the Django Admin removal effort (A3/5).
Association and Nonce are ephemeral social-django bookkeeping tables for the OIDC login handshake - never read or written by Orthos2 code and not meant for hands-on editing. Adds a superuser-only, read-only list of both for troubleshooting, without exposing Association.secret. Part of the Django Admin removal effort (A4/5).
Users, Groups, Tokens, Associations, Nonces, and UserSocialAuths all now have frontend equivalents (or an explicit no-UI decision for the purely internal OIDC bookkeeping tables). Drop django.contrib.admin from INSTALLED_APPS, the /admin/ URL include, the "Django Admin" nav link, and the now-pointless empty admin.py files. Completes the Django Admin removal effort (A5/5).
The dev DB/NetBox instance persists across container restarts, but several startup steps in devel-server.sh/setup_netbox.py assumed a fresh environment and blew up on every restart after the first: - django-generate-admin-token used Token.objects.create() unconditionally, raising IntegrityError once the admin user already had a token (Token.user is a OneToOneField). - devel-server.sh's two loaddata calls and createsuperuser errored with duplicate-key/"username already taken" once that data already existed. - setup_netbox.py unconditionally re-POSTed ~50 objects to NetBox, most already caught by broad try/except but still spamming HTTP 400s (and the few uncaught ones, e.g. the site/device-role creation, would abort the script outright on a second run). Guard each with an existence check (get_or_create for the token, shell -c exit-code checks before the fixture/superuser commands, and a netbox.check_site() early-return in setup_netbox.py) so re-running against already-provisioned state is a no-op instead of an error.
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| Documentation | 17 minor |
| Security | 2 high |
🟢 Metrics 101 complexity · 53 duplication
Metric Results Complexity 101 Duplication 53
🟢 Coverage 100.00% diff coverage · +0.67% coverage variation
Metric Results Coverage variation ✅ +0.67% coverage variation (-1.00%) Diff coverage ✅ 100.00% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (4e93e8f) 23012 17115 74.37% Head commit (ebda194) 23634 (+622) 17737 (+622) 75.05% (+0.67%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#445) 631 631 100.00% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the missing functionality to get rid of the Django Admin completely. This is another step to prepare for the upcoming migration of Orthos 2 into Cobbler.