feat(admin): users-management page with admin/agent role toggles#50
Merged
Conversation
Port the admin User-management surface from escalated-laravel#94 so the shared `Escalated/Admin/Users/Index` Inertia page works against the Django host. Adds: - GET /support/admin/users (`escalated:admin_users_index`) — paginated users list with name+email LIKE search, exposing is_admin / is_agent per row plus currentUserId. - PATCH /support/admin/users/<int:user_id>/role (`escalated:admin_users_role`) — toggle admin or agent. Promoting to admin also marks agent; revoking agent from an admin cascades to is_admin=false. Self-demote is blocked with a redirect-back so admins cannot lock themselves out of the panel they are using. Django has no first-class is_admin / is_agent columns, so the package maps is_admin <-> User.is_staff and is_agent <-> membership in any active Department. Hosts that model roles differently can override the controller as usual. Tested via pytest (8 cases covering list, forbidden, search, promote admin, promote agent only, self-demote guard, agent->admin cascade, role-forbidden). Ref: escalated-dev/escalated-laravel#94
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.
Summary
Ports the admin Users management feature from
escalated-laravel#94into the Django plugin so the sharedEscalated/Admin/Users/IndexInertia page (in@escalated-dev/escalated@0.8.0) has feature parity./support/admin/users/(escalated:admin_users_index) — paginated users list (20/page) with name+email+usernameicontainssearch, exposingis_admin/is_agentper row pluscurrentUserId./support/admin/users/<int:user_id>/role/(escalated:admin_users_role) — toggle admin or agent. Promoting to admin also flags the user as an agent; revoking agent from an admin cascades tois_admin=false. Self-demote is blocked with a redirect-back so admins cannot lock themselves out of the panel they are using.Deviations from Laravel reference
Django's
auth.Userhas no first-classis_admin/is_agentcolumns, so this port maps them via the same gates the rest ofescalated-djangoalready uses (escalated.permissions):is_admin<->User.is_staffis_agent<-> membership in at least one activeDepartmentPromoting to agent attaches the user to the first active
Department(creating a defaultSupportdepartment if none exist). Revoking agent removes the user from every department they belong to. Hosts that model roles differently can override the views the same way they would in Laravel.Test plan
python -m pytest tests/integration/test_admin_users_views.py— 8 cases (list, non-admin forbidden, search filter, promote-to-admin, promote-to-agent-only, self-demote guard, admin->agent cascade, role-toggle forbidden)python -m pytest— 730 passedpython -m ruff check— clean