Zeige im Breadcrumb die Aktenstruktur und lass Kapitel samt Inhalt an ihren Ort ziehen.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
cafa4e8b92
commit
7ef73ad500
12 files changed
+627
-93
No files matched your search
+81
-7
@@ -121,7 +121,16 @@ def patch_case(conn, actor: UUID, case_id: UUID, expected: int, title: str | Non
|
||||
return updated
|
||||
|
||||
|
||||
def create_chapter(conn, actor: UUID, kind: str, container_id: UUID, title: str, position: int | None, context: Ctx | None) -> dict:
|
||||
def create_chapter(
|
||||
conn,
|
||||
actor: UUID,
|
||||
kind: str,
|
||||
container_id: UUID,
|
||||
title: str,
|
||||
position: int | None,
|
||||
context: Ctx | None,
|
||||
document_on: date | None = None,
|
||||
) -> dict:
|
||||
if kind == "case":
|
||||
container, _rights = require_case(conn, actor, container_id, "edit")
|
||||
else:
|
||||
@@ -136,23 +145,88 @@ def create_chapter(conn, actor: UUID, kind: str, container_id: UUID, title: str,
|
||||
if kind == "case":
|
||||
row = conn.execute(
|
||||
"""
|
||||
INSERT INTO chapters (home_scope_id, case_id, title, position)
|
||||
VALUES (%s, %s, %s, %s) RETURNING *
|
||||
INSERT INTO chapters (home_scope_id, case_id, title, position, document_on)
|
||||
VALUES (%s, %s, %s, %s, %s) RETURNING *
|
||||
""",
|
||||
(container["home_scope_id"], container_id, title.strip(), position),
|
||||
(container["home_scope_id"], container_id, title.strip(), position, document_on),
|
||||
).fetchone()
|
||||
else:
|
||||
row = conn.execute(
|
||||
"""
|
||||
INSERT INTO chapters (home_scope_id, matter_id, title, position)
|
||||
VALUES (%s, %s, %s, %s) RETURNING *
|
||||
INSERT INTO chapters (home_scope_id, matter_id, title, position, document_on)
|
||||
VALUES (%s, %s, %s, %s, %s) RETURNING *
|
||||
""",
|
||||
(container["home_scope_id"], container_id, title.strip(), position),
|
||||
(container["home_scope_id"], container_id, title.strip(), position, document_on),
|
||||
).fetchone()
|
||||
audit(conn, actor, container["home_scope_id"], "chapter_created", kind, container_id, context)
|
||||
return row
|
||||
|
||||
|
||||
def reorder_chapters(
|
||||
conn,
|
||||
actor: UUID,
|
||||
kind: str,
|
||||
container_id: UUID,
|
||||
expected: int,
|
||||
chapter_ids: list[UUID],
|
||||
context: Ctx | None,
|
||||
) -> int:
|
||||
if kind == "case":
|
||||
container, rights = require_case(conn, actor, container_id, "edit")
|
||||
table = "cases"
|
||||
column = "case_id"
|
||||
else:
|
||||
container, rights = require_matter(conn, actor, container_id, context, "edit")
|
||||
table = "matters"
|
||||
column = "matter_id"
|
||||
if not rights.edit:
|
||||
raise forbidden()
|
||||
version = bump_version(conn, table, container_id, expected)
|
||||
rows = conn.execute(f"SELECT id FROM chapters WHERE {column} = %s", (container_id,)).fetchall()
|
||||
existing = [row["id"] for row in rows]
|
||||
if len(chapter_ids) != len(set(chapter_ids)):
|
||||
raise unprocessable("Dasselbe Kapitel steht mehrfach in der Ordnung.")
|
||||
if any(item not in set(existing) for item in chapter_ids):
|
||||
raise not_found()
|
||||
if set(chapter_ids) != set(existing):
|
||||
raise unprocessable("Die Kapitelordnung ist unvollständig. Bitte neu laden.")
|
||||
for index, chapter_id in enumerate(chapter_ids):
|
||||
conn.execute("UPDATE chapters SET position = %s WHERE id = %s", (index, chapter_id))
|
||||
audit(conn, actor, container["home_scope_id"], "chapters_reordered", kind, container_id, context)
|
||||
return version
|
||||
|
||||
|
||||
def set_chapter_date(
|
||||
conn,
|
||||
actor: UUID,
|
||||
chapter_id: UUID,
|
||||
expected: int,
|
||||
document_on: date | None,
|
||||
context: Ctx | None,
|
||||
) -> int:
|
||||
row = conn.execute("SELECT * FROM chapters WHERE id = %s", (chapter_id,)).fetchone()
|
||||
if row is None:
|
||||
raise not_found()
|
||||
if row["case_id"] is not None:
|
||||
container, rights = require_case(conn, actor, row["case_id"], "edit")
|
||||
table = "cases"
|
||||
container_id = row["case_id"]
|
||||
kind = "case"
|
||||
page = None
|
||||
else:
|
||||
container, rights = require_matter(conn, actor, row["matter_id"], context, "edit")
|
||||
table = "matters"
|
||||
container_id = row["matter_id"]
|
||||
kind = "matter"
|
||||
page = context
|
||||
if not rights.edit:
|
||||
raise forbidden()
|
||||
version = bump_version(conn, table, container_id, expected)
|
||||
conn.execute("UPDATE chapters SET document_on = %s WHERE id = %s", (document_on, chapter_id))
|
||||
audit(conn, actor, container["home_scope_id"], "chapter_dated", kind, container_id, page)
|
||||
return version
|
||||
|
||||
|
||||
def create_matter(conn, actor: UUID, scope_id: UUID, title: str, parent_matter_id: UUID | None, context: Ctx | None) -> dict:
|
||||
title = title.strip()
|
||||
if parent_matter_id is None:
|
||||
|
||||
Reference in new issue
Block a user