Currently the dashboard shows everything (sandboxes, users, system status) on one page, with admin-only sections guarded by inline Current.user.admin? checks and require_admin! before_actions. This plan:
Splits the dashboard so regular users see only their own sandcastles, Tailscale link, and preferences
Moves admin content (all sandboxes, user list, system status) to a dedicated admin sub-page (/admin)
Replaces inline admin checks with Pundit policies
Renames "Sandbox" → "Sandcastle" in all UI display text (not code/models/DB)
1. Install Pundit
Add gem "pundit", "~> 2.4" to Gemfile
bundle install
2. Pundit Setup
app/controllers/application_controller.rb
Add include Pundit::Authorization
Override pundit_user → Current.user
Rescue Pundit::NotAuthorizedError → redirect to root with alert
I'll start by reading all the key files I need to understand and modify. Let me do this in parallel.
Assistant
Now let me read the view files and API controllers.
Assistant
Let me also check the remaining admin views and the layout.
Assistant
Now I have a complete picture. Let me create task tracking and start implementing.
Assistant
Task 1: Install Pundit gem
Assistant
Task 2: Create Pundit policies
Assistant
Task 3: Setup Pundit in controllers
Assistant
Task 4: Update routes
Assistant
Task 5: Restructure controllers
Update DashboardController:
Assistant
Create Admin::DashboardController:
Assistant
Create Admin::SandboxesController:
Assistant
Update SandboxesController with Pundit:
Assistant
Update Admin::UsersController with Pundit:
Assistant
Update Api::SandboxesController with Pundit:
Assistant
Update Api::UsersController with Pundit:
Assistant
Task 6: Update and create views
Update the user dashboard view:
Assistant
Update the user sandbox partial (remove admin owner badge, rename text):
Assistant
Create admin dashboard index view:
Assistant
Create admin sandbox partial (with owner badge and admin routes):
Assistant
Move system_status partial to admin namespace and rename "Sandboxes" → "Sandcastles":
Assistant
Now I need to create the _sandbox_stats partial for admin too. Let me check if it needs its own copy or can reuse the dashboard one.
Assistant
Now let me check if human_bytes is a helper method I need to check:
Assistant
Good, it's in the application helper, so both views can use it. Now update admin/users/index.html.erb — rename "Sandboxes" → "Sandcastles":
Assistant
Also update the delete confirmation text in admin/users/index to say "sandcastles":
Assistant
Now delete the old system_status partial since it moved to admin:
Assistant
Task 7: Remove require_admin! from concerns
Assistant
Let me verify no other references to require_admin! exist:
Assistant
Good — only in documentation, not in code.
Assistant
Task 8: Run tests and fix issues
Assistant
All 26 tests pass. Let me also run rubocop to check for style issues:
Assistant
Let me also verify routes are valid:
Assistant
All routes look correct. Let me run all tests one more time to be sure:
Assistant
All 26 tests pass, 0 failures.
Assistant
Implementation complete. Here's a summary of all changes:
Summary
Pundit Authorization
Added gem "pundit" to Gemfile
Created 3 policies in app/policies/:
ApplicationPolicy — default deny all, base class
SandboxPolicy — owner-or-admin for actions, scoped index (user sees own, admin sees all active)
— admin-only for all actions, destroy prevented for self-delete
User
set a fixed width - don't want teh layout to wiggle when turbo data arrives. make tht toplevel navigation beautiful!
Assistant
Let me look at the current state of the views to understand the layout.
Assistant
Let me also check the layout and other pages that have their own nav to understand the full picture.
Assistant
Let me also check which controllers skip authentication to know where the nav shouldn't appear.
Assistant
Good. Now I have the full picture. Let me implement both changes:
Nav bar — extract to a shared partial in the layout, with proper visual treatment
Fixed-width turbo frames — prevent layout shift on stats/system status
Assistant
Now update the layout to include the navbar when authenticated:
Assistant
Now strip the inline nav from dashboard/index.html.erb:
Assistant
Strip inline nav from admin/dashboard/index.html.erb:
Assistant
Strip inline nav from tailscale/show.html.erb:
Assistant
Strip inline nav from admin/users/index.html.erb:
Assistant
Update admin/users/new.html.erb and edit.html.erb — change "Back" links to point to admin users instead of needing dashboard:
Assistant
Those are fine — they link back to admin_users_path which is correct.
Now fix the stats turbo frames to have a fixed width and prevent layout wiggle. The stats area shows: CPU, MEM, NET, DISK, PIDs — I'll give the container a fixed min-width.
Assistant
Do the same for admin sandbox partial:
Assistant
Now fix the system status loading placeholder to match the loaded height — use the same grid structure:
Assistant
Now let me also handle the unauthenticated mt-28 case — pages like login need vertical spacing too. Let me check the login page:
Assistant
The login page uses mx-auto md:w-2/3 w-full and relies on the layout's mt-28 for vertical centering. I should keep vertical spacing for unauthenticated pages. Let me update the layout:
Assistant
Now let me run the tests to make sure everything still works:
Assistant
All 26 tests pass. Let me also verify the guide page doesn't have redundant nav (it's unauthenticated-accessible so it may not have inline nav):
Assistant
Good — the guide page doesn't have inline nav to clean up. Let me do a final check on all modified files with rubocop:
Assistant
All clean. Here's what I did:
Beautiful navigation bar (app/views/shared/_navbar.html.erb):
Fixed top nav with bg-white/80 backdrop-blur-md frosted glass effect
Sandcastle brand with a house icon on the left
Nav links (Dashboard, Guide, Tailscale, Admin) with active state highlighting (dark pill for current section)
Vertical divider separating nav from user controls
User name, password link, and log out on the right
Only shown when authenticated (via layout conditional)
Fixed-width stats containers (both dashboard/_sandbox.html.erb and admin/dashboard/_sandbox.html.erb):
Wrapped the turbo frame stats area in a w-80 shrink-0 container so it reserves space before the turbo frame loads
System status skeleton (admin/dashboard/index.html.erb):
Replaced "Loading..." text with a skeleton grid matching the 4-column layout of the loaded content
Already properly scoped to current user. No Pundit changes needed (these don't have authorization concerns beyond authentication).
Skip Pundit for unauthenticated controllers
Api::AuthController — inherits from ActionController::API directly, no Pundit involvement
5. Route Changes (config/routes.rb)
ruby
# Remove top-level system_status route
# (was: get "system_status", to: "dashboard#system_status")
namespace :admin do
get "/", to: "dashboard#index", as: :dashboard
get "system_status", to: "dashboard#system_status"
resources :users
resources :sandboxes, only: :destroy do
member do
post :start
post :stop
get :stats
end
end
end
Keep the existing top-level resources :sandboxes for user's own sandbox actions.
6. View Changes
app/views/dashboard/index.html.erb
Remove system status turbo frame
Remove users table section
Remove all Current.user.admin? conditionals
Header: Always "My Sandcastles"
Add "Admin" nav link (visible only to admins via policy(:user).index?)
Rename "Sandbox" → "Sandcastle" in display text
Empty state: "No sandcastles yet" / sandcastle create my-dev
app/views/dashboard/_sandbox.html.erb
Remove if Current.user.admin? owner badge (user dashboard never shows other users' sandboxes)
Rename confirm text: "Destroy sandcastle X?"
"Remove sandcastle" for temp
New app/views/admin/dashboard/index.html.erb
Admin page header with "Back to Dashboard" link
System status turbo frame (src: admin_system_status_path)
"All Sandcastles" section with @sandboxes
Users table (moved from dashboard/index)
New app/views/admin/dashboard/_sandbox.html.erb
Copy of dashboard/_sandbox.html.erb but:
Always shows owner badge
Action buttons point to admin_sandbox_path routes
Stats turbo frame points to stats_admin_sandbox_path
Manual: Log in as regular user → dashboard shows only "My Sandcastles", no admin link, no users table
Manual: Log in as admin → dashboard shows "My Sandcastles" + "Admin" link → admin page shows system status, all sandcastles, users table
Manual: Regular user cannot access /admin (redirected with "Not authorized")
Manual: Admin can start/stop/destroy any sandcastle from admin page
bin/rubocop — no new violations
If you need specific details from before exiting plan mode (like exact code snippets, error messages, or content you generated), read the full transcript at: /Users/thies/.REDACTED.jsonl
UserPolicy
Controller Restructure
ApplicationController — includes Pundit::Authorization, rescues NotAuthorizedError → redirect with alert
Api::BaseController — includes Pundit::Authorization, rescues NotAuthorizedError → JSON 403
DashboardController — simplified to use policy_scope(Sandbox), no admin branching, removed system_status action