Files
Jonathan Boniface d8a4b6b3c1
Some checks failed
quality-gates / verify (push) Failing after 7s
fix: files manually
2026-09-01 17:21:58 +01:00

23 lines
1.1 KiB
Python

from .models import Document
from .util import now
def publish(batch, publisher, tenant_id):
accepted=[d for d in batch if d.tenant_id==tenant_id and d.acl.tenant_id==tenant_id and not d.deleted]
publisher.upsert(accepted)
return {"published":len(accepted),"rejected":len(batch)-len(accepted),"tenant_id":tenant_id,"at":now()}
def deletion(ids,publisher,tenant_id): publisher.delete(ids,tenant_id); return {"deleted":len(ids),"tenant_id":tenant_id,"at":now()}
def audit(event,run_id,tenant_id): return {"event":event,"run_id":run_id,"tenant_id":tenant_id,"at":now()}
class GovernedPublisher:
def __init__(self, publisher, audit_log=None):
self.publisher = publisher
self.audit_log = audit_log if audit_log is not None else []
def publish(self, batch):
for doc in getattr(batch, "documents", []):
if getattr(doc, "tenant_id", None) != getattr(batch, "tenant_id", None):
raise PermissionError("Tenant isolation failure")
return publish(getattr(batch, "documents", []), self.publisher, batch.tenant_id)