feat(app): admin and catalogue entries, step-up guard, MFA in Mon compte (V1-2.5 E, F)

Nav hint from own grants and roles (never a control); RequireCatalog, RequireAdmin (no admin read before aal2), Accès non autorisé page, placeholder routes; TOTP factor list, enrolment with QR and one-time secret, removal, inline step-up for aal2 actions, step-up in password reset; auth kind aal2_required. App 601, e2e:ui 227.
This commit is contained in:
bchanot committed 2026-11-02 16:49:37 +01:00
1 parent 99488d71d9
commit 4744e28986
38 files changed
+1818 -55

No files matched your search

@@ -0,0 +1,26 @@
import ButtonLink from '@/components/ui/ButtonLink'
import Card from '@/components/ui/Card'
import { usePageHeading } from '@/app/usePageHeading'
import { useT } from '@/i18n/useT'
/**
* « Accès non autorisé » (contract §5.3, BDR-094): what a catalogue or
* administration page shows when the server refuses (`rights.*`, and
* `not_found` under /app/anatomy), the same whether the sheet exists or not.
* Nothing from the address is echoed.
*/
export default function AccessDenied() {
const t = useT()
const heading = usePageHeading()
return (
<Card as="section" className="space-y-3 p-5 sm:p-6">
<h1 ref={heading} tabIndex={-1} className="outline-none font-serif text-2xl text-[var(--color-ink)]">
{t('access_denied.title')}
</h1>
<p className="text-sm text-[var(--color-ink-muted)]">{t('access_denied.body')}</p>
<ButtonLink to="/app" variant="secondary">
{t('access_denied.back')}
</ButtonLink>
</Card>
)
}
@@ -0,0 +1,16 @@
import { usePageHeading } from '@/app/usePageHeading'
import { useT } from '@/i18n/useT'
/**
* V1-2.5 placeholder: the heading of a catalogue or administration page that
* a later slice of the step builds (G to I). It requests nothing.
*/
export default function PlaceholderPage({ titleKey }: { titleKey: string }) {
const t = useT()
const heading = usePageHeading()
return (
<h1 ref={heading} tabIndex={-1} className="outline-none font-serif text-2xl sm:text-3xl text-[var(--color-ink)]">
{t(titleKey)}
</h1>
)
}
+46 -19
View File
@@ -1,5 +1,8 @@
import { Fragment } from 'react'
import { NavLink } from 'react-router-dom'
import Icon, { type IconName } from '@/components/ui/Icon'
import { navigationHint, type NavigationHint } from '@/auth/navigationHint'
import { useAuthStore } from '@/state/authStore'
import { useT } from '@/i18n/useT'
interface NavItem {
@@ -8,12 +11,24 @@ interface NavItem {
labelKey: string
hintKey?: string
end?: boolean
/** Shown only when this part of the navigation hint holds (V1-2, §11.1). */
shownWhen?: keyof NavigationHint
/** Set apart by a separator above and below, as on the validated board 10. */
separated?: boolean
}
export const NAV_ITEMS: readonly NavItem[] = [
{ to: '/app', icon: 'dashboard', labelKey: 'shell.nav.dashboard', end: true },
{ to: '/app/clients', icon: 'users', labelKey: 'shell.nav.clients' },
{ to: '/app/animals', icon: 'paw', labelKey: 'shell.nav.animals' },
{ to: '/app/anatomy', icon: 'book', labelKey: 'shell.nav.anatomy', shownWhen: 'catalog' },
{
to: '/app/admin',
icon: 'shield',
labelKey: 'shell.nav.admin',
shownWhen: 'admin',
separated: true,
},
{ to: '/app/account', icon: 'user', labelKey: 'shell.nav.account' },
{
to: '/',
@@ -33,29 +48,41 @@ function linkClass(active: boolean): string {
].join(' ')
}
/** The destinations of the shell, in the validated mockup's order; `onNavigate` closes the mobile drawer. */
/**
* The destinations of the shell, in the validated mockup's order; `onNavigate`
* closes the mobile drawer. « Fiches anatomiques » and « Administration » follow
* the account's own grant rows and roles: hiding an entry protects nothing,
* the pages act on the server's refusal.
*/
export default function SidebarNav({ onNavigate }: { onNavigate?: () => void }) {
const t = useT()
const grants = useAuthStore((s) => s.catalogGrants)
const roles = useAuthStore((s) => s.roles)
const hint = navigationHint(grants, roles)
const items = NAV_ITEMS.filter((item) => !item.shownWhen || hint[item.shownWhen])
return (
<nav aria-label={t('shell.nav_label')} className="space-y-1">
{NAV_ITEMS.map((item) => (
<NavLink
key={item.to}
to={item.to}
end={item.end}
onClick={onNavigate}
className={({ isActive }) => linkClass(isActive)}
>
<Icon name={item.icon} size={20} className="shrink-0" />
<span className="flex min-w-0 flex-col leading-tight">
<span className="truncate">{t(item.labelKey)}</span>
{item.hintKey && (
<span className="truncate text-xs font-normal text-[var(--color-ink-muted)]">
{t(item.hintKey)}
</span>
)}
</span>
</NavLink>
{items.map((item) => (
<Fragment key={item.to}>
{item.separated && <hr className="my-3 border-[var(--color-border)]" />}
<NavLink
to={item.to}
end={item.end}
onClick={onNavigate}
className={({ isActive }) => linkClass(isActive)}
>
<Icon name={item.icon} size={20} className="shrink-0" />
<span className="flex min-w-0 flex-col leading-tight">
<span className="truncate">{t(item.labelKey)}</span>
{item.hintKey && (
<span className="truncate text-xs font-normal text-[var(--color-ink-muted)]">
{t(item.hintKey)}
</span>
)}
</span>
</NavLink>
{item.separated && <hr className="my-3 border-[var(--color-border)]" />}
</Fragment>
))}
</nav>
)