fix(app): sheet creation form only for editors; review findings (V1-2.5 K)

Verifier C4: /app/admin/sheets/new shows Accès non autorisé without sheet_editor (display rule, server unchanged), tests. Security: M7 restates get_sheet_version grants; e2e enrolment check never prints the setup key. Contract clarifications: phone skips, run evidence, one intermittent e2e failure tracked.
This commit is contained in:
bchanot committed 2026-11-02 18:18:54 +01:00
1 parent 3d2b5a5f1c
commit 02625a76b6
5 files changed
+46 -3

No files matched your search

+2 -1
View File
@@ -113,7 +113,8 @@ async function enrolFromPage(
box.getByRole('img', { name: dict['mfa.enrol.qr_alt'] }),
).toBeVisible()
const secret = (await box.locator('code').textContent())?.trim() ?? ''
expect(secret).toMatch(/^[A-Z2-7]{16,}$/)
// A boolean, so a failure report never prints the secret.
expect(/^[A-Z2-7]{16,}$/.test(secret), 'base32 setup key shown').toBe(true)
await enterCode(box, dict, secret)
await expect(page.getByText(dict['mfa.enrol.done'])).toBeVisible()
return secret
@@ -18,6 +18,7 @@ import Input from '@/components/ui/Input'
import Notice from '@/components/ui/Notice'
import Select from '@/components/ui/Select'
import { failureMessage, speciesName } from '@/admin/labels'
import { useAdminPermissions } from '@/admin/permissions'
import { isRightsRefusal, useAdminQuery } from '@/admin/useAdminQuery'
import {
parseSheet,
@@ -93,6 +94,7 @@ export default function AdminSheetCreateRoute() {
const heading = usePageHeading()
const navigate = useNavigate()
const locale = useLocaleStore((s) => s.locale)
const { editor } = useAdminPermissions()
const species = useAdminQuery('species', listCatalogSpecies)
const [values, setValues] = useState<SheetFormValues>(EMPTY)
const [slugEdited, setSlugEdited] = useState(false)
@@ -108,9 +110,13 @@ export default function AdminSheetCreateRoute() {
if (first) document.getElementById(fieldId(first))?.focus()
}, [errorRound, errors])
// A display rule like the « Nouvelle fiche » button: a reviewer or a
// publisher reaching the address is not offered the form. The server still
// refuses the creation to anyone without the editor capability.
if (
species.state.status === 'error' &&
isRightsRefusal(species.state.failure)
!editor ||
(species.state.status === 'error' &&
isRightsRefusal(species.state.failure))
)
return <AccessDenied />
+13
View File
@@ -642,6 +642,19 @@ describe('Official sheets list (H1)', () => {
})
describe('Sheet creation (A1)', () => {
it.each([
['a reviewer', [grant('sheet_reviewer')], []],
['a publisher', [grant('sheet_publisher')], []],
['an owner without the editor capability', [], ['owner']],
] as const)('offers no form to %s reaching the address', async (_, grants, roles) => {
mount('/app/admin/sheets/new', [...grants], [...roles])
expect(
await screen.findByRole('heading', { name: fr['access_denied.title'] }),
).toBeInTheDocument()
expect(screen.queryByLabelText('Espèce')).toBeNull()
expect(rpcArgs('create_official_sheet')).toEqual([])
})
it('proposes a slug from the French name', () => {
expect(proposeSlug('Chien : squelette et rachis ')).toBe(
'chien-squelette-et-rachis',