Steuere das Herunterladen von Originalen je Rolle, benenne Dateien richtig und zeige HTML-Mails gesichert im Sandbox-Rahmen.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0a5daf6713
commit
075525ee17
26 files changed
+494
-71
No files matched your search
@@ -24,16 +24,18 @@ class Rights:
|
||||
edit: bool = False
|
||||
share: bool = False
|
||||
delete: bool = False
|
||||
# Saving or opening the original outside of Tsumugu. Reading in the app does not need it.
|
||||
download: bool = False
|
||||
|
||||
@classmethod
|
||||
def full(cls) -> Rights:
|
||||
return cls(True, True, True, True)
|
||||
return cls(True, True, True, True, True)
|
||||
|
||||
@classmethod
|
||||
def from_row(cls, row: dict | None) -> Rights:
|
||||
def from_row(cls, row: dict | None, download: bool = False) -> Rights:
|
||||
if row is None:
|
||||
return cls()
|
||||
return cls(bool(row["can_read"]), bool(row["can_edit"]), bool(row["can_share"]), bool(row["can_delete"]))
|
||||
return cls(bool(row["can_read"]), bool(row["can_edit"]), bool(row["can_share"]), bool(row["can_delete"]), download and bool(row["can_read"]))
|
||||
|
||||
def union(self, other: Rights) -> Rights:
|
||||
return Rights(
|
||||
@@ -41,21 +43,24 @@ class Rights:
|
||||
self.edit or other.edit,
|
||||
self.share or other.share,
|
||||
self.delete or other.delete,
|
||||
self.download or other.download,
|
||||
)
|
||||
|
||||
def without(self, blocked: Rights) -> Rights:
|
||||
# An exception that takes away reading takes away downloading too.
|
||||
return Rights(
|
||||
self.read and not blocked.read,
|
||||
self.edit and not blocked.edit,
|
||||
self.share and not blocked.share,
|
||||
self.delete and not blocked.delete,
|
||||
self.download and not blocked.read,
|
||||
)
|
||||
|
||||
def allows(self, need: str) -> bool:
|
||||
return bool(getattr(self, need))
|
||||
|
||||
def as_dict(self) -> dict[str, bool]:
|
||||
return {"read": self.read, "edit": self.edit, "share": self.share, "delete": self.delete}
|
||||
return {"read": self.read, "edit": self.edit, "share": self.share, "delete": self.delete, "download": self.read and self.download}
|
||||
|
||||
|
||||
# The room share: what a room role may do with a case or matter that is shared with the room.
|
||||
@@ -206,7 +211,25 @@ def _direct_grant(conn, actor: UUID, kind: str, resource_id: UUID) -> Rights:
|
||||
""",
|
||||
(actor, kind, resource_id),
|
||||
).fetchone()
|
||||
return Rights.from_row(row)
|
||||
if row is None:
|
||||
return Rights()
|
||||
return Rights.from_row(row, _direct_download(conn, kind, resource_id))
|
||||
|
||||
|
||||
def _direct_download(conn, kind: str, resource_id: UUID) -> bool:
|
||||
"""Direct recipients follow the download setting `direct` of the owner of the entry."""
|
||||
table = {"case": "cases", "matter": "matters", "element": "elements"}.get(kind)
|
||||
if table is None:
|
||||
return False
|
||||
row = conn.execute(
|
||||
f"""
|
||||
SELECT a.download_defaults
|
||||
FROM {table} r JOIN auth_accounts a ON a.id = r.owner_subject_id
|
||||
WHERE r.id = %s
|
||||
""",
|
||||
(resource_id,),
|
||||
).fetchone()
|
||||
return bool(row and row["download_defaults"].get("direct", False))
|
||||
|
||||
|
||||
def _exceptions(conn, actor: UUID, kind: str, resource_id: UUID, context: Ctx | None) -> Rights:
|
||||
@@ -249,7 +272,7 @@ def room_default(conn, actor: UUID, kind: str, resource_id: UUID) -> Rights:
|
||||
"""
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT m.role, s.access
|
||||
SELECT m.role, s.access, r.download_roles
|
||||
FROM room_shares s
|
||||
JOIN room_memberships m ON m.room_id = s.room_id AND m.subject_id = %s AND m.status = 'active'
|
||||
JOIN data_rooms r ON r.id = s.room_id AND r.kind = 'organization' AND r.status = 'active'
|
||||
@@ -265,6 +288,8 @@ def room_default(conn, actor: UUID, kind: str, resource_id: UUID) -> Rights:
|
||||
rights = Rights(read=rights.read)
|
||||
elif row["access"] != "edit":
|
||||
rights = Rights()
|
||||
if rights.read and row["download_roles"].get(row["role"], False):
|
||||
rights = Rights(rights.read, rights.edit, rights.share, rights.delete, True)
|
||||
result = result.union(rights)
|
||||
return result
|
||||
|
||||
|
||||
Reference in new issue
Block a user