Erlaube berechtigten Konten, verknüpfte Originale über die Zugänge des Owners zu lesen.
Deploy Development / deploy (push) Successful in 26s
Test Suite / pytest-backend (push) Successful in 1m51s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 9s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-18 21:47:30 +02:00
1 parent 562c0848b1
commit 75a3949f7c
14 files changed
+815 -93

No files matched your search

+62 -2
View File
@@ -11,6 +11,8 @@ from dataclasses import dataclass
from typing import Any
from uuid import UUID
from psycopg.types.json import Json
from app.core.errors import conflict, forbidden, not_found, unprocessable
SHARED_NOTICE = "Diese Änderung betrifft den gemeinsamen Inhalt der Notiz."
@@ -87,14 +89,17 @@ def audit(
resource_id: UUID,
context: Ctx | None = None,
occurred_on=None,
*,
result: str = "ok",
detail: dict | None = None,
) -> None:
conn.execute(
"""
INSERT INTO domain_events (
actor_subject_id, scope_id, action, resource_kind, resource_id,
context_kind, context_id, occurred_on
context_kind, context_id, occurred_on, result, detail
)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
""",
(
actor_id,
@@ -105,6 +110,8 @@ def audit(
context.kind if context else None,
context.id if context else None,
occurred_on,
result,
Json(detail) if detail is not None else None,
),
)
@@ -348,6 +355,59 @@ def _child_of(conn, matter_id: UUID, parent_id: UUID) -> bool:
return bool(matter and matter["parent_matter_id"] == parent_id)
def _rights_bearing_case(conn, case: dict) -> dict:
seen: set[UUID] = set()
current = case
while current["parent_case_id"] is not None and current["rights_mode"] == "inherit_parent":
if current["id"] in seen:
break
seen.add(current["id"])
parent = get_case(conn, current["parent_case_id"])
if parent is None:
break
current = parent
return current
def _source_grant(conn, actor: UUID, kind: str, resource_id: UUID) -> dict | None:
return conn.execute(
"""
SELECT can_read, use_owner_sources
FROM access_grants
WHERE NOT is_exception
AND grantee_subject_id = %s
AND resource_kind = %s
AND resource_id = %s
AND context_kind IS NULL
""",
(actor, kind, resource_id),
).fetchone()
def mediated_source_owner(conn, actor: UUID, element: dict, context: Ctx | None) -> UUID | None:
"""Owner whose stored connector may serve this reader. None unless the grant allows it."""
if context is None or not element_rights(conn, actor, element, context).read:
return None
if context.kind == "case":
resource = get_case(conn, context.id)
if resource is None:
return None
resource = _rights_bearing_case(conn, resource)
grant = _source_grant(conn, actor, "case", resource["id"])
elif context.kind == "matter":
resource = get_matter(conn, context.id)
if resource is None:
return None
grant = _source_grant(conn, actor, "matter", resource["id"])
else:
return None
if resource["owner_subject_id"] == actor:
return None
if grant is None or not grant["can_read"] or not grant["use_owner_sources"]:
return None
return resource["owner_subject_id"]
def element_rights_via_case_or_direct(conn, actor: UUID, element: dict, context: Ctx | None) -> Rights:
"""Rights for an element bound to a matter when the caller names a case path.