towerops/lib/towerops_web/live/admin/dashboard_live.html.heex
Graham McIntire 853d548f82
Add superuser system with user impersonation for admin support
Implement comprehensive admin interface allowing designated superusers to view all users and organizations, impersonate users for debugging, and perform administrative operations. All superuser actions are tracked in audit logs for compliance.

Features:
- Superuser authentication with dedicated admin routes at /admin
- User impersonation with session state preservation
- Admin dashboard with system statistics
- User and organization management interfaces
- Comprehensive audit logging with IP tracking
- Visual impersonation banner with exit capability
- Security controls preventing self-impersonation and superuser-to-superuser impersonation

Database:
- Add is_superuser boolean field to users table
- Create audit_logs table for tracking sensitive operations
- Set graham@mcintire.me as initial superuser
2026-01-06 12:50:10 -06:00

40 lines
1.7 KiB
Text

<Layouts.admin flash={@flash}>
<div class="space-y-6">
<div>
<h1 class="text-2xl font-bold text-zinc-900">Admin Dashboard</h1>
<p class="text-zinc-600">System overview and recent activity</p>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="bg-white rounded-lg border border-zinc-200 p-6">
<h2 class="text-lg font-semibold text-zinc-900 mb-2">Users</h2>
<p class="text-3xl font-bold text-zinc-900">{@user_count}</p>
<.link navigate={~p"/admin/users"} class="text-blue-600 hover:underline text-sm">
View all users →
</.link>
</div>
<div class="bg-white rounded-lg border border-zinc-200 p-6">
<h2 class="text-lg font-semibold text-zinc-900 mb-2">Organizations</h2>
<p class="text-3xl font-bold text-zinc-900">{@org_count}</p>
<.link navigate={~p"/admin/organizations"} class="text-blue-600 hover:underline text-sm">
View all organizations →
</.link>
</div>
</div>
<div class="bg-white rounded-lg border border-zinc-200">
<div class="px-4 py-3 border-b border-zinc-200">
<h2 class="text-lg font-semibold text-zinc-900">Recent Audit Logs</h2>
</div>
<.table id="audit-logs" rows={@recent_logs}>
<:col :let={log} label="Action">{log.action}</:col>
<:col :let={log} label="Superuser">{log.superuser && log.superuser.email}</:col>
<:col :let={log} label="Target">{log.target_user && log.target_user.email}</:col>
<:col :let={log} label="Time">
{Calendar.strftime(log.inserted_at, "%Y-%m-%d %H:%M:%S")}
</:col>
</.table>
</div>
</div>
</Layouts.admin>