fix(app): creation page waits for own grants; e2e never prints setup keys
Delta verifier: two remaining setup-key assertions now booleans. Its observation: the editor rule read grants before they loaded; authStore.catalogGrantsStatus (loading, ready, failed): the page waits, and a failed read leaves the decision to the server. App 654, e2e:ui 227, admin shell spec 14 + 6 skipped.
This commit is contained in:
1 parent
02625a76b6
commit
f04bfdd040
6 files changed
+37
-11
No files matched your search
@@ -250,13 +250,13 @@ for (const [locale, dict] of LANGUAGES) {
|
||||
'the enrolment step with the QR code',
|
||||
)
|
||||
const first = (await box.locator('code').textContent())?.trim() ?? ''
|
||||
expect(first).toMatch(/^[A-Z2-7]{16,}$/)
|
||||
expect(/^[A-Z2-7]{16,}$/.test(first), 'base32 setup key shown').toBe(true)
|
||||
await enterCode(box, dict, first)
|
||||
await expect(page.getByText(dict['mfa.enrol.done'])).toBeVisible()
|
||||
expect(await sessionAal(page)).toBe('aal2')
|
||||
// A second factor at aal2: no step-up asked.
|
||||
const second = await enrolFromPage(page, dict, 'Clé de secours')
|
||||
expect(second).not.toBe(first)
|
||||
expect(second !== first, 'a new setup key').toBe(true)
|
||||
await expect(factorList(page, dict)).toHaveCount(2)
|
||||
await expect(
|
||||
factorList(page, dict).filter({ hasText: dict['mfa.factor.verified'] }),
|
||||
|
||||
@@ -33,6 +33,7 @@ import { coreFailureMessage } from '@/core/failure'
|
||||
import { coreRuntime } from '@/core/runtime'
|
||||
import { emptySheetDocument } from '@/core/sheetDocumentOps'
|
||||
import { getSupabaseClient } from '@/lib/supabase'
|
||||
import { useAuthStore } from '@/state/authStore'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
@@ -95,6 +96,7 @@ export default function AdminSheetCreateRoute() {
|
||||
const navigate = useNavigate()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const { editor } = useAdminPermissions()
|
||||
const grantsStatus = useAuthStore((s) => s.catalogGrantsStatus)
|
||||
const species = useAdminQuery('species', listCatalogSpecies)
|
||||
const [values, setValues] = useState<SheetFormValues>(EMPTY)
|
||||
const [slugEdited, setSlugEdited] = useState(false)
|
||||
@@ -110,11 +112,19 @@ 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.
|
||||
// A display rule like the « Nouvelle fiche » button: once the caller's own
|
||||
// grants are read, a reviewer or a publisher reaching the address is not
|
||||
// offered the form. While they load nothing is decided; if the read failed
|
||||
// the form shows and the server, which refuses creation to anyone without
|
||||
// the editor capability, decides.
|
||||
if (grantsStatus === 'loading')
|
||||
return (
|
||||
<p role="status" className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('shell.loading_session')}
|
||||
</p>
|
||||
)
|
||||
if (
|
||||
!editor ||
|
||||
(grantsStatus === 'ready' && !editor) ||
|
||||
(species.state.status === 'error' &&
|
||||
isRightsRefusal(species.state.failure))
|
||||
)
|
||||
|
||||
@@ -6,8 +6,10 @@ 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.
|
||||
* `not_found` under /app/anatomy), the same whether the sheet exists or not;
|
||||
* also the sheet creation page for an account whose own grants hold no editor
|
||||
* capability (a display rule, the server still decides). Nothing from the
|
||||
* address is echoed.
|
||||
*/
|
||||
export default function AccessDenied() {
|
||||
const t = useT()
|
||||
|
||||
@@ -68,6 +68,8 @@ export interface AuthState {
|
||||
* Empty until loaded and when the read fails.
|
||||
*/
|
||||
catalogGrants: OwnCatalogGrant[]
|
||||
/** Whether `catalogGrants` is read yet: a display rule waits for `ready`, and a `failed` read leaves the decision to the server. */
|
||||
catalogGrantsStatus: 'loading' | 'ready' | 'failed'
|
||||
/** Subscribes to the client; returns the unsubscribe. Safe to call twice. */
|
||||
start: () => () => void
|
||||
refreshAccount: () => Promise<void>
|
||||
@@ -150,8 +152,8 @@ async function loadAccount(client: FaunosteoClient, user: User, set: Set, get: G
|
||||
loadWorkspace(client, user, profile, setOwn, get),
|
||||
syncAvatar(client, user, setOwn, get).catch(() => setOwn({ avatar: null })),
|
||||
listOwnCatalogGrants(client, user.id)
|
||||
.then((catalogGrants) => setOwn({ catalogGrants }))
|
||||
.catch(() => setOwn({ catalogGrants: [] })),
|
||||
.then((catalogGrants) => setOwn({ catalogGrants, catalogGrantsStatus: 'ready' }))
|
||||
.catch(() => setOwn({ catalogGrants: [], catalogGrantsStatus: 'failed' })),
|
||||
])
|
||||
}
|
||||
|
||||
@@ -165,6 +167,7 @@ function accountReset(get: Get): Partial<AuthState> {
|
||||
avatarUrl: null,
|
||||
workspace: { status: 'idle' },
|
||||
catalogGrants: [],
|
||||
catalogGrantsStatus: 'loading',
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,6 +239,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
|
||||
avatarUrl: null,
|
||||
workspace: { status: 'idle' },
|
||||
catalogGrants: [],
|
||||
catalogGrantsStatus: 'loading',
|
||||
|
||||
start: () => {
|
||||
const client = getSupabaseClient()
|
||||
|
||||
@@ -149,7 +149,7 @@ function mount(
|
||||
grants: OwnCatalogGrant[],
|
||||
roles: PlatformRole[] = [],
|
||||
) {
|
||||
useAuthStore.setState({ catalogGrants: grants, roles })
|
||||
useAuthStore.setState({ catalogGrants: grants, catalogGrantsStatus: 'ready', roles })
|
||||
return render(
|
||||
<MemoryRouter initialEntries={[path]}>
|
||||
<Routes>
|
||||
@@ -655,6 +655,15 @@ describe('Sheet creation (A1)', () => {
|
||||
expect(rpcArgs('create_official_sheet')).toEqual([])
|
||||
})
|
||||
|
||||
it('decides nothing while the own grants load, and leaves a failed read to the server', async () => {
|
||||
mount('/app/admin/sheets/new', [])
|
||||
useAuthStore.setState({ catalogGrantsStatus: 'loading' })
|
||||
expect(await screen.findByRole('status')).toHaveTextContent(fr['shell.loading_session'])
|
||||
expect(screen.queryByRole('heading', { name: fr['access_denied.title'] })).toBeNull()
|
||||
useAuthStore.setState({ catalogGrantsStatus: 'failed' })
|
||||
expect(await screen.findByLabelText('Espèce')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('proposes a slug from the French name', () => {
|
||||
expect(proposeSlug('Chien : squelette et rachis ')).toBe(
|
||||
'chien-squelette-et-rachis',
|
||||
|
||||
@@ -29,6 +29,7 @@ const INITIAL = {
|
||||
avatarUrl: null,
|
||||
workspace: { status: 'idle' as const },
|
||||
catalogGrants: [],
|
||||
catalogGrantsStatus: 'loading' as const,
|
||||
}
|
||||
|
||||
let fake: FakeSupabase
|
||||
|
||||
Reference in new issue
Block a user