Implement recursive CTE in compute_visible_party_ids

Table of Contents

This page is a capture in the discarded bucket of the product backlog.

Resolved (deep backlog refinement, 2026-07-11): projects/ores.sql/create/refdata/refdata_party_functions_create.sql lines 100-120 define ores_refdata_visible_party_ids_fn with a `WITH RECURSIVE party_tree AS (…)` CTE joining on parent_party_id, returning array_agg(id) of the party and all descendants – exactly the fix requested, no longer a stub returning only {party_id}.

What

(One paragraph: the idea.)

Why

(Motivation, problem being solved, related context.)

References

See also

The current implementation of compute_visible_party_ids (used by PostgreSQL RLS to decide which party rows a session may see) returns only {party_id} with no descendants:

-- stub: just {party_id}
RETURN QUERY SELECT party_id;

Replace with a recursive CTE over ores_refdata_parties_tbl.parent_party_id so the visible set includes the logged-in party and all its descendants. This is the mechanism for HBAC (hierarchy-based access control) on books, portfolios, and other party-scoped entities.

Emacs 29.3 (Org mode 9.6.15)