fix(supabase): V1-2.1 audit M1 M2 M3 and LOW fixes in M5

Approval needs an active sheet (lock sheet, version, round); a base only
from a still-published round version; rights.mfa before rights.capability;
withdrawal of a published round refused; approver separation at publish;
deprecate and working copy serialised; closed codes; append-only acks;
upload policy bound to the registering editor. pgTAP 017-019 added.
This commit is contained in:
bchanot committed 2026-10-28 18:14:09 +01:00
1 parent 3914eaa866
commit d05f75da84
10 files changed
+1477 -127

No files matched your search

+16 -8
View File
@@ -158,7 +158,9 @@ insert into public.anatomical_catalog_grants (user_id,grant_kind,reason,granted_
-- A catalogue reader sees the published version and its drawing; not the grants.
set local role authenticated;
select pg_temp.act('e0000000-0000-0000-0000-0000000000cc', gen_random_uuid());
select is((select jsonb_array_length(public.list_official_catalog())), 1, 'the reader sees one catalogue sheet');
select is((select count(*) from jsonb_array_elements(public.list_official_catalog()) e
where (e ->> 'sheet_id')::uuid = (select id from pg_temp.k where key='sheet')), 1::bigint,
'the reader sees the published sheet in the catalogue');
select is((select (public.get_sheet_version((select id from pg_temp.k where key='v1'))) ->> 'status'), 'published',
'the reader reads the published version by id');
@@ -168,7 +170,9 @@ select public.deprecate_sheet_version((select id from pg_temp.k where key='v1'),
select pg_temp.act('e0000000-0000-0000-0000-0000000000cc', gen_random_uuid());
select is((select (public.get_sheet_version((select id from pg_temp.k where key='v1'))) ->> 'status'), 'deprecated',
'a deprecated version stays readable by id (D8)');
select is((select jsonb_array_length(public.list_official_catalog())), 0, 'the sheet leaves the catalogue list once its last version is deprecated');
select is((select count(*) from jsonb_array_elements(public.list_official_catalog()) e
where (e ->> 'sheet_id')::uuid = (select id from pg_temp.k where key='sheet')), 0::bigint,
'the sheet leaves the catalogue list once its last version is deprecated');
-- ============ Species rules (§7.2) ============
select pg_temp.act('e0000000-0000-0000-0000-00000000000e','e1000000-0000-0000-0000-00000000000e');
@@ -189,16 +193,16 @@ select pg_temp.act('e0000000-0000-0000-0000-00000000000e','e1000000-0000-0000-00
select throws_ok($$ select public.create_sheet_working_copy((select id from pg_temp.k where key='v1'), 'copie') $$,
'P0001', 'working_copy.source_invalid', 'a working copy of a non-historical version is refused');
-- ============ Base only from a round-published version (§6.2) ============
-- v1 was published through r2 (a V1-2 round), so a new draft takes it as base
-- (passed explicitly, since deprecating the only published version cleared the
-- sheet's current version).
-- ============ Base only from a version still published through a round (§6.2) ============
-- v1 was published through r2 and then deprecated (passed explicitly, since
-- deprecating the only published version cleared the sheet's current
-- version): a deprecated source gives no base. The positive base case is in 017.
insert into pg_temp.k select 'v2', public.create_sheet_draft(
(select id from pg_temp.k where key='sheet'), (select id from pg_temp.k where key='v1'), 'new edition');
reset role;
select is(
(select (source_version_id = (select id from pg_temp.k where key='v1')) from public.anatomical_sheet_versions where id=(select id from pg_temp.k where key='v2')),
true, 'a draft derived from a round-published version records it as its base');
(select source_version_id from public.anatomical_sheet_versions where id=(select id from pg_temp.k where key='v2')),
null, 'a draft derived from a deprecated version has no base');
-- The publish gate: a direct UPDATE of a real draft to published is refused for
-- the table owner (no approved round named).
select throws_ok($$ update public.anatomical_sheet_versions set status='published', published_at=now(), document_fingerprint=repeat('a',64)
@@ -336,7 +340,11 @@ select throws_ok($$ select public.delete_sheet_version((select id from pg_temp.k
-- ============ Working copy of the historical sheet, positive path (§14.3) ============
-- Confirm the seeded historical drawing object, then create the working copy.
-- A working copy already active on this stack is archived inside this
-- transaction first (LRN-093: scope to the fixture, never to the stack state).
reset role;
update public.anatomical_sheets set status = 'archived', archived_at = now()
where status = 'active' and private.is_historical_working_copy(id);
insert into storage.objects (bucket_id, name, metadata)
select 'anatomical-sheet-assets', a.sha256 || '.svg', jsonb_build_object('size', a.byte_size)
from public.anatomical_sheet_assets a where a.sheet_id = '503dc301-a8b1-50d4-9e44-0919b2fc2916'