fix(supabase): get_sheet_version returns a deprecated version's fingerprint

PreviewSheet checks the fingerprint of published and deprecated versions; M5 gave it for published only, so no withdrawn version opened in the catalogue. Redefined in M7 (owner decision, BDR-098); pgTAP 022 +3, suite 1941 on the sandbox; contract §10, §12.3, §17.10.
This commit is contained in:
bchanot committed 2026-11-02 17:18:26 +01:00
1 parent ffefb91204
commit 9f7824dc08
3 files changed
+83 -11

No files matched your search

+21 -7
View File
@@ -4,7 +4,7 @@
-- unknown, deleted, personal or forbidden sheet gets one answer. Fixtures are
-- scoped to the ids created here.
begin;
select plan(40);
select plan(43);
-- Accounts. O owner, A admin, E admin + editor, V reviewer, P admin +
-- publisher, R reader, N no right. Every one has a verified factor and a live
@@ -40,7 +40,8 @@ create table pg_temp.k (key text primary key, id uuid not null);
insert into pg_temp.k values
('SP', '22200000-0000-0000-0000-000000000001'), ('SA', '22200000-0000-0000-0000-000000000002'),
('SD', '22200000-0000-0000-0000-000000000003'), ('PS', '22200000-0000-0000-0000-000000000004'),
('WC', '22200000-0000-0000-0000-000000000005'),
('WC', '22200000-0000-0000-0000-000000000005'), ('SX', '22200000-0000-0000-0000-000000000006'),
('SX.v1', '22300000-0000-0000-0000-000000000061'), ('SX.v2', '22300000-0000-0000-0000-000000000062'),
('SP.v1', '22300000-0000-0000-0000-000000000011'), ('SP.v2', '22300000-0000-0000-0000-000000000012'),
('SA.v1', '22300000-0000-0000-0000-000000000021'), ('WC.v1', '22300000-0000-0000-0000-000000000051'),
('SP.r', '22500000-0000-0000-0000-000000000001'),
@@ -64,13 +65,19 @@ insert into public.anatomical_sheets (id, species_id, name, slug, is_official, v
(pg_temp.id('SA'), 'equine', 'SA', 'm22-sa', true, 'private', 'archived', now(), null, null, null),
(pg_temp.id('SD'), 'equine', 'SD', 'm22-sd', true, 'private', 'deleted', null, now(), null, null),
(pg_temp.id('PS'), 'equine', 'PS', 'm22-ps', false, 'private', 'active', null, null, '22000000-0000-0000-0000-00000000000e', null),
(pg_temp.id('WC'), 'equine', 'WC', 'm22-wc', true, 'private', 'active', null, null, null, pg_temp.id('h.v'));
(pg_temp.id('WC'), 'equine', 'WC', 'm22-wc', true, 'private', 'active', null, null, null, pg_temp.id('h.v')),
(pg_temp.id('SX'), 'equine', 'SX', 'm22-sx', true, 'private', 'active', null, null, null, null);
insert into public.anatomical_sheet_versions (id, sheet_id, version_number, status, document_schema_version, content,
published_at, document_fingerprint) values
(pg_temp.id('SP.v1'), pg_temp.id('SP'), 1, 'published', 2, pg_temp.doc('Publiée'), now(), repeat('0', 64)),
(pg_temp.id('SP.v2'), pg_temp.id('SP'), 2, 'draft', 2, pg_temp.doc('Brouillon'), null, null),
(pg_temp.id('SA.v1'), pg_temp.id('SA'), 1, 'published', 2, pg_temp.doc('Archivée'), now(), repeat('0', 64)),
(pg_temp.id('WC.v1'), pg_temp.id('WC'), 1, 'draft', 2, pg_temp.doc('Copie'), null, null);
(pg_temp.id('WC.v1'), pg_temp.id('WC'), 1, 'draft', 2, pg_temp.doc('Copie'), null, null),
(pg_temp.id('SX.v2'), pg_temp.id('SX'), 2, 'published', 2, pg_temp.doc('Courante'), now(), repeat('e', 64));
insert into public.anatomical_sheet_versions (id, sheet_id, version_number, status, document_schema_version, content,
published_at, deprecated_at, document_fingerprint)
values (pg_temp.id('SX.v1'), pg_temp.id('SX'), 1, 'deprecated', 2, pg_temp.doc('Retirée'), now(), now(), repeat('d', 64));
update public.anatomical_sheets set current_version_id = pg_temp.id('SX.v2'), last_version_number = 2 where id = pg_temp.id('SX');
update public.anatomical_sheet_versions set authors = array['22000000-0000-0000-0000-00000000000e'::uuid]
where id = pg_temp.id('SP.v2');
update public.anatomical_sheets set current_version_id = pg_temp.id('SP.v1'), last_version_number = 2 where id = pg_temp.id('SP');
@@ -133,11 +140,11 @@ select is(pg_temp.listed(), '42501 rights.mfa', 'editor at aal1: list refused');
select is(pg_temp.val($$ select public.get_official_sheet_admin(pg_temp.id('SP')) ->> 'slug' $$), '42501 rights.mfa', 'editor at aal1: sheet refused');
select pg_temp.as_user('E', 'aal2');
select is(pg_temp.listed(), 'SA,SP,WC,h', 'editor at aal2: every official sheet but the deleted one');
select is(pg_temp.listed(), 'SA,SP,SX,WC,h', 'editor at aal2: every official sheet but the deleted one');
select pg_temp.as_user('V', 'aal2');
select is(pg_temp.listed(), 'SA,SP,WC,h', 'reviewer at aal2: the same list');
select is(pg_temp.listed(), 'SA,SP,SX,WC,h', 'reviewer at aal2: the same list');
select pg_temp.as_user('P', 'aal2');
select is(pg_temp.listed(), 'SA,SP,WC,h', 'publisher at aal2: the same list');
select is(pg_temp.listed(), 'SA,SP,SX,WC,h', 'publisher at aal2: the same list');
select is(pg_temp.val($$ select public.get_official_sheet_admin(pg_temp.id('SD')) ->> 'slug' $$), '42501 not_found', 'deleted sheet: not_found');
select is(pg_temp.val($$ select public.get_official_sheet_admin(pg_temp.id('PS')) ->> 'slug' $$), '42501 not_found', 'personal sheet: not_found');
select is(pg_temp.val($$ select public.get_official_sheet_admin('22200000-0000-0000-0000-0000000000ff') ->> 'slug' $$), '42501 not_found', 'unknown id: not_found');
@@ -167,6 +174,13 @@ select is(pg_temp.val($$ select public.get_official_sheet_admin(pg_temp.id('SP')
select is(pg_temp.val($$ select (public.get_official_sheet_admin(pg_temp.id('SA')) ->> 'status') $$), 'archived', 'overview of an archived sheet');
select is(pg_temp.val($$ select public.get_official_sheet_admin(pg_temp.id('WC')) #>> '{working_copy_source,version_id}' $$), pg_temp.id('h.v')::text, 'overview: the working copy names its source');
-- ============ get_sheet_version: the fingerprint of a deprecated version (BDR-098) ============
select pg_temp.as_user('R', 'aal1');
select is(pg_temp.val($$ select public.get_sheet_version(pg_temp.id('SX.v1')) ->> 'fingerprint' $$), repeat('d', 64), 'reader: a deprecated version carries its publication fingerprint');
select is(pg_temp.val($$ select public.get_sheet_version(pg_temp.id('SX.v2')) ->> 'fingerprint' $$), repeat('e', 64), 'reader: a published version carries its fingerprint');
select pg_temp.as_user('E', 'aal2');
select is(pg_temp.val($$ select public.get_sheet_version(pg_temp.id('SP.v2')) ->> 'fingerprint' $$), 'ok', 'editor: a draft has no fingerprint');
-- ============ Privileges and nature ============
reset role;
select ok(not has_function_privilege('anon', 'public.list_official_sheets_admin()', 'execute')