Liefere Zähler, Rauminhalt und Teilen im Stapel für die neue Ablage.
Akten und Vorgänge melden Unterakten, Vorgänge und die Räume, mit denen sie geteilt sind, jeweils nur aus Lesbarem. Neue Endpunkte zeigen die Räume als Kacheln, den Inhalt eines Raums und teilen mehrere Einträge auf einmal oder gar nicht. Beim Anlegen lässt sich ein Eintrag gleich in einen Raum legen. Die lokale Suite läuft mit 148 Tests grün. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
30b6544514
commit
d39c7d7999
9 files changed
+411
-24
No files matched your search
@@ -0,0 +1,99 @@
|
||||
"""Library endpoints: rooms as tiles, what lies in a room, and sharing several entries at once."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from fastapi.responses import JSONResponse
|
||||
from psycopg import Connection
|
||||
|
||||
from app.access.roles import room_role
|
||||
from app.api.deps import Principal, get_conn, get_principal
|
||||
from app.api.schemas import BatchShareIn
|
||||
from app.core.errors import forbidden
|
||||
from app.library import case_items, matter_items, room_contents, room_effect
|
||||
from app.ops import share_with_room
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
_NO_STORE = {"Cache-Control": "no-store"}
|
||||
|
||||
|
||||
@router.get("/api/v1/rooms/overview")
|
||||
def rooms_overview(principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
|
||||
"""The team rooms of the person as tiles. Names of members are only shown to managers."""
|
||||
actor = principal.account_id
|
||||
rooms = conn.execute(
|
||||
"""
|
||||
SELECT r.id, r.name, r.owner_id, r.default_visibility, m.role,
|
||||
(SELECT count(*) FROM room_memberships x WHERE x.room_id = r.id AND x.status = 'active') AS members
|
||||
FROM room_memberships m JOIN data_rooms r ON r.id = m.room_id
|
||||
WHERE m.subject_id = %s AND m.status = 'active' AND r.kind = 'organization' AND r.status = 'active'
|
||||
ORDER BY r.name, r.id
|
||||
""",
|
||||
(actor,),
|
||||
).fetchall()
|
||||
items = []
|
||||
for room in rooms:
|
||||
cases, matters = room_contents(conn, actor, room["id"])
|
||||
people = []
|
||||
if room["role"] == "manager":
|
||||
people = [
|
||||
row["display_name"]
|
||||
for row in conn.execute(
|
||||
"""
|
||||
SELECT a.display_name FROM room_memberships x JOIN auth_accounts a ON a.id = x.subject_id
|
||||
WHERE x.room_id = %s AND x.status = 'active'
|
||||
ORDER BY a.display_name, a.id LIMIT 6
|
||||
""",
|
||||
(room["id"],),
|
||||
).fetchall()
|
||||
]
|
||||
items.append(
|
||||
{
|
||||
"id": str(room["id"]),
|
||||
"name": room["name"],
|
||||
"role": room["role"],
|
||||
"is_owner": room["owner_id"] == actor,
|
||||
"private": room["members"] <= 1,
|
||||
"default_visibility": room["default_visibility"],
|
||||
"member_count": room["members"],
|
||||
"members": people,
|
||||
"case_count": sum(1 for case, _ in cases if not case["parent_case_id"]),
|
||||
"matter_count": sum(1 for matter, _ in matters if not matter["parent_matter_id"]),
|
||||
}
|
||||
)
|
||||
return JSONResponse({"items": items}, headers=_NO_STORE)
|
||||
|
||||
|
||||
@router.get("/api/v1/rooms/{room_id}/contents")
|
||||
def contents(room_id: UUID, principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
|
||||
"""Cases and matters shared with the room that the person may read."""
|
||||
if room_role(conn, principal.account_id, room_id) is None:
|
||||
raise forbidden()
|
||||
cases, matters = room_contents(conn, principal.account_id, room_id)
|
||||
return JSONResponse(
|
||||
{
|
||||
"cases": case_items(conn, principal.account_id, cases),
|
||||
"matters": matter_items(conn, principal.account_id, matters),
|
||||
},
|
||||
headers=_NO_STORE,
|
||||
)
|
||||
|
||||
|
||||
@router.post("/api/v1/rooms/{room_id}/shares")
|
||||
def share_many(
|
||||
room_id: UUID,
|
||||
body: BatchShareIn,
|
||||
principal: Principal = Depends(get_principal),
|
||||
conn: Connection = Depends(get_conn),
|
||||
):
|
||||
"""Share several own entries with the room. All or none: one failure rolls the request back."""
|
||||
for item in body.items:
|
||||
share_with_room(conn, principal.account_id, item.kind, item.id, room_id, body.access)
|
||||
return {
|
||||
"shared": len(body.items),
|
||||
"access": body.access,
|
||||
"effect": room_effect(conn, room_id, principal.account_id, body.access),
|
||||
}
|
||||
@@ -12,6 +12,7 @@ from psycopg import Connection
|
||||
from app.access.policy import ROOM_RIGHTS, Rights
|
||||
from app.api.deps import Principal, get_conn, get_principal
|
||||
from app.api.schemas import ExclusionIn, RoomShareIn
|
||||
from app.library import room_effect
|
||||
from app.ops import _shareable, set_person_exclusion, share_with_room, unshare_from_room
|
||||
|
||||
router = APIRouter()
|
||||
@@ -108,7 +109,9 @@ def _register(kind: str, plural: str) -> None:
|
||||
principal: Principal = Depends(get_principal),
|
||||
conn: Connection = Depends(get_conn),
|
||||
):
|
||||
return share_with_room(conn, principal.account_id, kind, resource_id, room_id, body.access)
|
||||
shared = share_with_room(conn, principal.account_id, kind, resource_id, room_id, body.access)
|
||||
shared["effect"] = room_effect(conn, room_id, principal.account_id, body.access)
|
||||
return shared
|
||||
|
||||
@router.delete(base + "/rooms/{room_id}", status_code=204, name=f"delete_{kind}_room_share")
|
||||
def delete_share(
|
||||
|
||||
@@ -165,9 +165,10 @@ from app.present import (
|
||||
matter_detail,
|
||||
matter_summary,
|
||||
note_update_payload,
|
||||
shared_room_names,
|
||||
task_payload,
|
||||
)
|
||||
from app.library import case_items, matter_items
|
||||
from app.ops import share_with_room as _share_with_room
|
||||
from app.seed import demo_public
|
||||
|
||||
router = APIRouter()
|
||||
@@ -382,20 +383,7 @@ def find_principal(email: str, principal: Principal = Depends(get_principal), co
|
||||
|
||||
@router.get("/api/v1/cases")
|
||||
def cases(principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
|
||||
items = []
|
||||
for case, rights in list_cases(conn, principal.account_id):
|
||||
summary = case_summary(case, rights)
|
||||
summary["home_scope_name"] = room_name(conn, case["home_scope_id"])
|
||||
summary["kind_label"] = "Unterakte" if case["parent_case_id"] else "Akte"
|
||||
summary["parent_title"] = None
|
||||
summary["is_owner"] = case["owner_subject_id"] == principal.account_id
|
||||
summary["shared_with"] = shared_room_names(conn, "case", case["id"]) if summary["is_owner"] else []
|
||||
if case["parent_case_id"]:
|
||||
parent = get_case(conn, case["parent_case_id"])
|
||||
if parent is not None and case_rights(conn, principal.account_id, parent).read:
|
||||
summary["parent_title"] = parent["title"]
|
||||
items.append(summary)
|
||||
return {"items": items, "next_cursor": None}
|
||||
return {"items": case_items(conn, principal.account_id, list_cases(conn, principal.account_id)), "next_cursor": None}
|
||||
|
||||
|
||||
@router.post("/api/v1/cases")
|
||||
@@ -408,6 +396,8 @@ def post_case(body: CaseIn, principal: Principal = Depends(get_principal), conn:
|
||||
body.parent_case_id,
|
||||
body.rights_mode,
|
||||
)
|
||||
if body.share_with_room_id is not None:
|
||||
_share_with_room(conn, principal.account_id, "case", case["id"], body.share_with_room_id, "edit")
|
||||
rights = case_rights(conn, principal.account_id, case)
|
||||
return _created(f"/api/v1/cases/{case['id']}", case_summary(case, rights))
|
||||
|
||||
@@ -492,8 +482,7 @@ def post_case_grant(
|
||||
|
||||
@router.get("/api/v1/matters")
|
||||
def matters(principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
|
||||
items = [matter_summary(conn, principal.account_id, matter) for matter, _contexts in list_matters(conn, principal.account_id)]
|
||||
return {"items": items, "next_cursor": None}
|
||||
return {"items": matter_items(conn, principal.account_id, list_matters(conn, principal.account_id)), "next_cursor": None}
|
||||
|
||||
|
||||
@router.post("/api/v1/matters")
|
||||
@@ -506,6 +495,8 @@ def post_matter(body: MatterIn, principal: Principal = Depends(get_principal), c
|
||||
body.parent_matter_id,
|
||||
_ctx_model(body.context),
|
||||
)
|
||||
if body.share_with_room_id is not None:
|
||||
_share_with_room(conn, principal.account_id, "matter", matter["id"], body.share_with_room_id, "edit")
|
||||
return _created(f"/api/v1/matters/{matter['id']}", matter_summary(conn, principal.account_id, matter))
|
||||
|
||||
|
||||
|
||||
@@ -77,6 +77,16 @@ class VisibilityIn(APIModel):
|
||||
visibility: Literal["private", "room"]
|
||||
|
||||
|
||||
class ShareItemIn(APIModel):
|
||||
kind: Literal["case", "matter"]
|
||||
id: UUID
|
||||
|
||||
|
||||
class BatchShareIn(APIModel):
|
||||
items: list[ShareItemIn] = Field(min_length=1, max_length=200)
|
||||
access: Literal["read", "edit"] = "edit"
|
||||
|
||||
|
||||
class RoomShareIn(APIModel):
|
||||
access: Literal["read", "edit"] = "edit"
|
||||
|
||||
@@ -122,6 +132,7 @@ class CaseIn(APIModel):
|
||||
parent_case_id: UUID | None = None
|
||||
rights_mode: Literal["inherit_parent", "explicit"] = "inherit_parent"
|
||||
home_scope_id: UUID | None = None
|
||||
share_with_room_id: UUID | None = None
|
||||
|
||||
|
||||
class CasePatch(APIModel):
|
||||
@@ -197,6 +208,7 @@ class MatterIn(APIModel):
|
||||
parent_matter_id: UUID | None = None
|
||||
context: ContextIn | None = None
|
||||
home_scope_id: UUID | None = None
|
||||
share_with_room_id: UUID | None = None
|
||||
|
||||
|
||||
class MatterPatch(APIModel):
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
"""Overviews for the library: cases and matters as tiles, and what lies in a room.
|
||||
|
||||
A room is a virtual folder. Cases and matters stay where they are; a share puts them into a room.
|
||||
Counts only include what the person may read. Hidden entries are neither named nor counted.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import Counter
|
||||
from uuid import UUID
|
||||
|
||||
from app.access.policy import (
|
||||
ROOM_RIGHTS,
|
||||
Ctx,
|
||||
Rights,
|
||||
case_rights,
|
||||
get_case,
|
||||
list_cases,
|
||||
list_matters,
|
||||
matter_rights,
|
||||
room_name,
|
||||
)
|
||||
from app.present import case_summary, matter_summary
|
||||
|
||||
|
||||
def shared_rooms(conn, kind: str, resource_id: UUID) -> list[dict]:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT r.id, r.name, s.access FROM room_shares s JOIN data_rooms r ON r.id = s.room_id
|
||||
WHERE s.resource_kind = %s AND s.resource_id = %s
|
||||
ORDER BY r.name, r.id
|
||||
""",
|
||||
(kind, resource_id),
|
||||
).fetchall()
|
||||
return [{"id": str(row["id"]), "name": row["name"], "access": row["access"]} for row in rows]
|
||||
|
||||
|
||||
def readable_matter_count(conn, actor: UUID, case: dict) -> int:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT m.* FROM matter_case_links l JOIN matters m ON m.id = l.matter_id
|
||||
WHERE l.case_id = %s AND m.deleted_at IS NULL AND m.parent_matter_id IS NULL
|
||||
""",
|
||||
(case["id"],),
|
||||
).fetchall()
|
||||
context = Ctx("case", case["id"])
|
||||
return sum(1 for matter in rows if matter_rights(conn, actor, matter, context).read)
|
||||
|
||||
|
||||
def case_items(conn, actor: UUID, visible: list[tuple[dict, Rights]]) -> list[dict]:
|
||||
children = Counter(case["parent_case_id"] for case, _ in visible if case["parent_case_id"])
|
||||
items = []
|
||||
for case, rights in visible:
|
||||
summary = case_summary(case, rights)
|
||||
owner = case["owner_subject_id"] == actor
|
||||
summary["home_scope_name"] = room_name(conn, case["home_scope_id"])
|
||||
summary["kind_label"] = "Unterakte" if case["parent_case_id"] else "Akte"
|
||||
summary["parent_title"] = None
|
||||
summary["is_owner"] = owner
|
||||
summary["shared_with"] = shared_rooms(conn, "case", case["id"]) if owner else []
|
||||
summary["child_cases"] = children.get(case["id"], 0)
|
||||
summary["matter_count"] = readable_matter_count(conn, actor, case)
|
||||
if case["parent_case_id"]:
|
||||
parent = get_case(conn, case["parent_case_id"])
|
||||
if parent is not None and case_rights(conn, actor, parent).read:
|
||||
summary["parent_title"] = parent["title"]
|
||||
items.append(summary)
|
||||
return items
|
||||
|
||||
|
||||
def matter_items(conn, actor: UUID, visible: list[tuple[dict, list[dict]]]) -> list[dict]:
|
||||
children = Counter(matter["parent_matter_id"] for matter, _ in visible if matter["parent_matter_id"])
|
||||
items = []
|
||||
for matter, _contexts in visible:
|
||||
summary = matter_summary(conn, actor, matter)
|
||||
summary["child_matters"] = children.get(matter["id"], 0)
|
||||
items.append(summary)
|
||||
return items
|
||||
|
||||
|
||||
def room_contents(conn, actor: UUID, room_id: UUID) -> tuple[list[tuple[dict, Rights]], list[tuple[dict, list[dict]]]]:
|
||||
"""Cases and matters shared with the room that the person may read, with their readable sub-entries."""
|
||||
rows = conn.execute(
|
||||
"SELECT resource_kind, resource_id FROM room_shares WHERE room_id = %s",
|
||||
(room_id,),
|
||||
).fetchall()
|
||||
case_ids = {row["resource_id"] for row in rows if row["resource_kind"] == "case"}
|
||||
matter_ids = {row["resource_id"] for row in rows if row["resource_kind"] == "matter"}
|
||||
cases = [
|
||||
(case, rights)
|
||||
for case, rights in list_cases(conn, actor)
|
||||
if case["id"] in case_ids
|
||||
or (case["rights_mode"] == "inherit_parent" and case["parent_case_id"] in case_ids)
|
||||
]
|
||||
matters = [
|
||||
(matter, contexts)
|
||||
for matter, contexts in list_matters(conn, actor)
|
||||
if matter["id"] in matter_ids or matter["parent_matter_id"] in matter_ids
|
||||
]
|
||||
return cases, matters
|
||||
|
||||
|
||||
def room_effect(conn, room_id: UUID, actor: UUID, access: str) -> list[dict]:
|
||||
"""Who gets which rights through a share with this room."""
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT m.subject_id, m.role, a.display_name
|
||||
FROM room_memberships m JOIN auth_accounts a ON a.id = m.subject_id
|
||||
WHERE m.room_id = %s AND m.status = 'active' AND a.status = 'active' AND m.subject_id <> %s
|
||||
ORDER BY a.display_name, a.id
|
||||
""",
|
||||
(room_id, actor),
|
||||
).fetchall()
|
||||
effect = []
|
||||
for row in rows:
|
||||
rights = ROOM_RIGHTS.get(row["role"], Rights())
|
||||
if access == "read":
|
||||
rights = Rights(read=rights.read)
|
||||
effect.append(
|
||||
{
|
||||
"display_name": row["display_name"],
|
||||
"role": row["role"],
|
||||
"rights": {"read": rights.read, "edit": rights.edit},
|
||||
}
|
||||
)
|
||||
return effect
|
||||
@@ -12,6 +12,7 @@ from fastapi.responses import JSONResponse
|
||||
from app.api.accounts import router as accounts_router
|
||||
from app.api.correspondence import router as correspondence_router
|
||||
from app.api.export import router as export_router
|
||||
from app.api.library import router as library_router
|
||||
from app.api.rooms import router as rooms_router
|
||||
from app.api.roomshare import router as roomshare_router
|
||||
from app.api.team import router as team_router
|
||||
@@ -121,6 +122,7 @@ def create_app() -> FastAPI:
|
||||
|
||||
app.include_router(router)
|
||||
app.include_router(accounts_router)
|
||||
app.include_router(library_router)
|
||||
app.include_router(rooms_router)
|
||||
app.include_router(roomshare_router)
|
||||
app.include_router(team_router)
|
||||
|
||||
@@ -747,23 +747,23 @@ def matter_contexts(conn, actor: UUID, matter: dict) -> list[dict]:
|
||||
return contexts
|
||||
|
||||
|
||||
def shared_room_names(conn, kind: str, resource_id: UUID) -> list[str]:
|
||||
def _shared_rooms(conn, kind: str, resource_id: UUID) -> list[dict]:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT r.name FROM room_shares s JOIN data_rooms r ON r.id = s.room_id
|
||||
SELECT r.id, r.name, s.access FROM room_shares s JOIN data_rooms r ON r.id = s.room_id
|
||||
WHERE s.resource_kind = %s AND s.resource_id = %s
|
||||
ORDER BY r.name, r.id
|
||||
""",
|
||||
(kind, resource_id),
|
||||
).fetchall()
|
||||
return [row["name"] for row in rows]
|
||||
return [{"id": str(row["id"]), "name": row["name"], "access": row["access"]} for row in rows]
|
||||
|
||||
|
||||
def matter_summary(conn, actor: UUID, matter: dict) -> dict:
|
||||
owner = matter["owner_subject_id"] == actor
|
||||
return {
|
||||
"is_owner": owner,
|
||||
"shared_with": shared_room_names(conn, "matter", matter["id"]) if owner else [],
|
||||
"shared_with": _shared_rooms(conn, "matter", matter["id"]) if owner else [],
|
||||
"id": str(matter["id"]),
|
||||
"title": matter["title"],
|
||||
"status": matter["record_status"],
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
"""Bibliothek: Zähler nur aus Lesbarem, Rauminhalt, Raumübersicht und Teilen im Stapel."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.auth.accounts import create_account
|
||||
from tests.support import PASSWORD, Actor, matter_of
|
||||
|
||||
|
||||
def _second_client():
|
||||
from app.main import app
|
||||
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
def _actor(client, db, key: str, *, main: bool = False) -> Actor:
|
||||
actor = Actor(client if main else _second_client(), f"{key}-bib@example.test", key.title())
|
||||
create_account(db, actor.email, actor.name, PASSWORD)
|
||||
db.commit()
|
||||
actor.login()
|
||||
return actor
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def world(client, db):
|
||||
ada = _actor(client, db, "ada", main=True)
|
||||
ben = _actor(client, db, "ben")
|
||||
cem = _actor(client, db, "cem")
|
||||
dan = _actor(client, db, "dan")
|
||||
room = ada.request("POST", "/api/v1/rooms", json={"name": "Werkstatt", "default_visibility": "private"}, status=201)["id"]
|
||||
ada.request("POST", f"/api/v1/rooms/{room}/members", json={"email": ben.email, "role": "member"})
|
||||
ada.request("POST", f"/api/v1/rooms/{room}/members", json={"email": cem.email, "role": "reader"})
|
||||
return {"ada": ada, "ben": ben, "cem": cem, "dan": dan, "room": room}
|
||||
|
||||
|
||||
def _share(actor, plural, resource_id, room, status=200):
|
||||
return actor.request("PUT", f"/api/v1/{plural}/{resource_id}/room-share/rooms/{room}", json={"access": "edit"}, status=status)
|
||||
|
||||
|
||||
def _link(actor, matter, case):
|
||||
actor.request("POST", f"/api/v1/matters/{matter}/case-links", json={"case_id": case}, status=201)
|
||||
|
||||
|
||||
def test_counts_include_only_what_the_person_may_read(world):
|
||||
ada, ben, room = world["ada"], world["ben"], world["room"]
|
||||
case = ada.request("POST", "/api/v1/cases", json={"title": "Vermietung"}, status=201)
|
||||
child = ada.request(
|
||||
"POST", "/api/v1/cases",
|
||||
json={"title": "Nebenkosten", "parent_case_id": case["id"], "rights_mode": "inherit_parent"}, status=201,
|
||||
)
|
||||
one = matter_of(ada, "Mietminderung")
|
||||
two = matter_of(ada, "Eigenbedarf intern")
|
||||
_link(ada, one["id"], case["id"])
|
||||
_link(ada, two["id"], case["id"])
|
||||
_share(ada, "cases", case["id"], room)
|
||||
|
||||
mine = next(i for i in ada.request("GET", "/api/v1/cases")["items"] if i["id"] == case["id"])
|
||||
assert (mine["child_cases"], mine["matter_count"]) == (1, 2)
|
||||
assert [s["name"] for s in mine["shared_with"]] == ["Werkstatt"]
|
||||
|
||||
# One matter is withheld from the room members in this case.
|
||||
ada.request(
|
||||
"PUT", "/api/v1/exceptions",
|
||||
json={"resource_kind": "matter", "resource_id": two["id"], "context": {"kind": "case", "id": case["id"]}, "remove_read": True},
|
||||
)
|
||||
seen = next(i for i in ben.request("GET", "/api/v1/cases")["items"] if i["id"] == case["id"])
|
||||
assert seen["matter_count"] == 1 and seen["shared_with"] == [] and seen["is_owner"] is False
|
||||
assert child["title"] == "Nebenkosten"
|
||||
|
||||
|
||||
def test_a_room_shows_its_contents_to_members_only(world):
|
||||
ada, ben, cem, dan, room = world["ada"], world["ben"], world["cem"], world["dan"], world["room"]
|
||||
case = ada.request("POST", "/api/v1/cases", json={"title": "Im Raum"}, status=201)
|
||||
sub = ada.request(
|
||||
"POST", "/api/v1/cases",
|
||||
json={"title": "Unter der Akte", "parent_case_id": case["id"], "rights_mode": "inherit_parent"}, status=201,
|
||||
)
|
||||
ada.request("POST", "/api/v1/cases", json={"title": "Bleibt privat"}, status=201)
|
||||
matter = matter_of(ada, "Vorgang im Raum")
|
||||
_share(ada, "cases", case["id"], room)
|
||||
_share(ada, "matters", matter["id"], room)
|
||||
|
||||
for member in (ada, ben, cem):
|
||||
found = member.request("GET", f"/api/v1/rooms/{room}/contents")
|
||||
assert {c["title"] for c in found["cases"]} == {"Im Raum", "Unter der Akte"}
|
||||
assert [m["title"] for m in found["matters"]] == ["Vorgang im Raum"]
|
||||
dan.request("GET", f"/api/v1/rooms/{room}/contents", status=403)
|
||||
# A person who is excluded does not see the entry in the room either.
|
||||
ada.request("PUT", f"/api/v1/cases/{case['id']}/room-share/people/{_id(ada, ben)}", json={"excluded": True})
|
||||
titles = {c["title"] for c in ben.request("GET", f"/api/v1/rooms/{room}/contents")["cases"]}
|
||||
assert "Im Raum" not in titles
|
||||
assert sub["title"] == "Unter der Akte"
|
||||
|
||||
|
||||
def test_the_room_overview_names_members_only_to_managers(world):
|
||||
ada, ben, room = world["ada"], world["ben"], world["room"]
|
||||
case = ada.request("POST", "/api/v1/cases", json={"title": "Gezählt"}, status=201)
|
||||
_share(ada, "cases", case["id"], room)
|
||||
mine = next(r for r in ada.request("GET", "/api/v1/rooms/overview")["items"] if r["id"] == room)
|
||||
assert mine["is_owner"] is True and mine["role"] == "manager" and mine["member_count"] == 3
|
||||
assert mine["case_count"] == 1 and mine["matter_count"] == 0
|
||||
assert set(mine["members"]) == {"Ada", "Ben", "Cem"}
|
||||
theirs = next(r for r in ben.request("GET", "/api/v1/rooms/overview")["items"] if r["id"] == room)
|
||||
assert theirs["members"] == [] and theirs["member_count"] == 3 and theirs["is_owner"] is False
|
||||
assert world["dan"].request("GET", "/api/v1/rooms/overview")["items"] == []
|
||||
|
||||
|
||||
def test_several_entries_are_shared_at_once_or_not_at_all(world):
|
||||
ada, ben, room = world["ada"], world["ben"], world["room"]
|
||||
a = ada.request("POST", "/api/v1/cases", json={"title": "Eins"}, status=201)
|
||||
b = ada.request("POST", "/api/v1/cases", json={"title": "Zwei"}, status=201)
|
||||
m = matter_of(ada, "Drei")
|
||||
done = ada.request(
|
||||
"POST", f"/api/v1/rooms/{room}/shares",
|
||||
json={"items": [{"kind": "case", "id": a["id"]}, {"kind": "case", "id": b["id"]}, {"kind": "matter", "id": m["id"]}], "access": "read"},
|
||||
)
|
||||
assert done["shared"] == 3
|
||||
assert {(e["display_name"], e["role"], e["rights"]["edit"]) for e in done["effect"]} == {("Ben", "member", False), ("Cem", "reader", False)}
|
||||
assert ben.request("GET", f"/api/v1/cases/{a['id']}")["rights"]["edit"] is False
|
||||
|
||||
foreign = ben.request("POST", "/api/v1/cases", json={"title": "Von Ben"}, status=201)
|
||||
c = ada.request("POST", "/api/v1/cases", json={"title": "Vier"}, status=201)
|
||||
ada.request(
|
||||
"POST", f"/api/v1/rooms/{room}/shares",
|
||||
json={"items": [{"kind": "case", "id": c["id"]}, {"kind": "case", "id": foreign["id"]}]}, status=404,
|
||||
)
|
||||
assert room not in [s["room_id"] for s in ada.request("GET", f"/api/v1/cases/{c['id']}/room-share")["shares"]]
|
||||
# An outsider cannot put his own entry into the room, and nobody shares an entry of someone else.
|
||||
own = world["dan"].request("POST", "/api/v1/cases", json={"title": "Von Dan"}, status=201)
|
||||
world["dan"].request("POST", f"/api/v1/rooms/{room}/shares", json={"items": [{"kind": "case", "id": own["id"]}]}, status=403)
|
||||
world["cem"].request("POST", f"/api/v1/rooms/{room}/shares", json={"items": [{"kind": "case", "id": c["id"]}]}, status=404)
|
||||
|
||||
|
||||
def test_creating_an_entry_can_put_it_into_a_room_and_reports_the_effect(world):
|
||||
ada, ben, room = world["ada"], world["ben"], world["room"]
|
||||
case = ada.request("POST", "/api/v1/cases", json={"title": "Gleich im Raum", "share_with_room_id": room}, status=201)
|
||||
matter = ada.request("POST", "/api/v1/matters", json={"title": "Vorgang im Raum", "share_with_room_id": room}, status=201)
|
||||
ben.request("GET", f"/api/v1/cases/{case['id']}")
|
||||
ben.request("GET", f"/api/v1/matters/{matter['id']}")
|
||||
other = ada.request("POST", "/api/v1/cases", json={"title": "Ohne Raum"}, status=201)
|
||||
ben.request("GET", f"/api/v1/cases/{other['id']}", status=404)
|
||||
answer = _share(ada, "cases", other["id"], room)
|
||||
assert {e["display_name"] for e in answer["effect"]} == {"Ben", "Cem"}
|
||||
world["dan"].request("POST", "/api/v1/cases", json={"title": "Fremd", "share_with_room_id": room}, status=403)
|
||||
|
||||
|
||||
def _id(owner: Actor, person: Actor) -> str:
|
||||
from app.core.settings import get_settings
|
||||
import psycopg
|
||||
|
||||
with psycopg.connect(get_settings().dsn(), row_factory=psycopg.rows.dict_row) as conn:
|
||||
return str(conn.execute("SELECT id FROM auth_accounts WHERE email = %s", (person.email,)).fetchone()["id"])
|
||||
@@ -318,12 +318,12 @@ def test_lists_tell_the_owner_what_is_shared_and_rooms_are_managed_from_any_room
|
||||
ada, ben, room = world["ada"], world["ben"], world["room"]
|
||||
case = ada.request("POST", "/api/v1/cases", json={"title": "Liste"}, status=201)
|
||||
item = next(i for i in ada.request("GET", "/api/v1/cases")["items"] if i["id"] == case["id"])
|
||||
assert item["is_owner"] is True and item["shared_with"] == ["Werkstatt"]
|
||||
assert item["is_owner"] is True and [s["name"] for s in item["shared_with"]] == ["Werkstatt"]
|
||||
seen = next(i for i in ben.request("GET", "/api/v1/cases")["items"] if i["id"] == case["id"])
|
||||
assert seen["is_owner"] is False and seen["shared_with"] == []
|
||||
matter = matter_of(ada, "Listenvorgang")
|
||||
row = next(i for i in ada.request("GET", "/api/v1/matters")["items"] if i["id"] == matter["id"])
|
||||
assert row["is_owner"] is True and row["shared_with"] == ["Werkstatt"]
|
||||
assert row["is_owner"] is True and [s["name"] for s in row["shared_with"]] == ["Werkstatt"]
|
||||
|
||||
# The owner manages the team while working in the personal room, without switching.
|
||||
personal = Actor(ada.client, ada.email, ada.name)
|
||||
|
||||
Reference in new issue
Block a user