Lesson 2 — Role-aware navigation
The chassis ships a sidebar that already adapts to the
signed-in user’s role. Until now it’s been showing the same
items regardless of who you signed in as, because the placeholder
chassis users all had the same role (field_officer). With
Lesson 1’s seed task complete, we have one of each role —
manager, dispatcher, field officer — and the sidebar’s
role-awareness becomes visible immediately.
This is a short lesson. We’re walking through what’s already there, verifying it works with the real seeded users, and refining the navigation list to match the structure Module 5 onward will deliver.
The chassis sidebar
Open app/components/sidebar.rb. The component has a
constant near the top:
|
|
Each item carries a roles: array — the list of roles that
should see this item in their sidebar. The component’s
visible_items method filters this list against the current
user’s role:
|
|
So a manager sees all five items; a dispatcher sees four (Reports is manager-only); a field officer sees two (Dashboard and Jobs).
The Development section at the bottom of the sidebar has
its own gating — it only appears when Rails.env.development?
is true, regardless of role. That’s where /lab lives.
Activity 1 — Sign in as each role and observe
Start the development server if it isn’t running:
|
|
Sign out (if you’re currently signed in) and visit
http://localhost:3000. Sign in as each of the three role
users in turn, observing the sidebar each time:
Manager (manager@vera.test / password):
- Sees: Dashboard, Jobs, Technicians, Service Areas, Reports
- Plus: Development → Lab (in dev mode)
Dispatcher (dispatcher@vera.test / password):
- Sees: Dashboard, Jobs, Technicians, Service Areas
- No Reports
- Plus: Development → Lab (in dev mode)
Field Officer (field_officer@vera.test / password):
- Sees: Dashboard, Jobs
- No Technicians, Service Areas, or Reports
- Plus: Development → Lab (in dev mode)
The sidebar item list visibly changes with each sign-in. That’s the chassis’s role-awareness in action.
If the sidebar doesn’t change between roles, double-check
that you completed Lesson 1’s seed task — without the seed,
all three users still have role field_officer from the
chassis defaults.
Refining the item list
The chassis’s item list is a reasonable starting point but a few items don’t quite match what Module 5+ will deliver. Some small adjustments:
Rename Technicians to Field Officers. The chassis used “Technicians” as a generic term; we’ve settled on “field officer” throughout the dispatch deck. Consistency matters for the reader.
Remove the Reports item for now. Reports become a Module 9 topic — the manager’s national reporting view — and we’d rather not dangle a manager-only link to a page that doesn’t exist yet. We’ll add it back in Module 9 when it has content.
Update ITEMS to:
|
|
Four items now. Manager sees all four. Dispatcher sees all four. Field officer sees the first two.
You’ll need to rename the controller and view files to match the new path:
|
|
Open app/controllers/field_officers_controller.rb and rename
the class:
|
|
And update config/routes.rb:
|
|
Activity 2 — Verify the renamed item
Restart your Rails server (the route reload may need a fresh boot in development) and refresh the browser. As the manager or dispatcher, you should see “Field Officers” in the sidebar where “Technicians” was. Click it; the placeholder page loads without error.
Where this leaves us
The sidebar visibly differentiates by role. Each user signs in to a navigation that matches what they need to do.
A few of the linked pages are still placeholders that say “Coming in Module 6” or similar — that’s fine. The next lesson lands the most important page of the lot: each role’s home page. Lesson 3 builds three role-specific home pages, each rendering a map scoped to the role’s responsibility.
A manager will see the full national overview. A dispatcher will see their state’s region. A field officer will see their patch. Same map component shape, different data scope — and suddenly the system feels like it’s aware of you.