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',
|
'the enrolment step with the QR code',
|
||||||
)
|
)
|
||||||
const first = (await box.locator('code').textContent())?.trim() ?? ''
|
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 enterCode(box, dict, first)
|
||||||
await expect(page.getByText(dict['mfa.enrol.done'])).toBeVisible()
|
await expect(page.getByText(dict['mfa.enrol.done'])).toBeVisible()
|
||||||
expect(await sessionAal(page)).toBe('aal2')
|
expect(await sessionAal(page)).toBe('aal2')
|
||||||
// A second factor at aal2: no step-up asked.
|
// A second factor at aal2: no step-up asked.
|
||||||
const second = await enrolFromPage(page, dict, 'Clé de secours')
|
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)).toHaveCount(2)
|
||||||
await expect(
|
await expect(
|
||||||
factorList(page, dict).filter({ hasText: dict['mfa.factor.verified'] }),
|
factorList(page, dict).filter({ hasText: dict['mfa.factor.verified'] }),
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import { coreFailureMessage } from '@/core/failure'
|
|||||||
import { coreRuntime } from '@/core/runtime'
|
import { coreRuntime } from '@/core/runtime'
|
||||||
import { emptySheetDocument } from '@/core/sheetDocumentOps'
|
import { emptySheetDocument } from '@/core/sheetDocumentOps'
|
||||||
import { getSupabaseClient } from '@/lib/supabase'
|
import { getSupabaseClient } from '@/lib/supabase'
|
||||||
|
import { useAuthStore } from '@/state/authStore'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
|
|
||||||
@@ -95,6 +96,7 @@ export default function AdminSheetCreateRoute() {
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const locale = useLocaleStore((s) => s.locale)
|
const locale = useLocaleStore((s) => s.locale)
|
||||||
const { editor } = useAdminPermissions()
|
const { editor } = useAdminPermissions()
|
||||||
|
const grantsStatus = useAuthStore((s) => s.catalogGrantsStatus)
|
||||||
const species = useAdminQuery('species', listCatalogSpecies)
|
const species = useAdminQuery('species', listCatalogSpecies)
|
||||||
const [values, setValues] = useState<SheetFormValues>(EMPTY)
|
const [values, setValues] = useState<SheetFormValues>(EMPTY)
|
||||||
const [slugEdited, setSlugEdited] = useState(false)
|
const [slugEdited, setSlugEdited] = useState(false)
|
||||||
@@ -110,11 +112,19 @@ export default function AdminSheetCreateRoute() {
|
|||||||
if (first) document.getElementById(fieldId(first))?.focus()
|
if (first) document.getElementById(fieldId(first))?.focus()
|
||||||
}, [errorRound, errors])
|
}, [errorRound, errors])
|
||||||
|
|
||||||
// A display rule like the « Nouvelle fiche » button: a reviewer or a
|
// A display rule like the « Nouvelle fiche » button: once the caller's own
|
||||||
// publisher reaching the address is not offered the form. The server still
|
// grants are read, a reviewer or a publisher reaching the address is not
|
||||||
// refuses the creation to anyone without the editor capability.
|
// 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 (
|
if (
|
||||||
!editor ||
|
(grantsStatus === 'ready' && !editor) ||
|
||||||
(species.state.status === 'error' &&
|
(species.state.status === 'error' &&
|
||||||
isRightsRefusal(species.state.failure))
|
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
|
* « Accès non autorisé » (contract §5.3, BDR-094): what a catalogue or
|
||||||
* administration page shows when the server refuses (`rights.*`, and
|
* administration page shows when the server refuses (`rights.*`, and
|
||||||
* `not_found` under /app/anatomy), the same whether the sheet exists or not.
|
* `not_found` under /app/anatomy), the same whether the sheet exists or not;
|
||||||
* Nothing from the address is echoed.
|
* 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() {
|
export default function AccessDenied() {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ export interface AuthState {
|
|||||||
* Empty until loaded and when the read fails.
|
* Empty until loaded and when the read fails.
|
||||||
*/
|
*/
|
||||||
catalogGrants: OwnCatalogGrant[]
|
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. */
|
/** Subscribes to the client; returns the unsubscribe. Safe to call twice. */
|
||||||
start: () => () => void
|
start: () => () => void
|
||||||
refreshAccount: () => Promise<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),
|
loadWorkspace(client, user, profile, setOwn, get),
|
||||||
syncAvatar(client, user, setOwn, get).catch(() => setOwn({ avatar: null })),
|
syncAvatar(client, user, setOwn, get).catch(() => setOwn({ avatar: null })),
|
||||||
listOwnCatalogGrants(client, user.id)
|
listOwnCatalogGrants(client, user.id)
|
||||||
.then((catalogGrants) => setOwn({ catalogGrants }))
|
.then((catalogGrants) => setOwn({ catalogGrants, catalogGrantsStatus: 'ready' }))
|
||||||
.catch(() => setOwn({ catalogGrants: [] })),
|
.catch(() => setOwn({ catalogGrants: [], catalogGrantsStatus: 'failed' })),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,6 +167,7 @@ function accountReset(get: Get): Partial<AuthState> {
|
|||||||
avatarUrl: null,
|
avatarUrl: null,
|
||||||
workspace: { status: 'idle' },
|
workspace: { status: 'idle' },
|
||||||
catalogGrants: [],
|
catalogGrants: [],
|
||||||
|
catalogGrantsStatus: 'loading',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,6 +239,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
|
|||||||
avatarUrl: null,
|
avatarUrl: null,
|
||||||
workspace: { status: 'idle' },
|
workspace: { status: 'idle' },
|
||||||
catalogGrants: [],
|
catalogGrants: [],
|
||||||
|
catalogGrantsStatus: 'loading',
|
||||||
|
|
||||||
start: () => {
|
start: () => {
|
||||||
const client = getSupabaseClient()
|
const client = getSupabaseClient()
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ function mount(
|
|||||||
grants: OwnCatalogGrant[],
|
grants: OwnCatalogGrant[],
|
||||||
roles: PlatformRole[] = [],
|
roles: PlatformRole[] = [],
|
||||||
) {
|
) {
|
||||||
useAuthStore.setState({ catalogGrants: grants, roles })
|
useAuthStore.setState({ catalogGrants: grants, catalogGrantsStatus: 'ready', roles })
|
||||||
return render(
|
return render(
|
||||||
<MemoryRouter initialEntries={[path]}>
|
<MemoryRouter initialEntries={[path]}>
|
||||||
<Routes>
|
<Routes>
|
||||||
@@ -655,6 +655,15 @@ describe('Sheet creation (A1)', () => {
|
|||||||
expect(rpcArgs('create_official_sheet')).toEqual([])
|
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', () => {
|
it('proposes a slug from the French name', () => {
|
||||||
expect(proposeSlug('Chien : squelette et rachis ')).toBe(
|
expect(proposeSlug('Chien : squelette et rachis ')).toBe(
|
||||||
'chien-squelette-et-rachis',
|
'chien-squelette-et-rachis',
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ const INITIAL = {
|
|||||||
avatarUrl: null,
|
avatarUrl: null,
|
||||||
workspace: { status: 'idle' as const },
|
workspace: { status: 'idle' as const },
|
||||||
catalogGrants: [],
|
catalogGrants: [],
|
||||||
|
catalogGrantsStatus: 'loading' as const,
|
||||||
}
|
}
|
||||||
|
|
||||||
let fake: FakeSupabase
|
let fake: FakeSupabase
|
||||||
|
|||||||
Reference in new issue
Block a user