feat(auth): merge reporter, supervisor, capa_owner into ssa role

Add Site Safety Assistant (ssa) role replacing reporter, supervisor and
capa_owner. Portals move under /ssa (overview, my-reports, incidents,
capas). Update RLS, schema, API role checks, notification recipients,
nav and tests. Add db/ops/2026-11-06-merge-roles-into-ssa.sql (not yet
applied; needs owner go-ahead and a pg_dump first).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Weei Han
2026-11-06 21:34:10 +08:00
co-authored by Claude Sonnet 5.5
parent 701fefd286
commit 813395700f
31 changed files with 123 additions and 96 deletions
+4 -4
View File
@@ -2,7 +2,7 @@
import { useState } from 'react'
import { useRouter } from 'next/navigation'
import { ALL_ROLES, type UserRole } from '@/lib/auth/roles'
import { ALL_ROLES, ROLE_LABELS, type UserRole } from '@/lib/auth/roles'
import { Modal } from '@/components/ui/modal'
import { INPUT_CLASS as inp } from '@/components/ui/field'
@@ -23,7 +23,7 @@ interface Props {
sites: SiteOption[]
}
const EMPTY = { email: '', name: '', phone: '', role: 'reporter' as UserRole, site_id: '', password: '' }
const EMPTY = { email: '', name: '', phone: '', role: 'ssa' as UserRole, site_id: '', password: '' }
const lbl = 'block text-xs font-medium text-gray-600 mb-1'
@@ -135,7 +135,7 @@ export function UserManager({ users, sites }: Props) {
<select value={u.role} disabled={busyId === u.id}
onChange={e => patchUser(u.id, { role: e.target.value })}
className="border border-divider px-2 py-1 text-xs focus:outline-none focus:ring-1 focus:ring-accent cursor-pointer">
{ALL_ROLES.map(r => <option key={r} value={r}>{r.replace(/_/g, ' ')}</option>)}
{ALL_ROLES.map(r => <option key={r} value={r}>{ROLE_LABELS[r]}</option>)}
</select>
</td>
<td className="px-5 py-3">
@@ -224,7 +224,7 @@ export function UserManager({ users, sites }: Props) {
<select id="au-role" value={form.role}
onChange={e => setForm(v => ({ ...v, role: e.target.value as UserRole }))}
className={inp}>
{ALL_ROLES.map(r => <option key={r} value={r}>{r.replace(/_/g, ' ')}</option>)}
{ALL_ROLES.map(r => <option key={r} value={r}>{ROLE_LABELS[r]}</option>)}
</select>
</div>
<div>
+8 -10
View File
@@ -16,14 +16,13 @@ export interface NavItem {
}
const NAV_ITEMS: Record<string, NavItem[]> = {
reporter: [
{ label: 'My Reports', href: '/reporter', icon: ClipboardList },
ssa: [
{ label: 'Overview', href: '/ssa', icon: AlignLeft },
{ label: 'My Reports', href: '/ssa/my-reports', icon: ClipboardList },
{ label: 'Site Incidents', href: '/ssa/incidents', icon: ClipboardList },
{ label: 'My CAPAs', href: '/ssa/capas', icon: CircleCheck },
{ label: 'New Incident', href: '/report', icon: Plus },
],
supervisor: [
{ label: 'Overview', href: '/supervisor', icon: AlignLeft },
{ label: 'Incidents', href: '/supervisor/incidents', icon: ClipboardList },
],
hse: [
{ label: 'Dashboard', href: '/hse/dashboard', icon: LayoutDashboard },
{ label: 'Incidents', href: '/hse/incidents', icon: ClipboardList },
@@ -31,7 +30,6 @@ const NAV_ITEMS: Record<string, NavItem[]> = {
{ label: 'Settings', href: '/hse/settings', icon: Settings },
],
management: [{ label: 'Dashboard', href: '/management', icon: LayoutDashboard }],
capa_owner: [{ label: 'My CAPAs', href: '/capa-owner', icon: CircleCheck }],
admin: [
{ label: 'Admin', href: '/admin', icon: Users },
{ label: 'Dashboard', href: '/hse/dashboard', icon: LayoutDashboard },
@@ -42,10 +40,10 @@ const NAV_ITEMS: Record<string, NavItem[]> = {
],
}
const EXACT_ROOTS = ['/reporter', '/supervisor', '/management', '/capa-owner', '/admin', '/report', '/account']
const EXACT_ROOTS = ['/ssa', '/management', '/admin', '/report', '/account']
export function navItemsFor(role: string): NavItem[] {
return NAV_ITEMS[role] ?? NAV_ITEMS.reporter
return NAV_ITEMS[role] ?? NAV_ITEMS.ssa
}
export function isActivePath(href: string, pathname: string): boolean {
@@ -54,6 +52,6 @@ export function isActivePath(href: string, pathname: string): boolean {
export function searchHrefFor(role: string): string | null {
if (role === 'hse' || role === 'admin') return '/hse/incidents'
if (role === 'supervisor') return '/supervisor/incidents'
if (role === 'ssa') return '/ssa/incidents'
return null
}