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;
|
||||
|
||||
Reference in new issue
Block a user