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:
1 parent
ffefb91204
commit
9f7824dc08
3 files changed
+83
-11
No files matched your search
@@ -13,7 +13,8 @@
|
||||
-- rounds, with the names of the people who acted.
|
||||
-- Capability holders at aal2 only (`caller_is_catalog_staff`, the predicate
|
||||
-- of the draft reads); an unknown or forbidden sheet gets one answer. No
|
||||
-- write, no grant, no policy and no rule changes here.
|
||||
-- write, no grant, no policy and no rule changes here. Also: `get_sheet_version`
|
||||
-- returns the fingerprint of a deprecated version (§10, BDR-098).
|
||||
|
||||
-- ===========================================================================
|
||||
-- 1. Helpers
|
||||
@@ -173,13 +174,68 @@ begin
|
||||
end;
|
||||
$$;
|
||||
|
||||
-- ===========================================================================
|
||||
-- 3. get_sheet_version: the fingerprint of a deprecated version too
|
||||
-- ===========================================================================
|
||||
-- M5 returned the fingerprint for published versions only, while the core's
|
||||
-- PreviewSheet checks it for published and deprecated versions alike (§10: a
|
||||
-- deprecated version previews like a published one), so no withdrawn version
|
||||
-- could open in the catalogue. A deprecated version keeps the fingerprint it
|
||||
-- was published with, already public then; a draft still gets none. Owner
|
||||
-- decision 2026-11-02 (BDR-098). Body otherwise identical to M5.
|
||||
create or replace function public.get_sheet_version(version_id uuid)
|
||||
returns jsonb
|
||||
language plpgsql
|
||||
stable
|
||||
security definer
|
||||
set search_path = ''
|
||||
as $$
|
||||
#variable_conflict use_column
|
||||
declare
|
||||
v_uid uuid := auth.uid();
|
||||
v_version public.anatomical_sheet_versions%rowtype;
|
||||
v_sheet public.anatomical_sheets%rowtype;
|
||||
v_allowed boolean;
|
||||
begin
|
||||
if v_uid is null then
|
||||
raise exception 'not_found' using errcode = '42501';
|
||||
end if;
|
||||
select v.* into v_version from public.anatomical_sheet_versions v where v.id = get_sheet_version.version_id;
|
||||
if v_version.id is null then
|
||||
raise exception 'not_found' using errcode = '42501';
|
||||
end if;
|
||||
select s.* into v_sheet from public.anatomical_sheets s where s.id = v_version.sheet_id;
|
||||
v_allowed := private.caller_can_see_official_sheet(v_sheet.id)
|
||||
or (v_version.status in ('published', 'deprecated') and private.can_read_catalog_sheet(v_uid, v_sheet.id));
|
||||
if not v_allowed then
|
||||
raise exception 'not_found' using errcode = '42501';
|
||||
end if;
|
||||
return jsonb_build_object(
|
||||
'sheet_id', v_sheet.id,
|
||||
'version_id', v_version.id,
|
||||
'version_number', v_version.version_number,
|
||||
'status', v_version.status,
|
||||
'species_id', v_sheet.species_id,
|
||||
'document', v_version.content,
|
||||
'revision', v_version.revision,
|
||||
'fingerprint', case when v_version.status in ('published', 'deprecated') then v_version.document_fingerprint end,
|
||||
'drawings', coalesce((
|
||||
select jsonb_agg(jsonb_build_object('asset_id', a.id, 'sha256', a.sha256, 'byte_size', a.byte_size) order by a.id)
|
||||
from public.anatomical_sheet_assets a
|
||||
where a.sheet_id = v_sheet.id and a.uploaded_at is not null
|
||||
and a.id::text = any (private.sheet_document_asset_ids(v_version.content))
|
||||
), '[]'::jsonb)
|
||||
);
|
||||
end;
|
||||
$$;
|
||||
|
||||
comment on function public.list_official_sheets_admin() is
|
||||
'Capability holders, live aal2 session: every official sheet that is not deleted, with its historical and working-copy badges, version and round states (V1-2 contract §11.1, M7).';
|
||||
comment on function public.get_official_sheet_admin(uuid) is
|
||||
'Capability holders, live aal2 session: one official sheet''s summary, versions (authors named) and rounds (actors named); unknown and forbidden ids answer not_found (V1-2 contract §11.1, M7).';
|
||||
|
||||
-- ===========================================================================
|
||||
-- 3. Privileges
|
||||
-- 4. Privileges
|
||||
-- ===========================================================================
|
||||
revoke all on function private.sheet_admin_person(uuid) from public, anon, authenticated, service_role;
|
||||
revoke all on function private.official_sheet_admin_summary(uuid) from public, anon, authenticated, service_role;
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in new issue
Block a user