feat(records): enforce purpose-bound restricted access
Module Package Release / publish-packages (push) Successful in 13s

This commit is contained in:
2026-08-24 19:07:04 +02:00
parent ecfcdd1fea
commit a2dd280c47
24 changed files with 2058 additions and 123 deletions
+39
View File
@@ -19,6 +19,7 @@ from govoplan_core.privacy.dsar_workflow import (
search_data_subject_request,
)
from govoplan_records.backend.db.models import (
RecordAccessGrantRevision,
RecordChronologyEntry,
RecordClassRevision,
RecordDispositionRevision,
@@ -478,6 +479,44 @@ class RecordsDsarProviderTests(unittest.TestCase):
self.assertNotIn("private-", exported)
self.assertIn("changed_file_plan", exported)
def test_account_search_exports_only_the_subjects_restricted_grant(self) -> None:
self.session.add(
RecordAccessGrantRevision(
id="grant-row-subject-1",
tenant_id="tenant-1",
grant_id="grant-subject-1",
record_id="record-1",
revision=1,
status="active",
subject_type="account",
subject_id="account-grantee-1",
actions=["read"],
allowed_purposes=["case-work"],
reason="Sensitive internal assignment reason",
valid_from=NOW,
recorded_at=NOW,
changed_by="records-admin-1",
institutional_context={"case_id": "case-1"},
idempotency_key="grant-subject-create-1",
request_sha256="a" * 64,
)
)
self.session.commit()
records = self.provider.search_subject(
self.session,
tenant_id="tenant-1",
subject=DsarSubjectRef(account_id="account-grantee-1"),
)
grants = [
record
for record in records
if record.resource_type == "record_access_grant_revision"
]
self.assertEqual(1, len(grants))
self.assertEqual(["case-work"], grants[0].data["allowed_purposes"])
self.assertNotIn("reason", grants[0].data)
self.assertNotIn("account-grantee-1", json.dumps(grants[0].data))
def test_direct_selectors_fail_closed_on_conflict_or_wrong_tenant(self) -> None:
conflict = self.provider.search_subject(
self.session,