Stelle den ersten nutzbaren Ablauf zum Organisieren und Nachverfolgen bereit.
Deploy Development / deploy (push) Successful in 23s
Deploy Development / deploy (push) Successful in 23s
Anmeldung, Datenraeume, Akten, Vorgaenge, gemeinsame Notizen, Dateien, manuelle Paperless-Referenzen, Aufgaben und unabhaengige Fristen laufen damit in der Entwicklungsumgebung. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
cfe17ff909
commit
2558239bfd
60 files changed
+8467
-71
No files matched your search
@@ -0,0 +1 @@
|
||||
"""HTTP adapters. Authorization stays in the domain services."""
|
||||
@@ -0,0 +1,97 @@
|
||||
"""Request scope: one transaction, a session principal, and no client-supplied identity."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import Depends, Request
|
||||
from psycopg import Connection
|
||||
|
||||
from app.access.policy import ensure_member_or_personal
|
||||
from app.auth.security import hash_secret, read_session_token
|
||||
from app.core.errors import forbidden, unauthorized
|
||||
from app.core.timeutil import utcnow
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Principal:
|
||||
account_id: UUID
|
||||
email: str
|
||||
display_name: str
|
||||
session_id: UUID
|
||||
scope_kind: str
|
||||
scope_id: UUID
|
||||
scope_name: str
|
||||
epoch: int
|
||||
|
||||
|
||||
def get_conn(request: Request):
|
||||
pool = request.app.state.pool
|
||||
with pool.connection() as conn:
|
||||
try:
|
||||
conn.execute("SET TIME ZONE 'UTC'")
|
||||
yield conn
|
||||
conn.commit()
|
||||
for path in getattr(request.state, "delete_after_commit", []):
|
||||
Path(path).unlink(missing_ok=True)
|
||||
except Exception:
|
||||
conn.rollback()
|
||||
for path in getattr(request.state, "cleanup_files", []):
|
||||
Path(path).unlink(missing_ok=True)
|
||||
raise
|
||||
|
||||
|
||||
def _session_row(conn: Connection, request: Request) -> dict:
|
||||
token = read_session_token(request)
|
||||
if not token:
|
||||
raise unauthorized()
|
||||
row = conn.execute(
|
||||
"""
|
||||
SELECT s.id, s.account_id, s.csrf_token, s.scope_kind, s.scope_id, s.epoch,
|
||||
s.expires_at, s.revoked_at, a.email, a.display_name, a.status AS account_status
|
||||
FROM auth_sessions s
|
||||
JOIN auth_accounts a ON a.id = s.account_id
|
||||
WHERE s.secret_hash = %s
|
||||
""",
|
||||
(hash_secret(token),),
|
||||
).fetchone()
|
||||
if row is None or row["revoked_at"] is not None or row["expires_at"] <= utcnow():
|
||||
raise unauthorized()
|
||||
if row["account_status"] != "active":
|
||||
raise unauthorized()
|
||||
if request.method not in {"GET", "HEAD", "OPTIONS"}:
|
||||
sent = request.headers.get("x-csrf-token") or ""
|
||||
if not sent or sent != row["csrf_token"]:
|
||||
raise forbidden("Die Anfrage konnte der Sitzung nicht zugeordnet werden.")
|
||||
return row
|
||||
|
||||
|
||||
def get_session(request: Request, conn: Connection = Depends(get_conn)) -> dict:
|
||||
return _session_row(conn, request)
|
||||
|
||||
|
||||
def get_principal(request: Request, conn: Connection = Depends(get_conn)) -> Principal:
|
||||
row = _session_row(conn, request)
|
||||
kind = request.headers.get("x-scope-kind")
|
||||
raw_scope = request.headers.get("x-scope-id")
|
||||
if not kind or not raw_scope:
|
||||
raise forbidden("Der Datenraum ist nicht gewählt.")
|
||||
try:
|
||||
scope_id = UUID(raw_scope)
|
||||
except ValueError as exc:
|
||||
raise forbidden("Der Datenraum ist nicht gewählt.") from exc
|
||||
if kind != row["scope_kind"] or scope_id != row["scope_id"]:
|
||||
raise forbidden("Der gewählte Datenraum entspricht nicht mehr der Sitzung.")
|
||||
room = ensure_member_or_personal(conn, row["account_id"], kind, scope_id)
|
||||
return Principal(
|
||||
account_id=row["account_id"],
|
||||
email=row["email"],
|
||||
display_name=row["display_name"],
|
||||
session_id=row["id"],
|
||||
scope_kind=kind,
|
||||
scope_id=scope_id,
|
||||
scope_name=room["name"],
|
||||
epoch=row["epoch"],
|
||||
)
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,203 @@
|
||||
"""Request bodies. Unknown fields are rejected."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date
|
||||
from typing import Annotated, Literal
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
Email = Annotated[str, Field(min_length=3, max_length=320, pattern=r"^[^@\s]+@[^@\s]+\.[^@\s]+$")]
|
||||
|
||||
|
||||
class APIModel(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
|
||||
class LoginIn(APIModel):
|
||||
email: Email
|
||||
password: str = Field(min_length=1, max_length=200)
|
||||
|
||||
|
||||
class ScopeIn(APIModel):
|
||||
kind: Literal["personal", "organization"]
|
||||
id: UUID
|
||||
|
||||
|
||||
class AcceptInviteIn(APIModel):
|
||||
token: str = Field(min_length=20, max_length=200)
|
||||
display_name: str = Field(min_length=1, max_length=120)
|
||||
password: str = Field(min_length=10, max_length=200)
|
||||
|
||||
|
||||
class InvitationIn(APIModel):
|
||||
email: Email
|
||||
room_id: UUID
|
||||
|
||||
|
||||
class RoomIn(APIModel):
|
||||
name: str = Field(min_length=1, max_length=160)
|
||||
|
||||
|
||||
class MemberIn(APIModel):
|
||||
email: Email
|
||||
role: Literal["member", "manager"]
|
||||
|
||||
|
||||
class ContextIn(APIModel):
|
||||
kind: Literal["case", "matter"]
|
||||
id: UUID
|
||||
|
||||
|
||||
class CaseIn(APIModel):
|
||||
title: str = Field(min_length=1, max_length=200)
|
||||
parent_case_id: UUID | None = None
|
||||
rights_mode: Literal["inherit_parent", "explicit"] = "inherit_parent"
|
||||
|
||||
|
||||
class CasePatch(APIModel):
|
||||
expected_version: int = Field(ge=1)
|
||||
title: str | None = Field(default=None, min_length=1, max_length=200)
|
||||
status: Literal["open", "closed"] | None = None
|
||||
|
||||
|
||||
class ChapterIn(APIModel):
|
||||
title: str = Field(min_length=1, max_length=200)
|
||||
position: int | None = Field(default=None, ge=0, le=10000)
|
||||
|
||||
|
||||
class MatterIn(APIModel):
|
||||
title: str = Field(min_length=1, max_length=200)
|
||||
parent_matter_id: UUID | None = None
|
||||
context: ContextIn | None = None
|
||||
|
||||
|
||||
class MatterPatch(APIModel):
|
||||
expected_version: int = Field(ge=1)
|
||||
title: str | None = Field(default=None, min_length=1, max_length=200)
|
||||
status: Literal["open", "closed"] | None = None
|
||||
context: ContextIn | None = None
|
||||
|
||||
|
||||
class CaseLinkIn(APIModel):
|
||||
case_id: UUID
|
||||
context: ContextIn | None = None
|
||||
|
||||
|
||||
class CrossLinkIn(APIModel):
|
||||
target_matter_id: UUID
|
||||
target_context: ContextIn
|
||||
source_context: ContextIn | None = None
|
||||
|
||||
|
||||
class GrantIn(APIModel):
|
||||
email: Email
|
||||
can_read: bool = True
|
||||
can_edit: bool = False
|
||||
can_share: bool = False
|
||||
|
||||
|
||||
class ExceptionIn(APIModel):
|
||||
resource_kind: Literal["element", "matter", "task", "deadline"]
|
||||
resource_id: UUID
|
||||
context: ContextIn
|
||||
remove_read: bool = False
|
||||
remove_edit: bool = False
|
||||
remove_share: bool = False
|
||||
|
||||
|
||||
class DocumentIn(APIModel):
|
||||
version: Literal[1] = 1
|
||||
blocks: list[dict]
|
||||
|
||||
|
||||
class NoteIn(APIModel):
|
||||
title: str = Field(min_length=1, max_length=200)
|
||||
document: DocumentIn
|
||||
context: ContextIn
|
||||
placement: ContextIn | None = None
|
||||
chapter_id: UUID | None = None
|
||||
|
||||
|
||||
class NotePatch(APIModel):
|
||||
expected_version: int = Field(ge=1)
|
||||
document: DocumentIn
|
||||
context: ContextIn | None = None
|
||||
|
||||
|
||||
class BindingIn(APIModel):
|
||||
element_id: UUID
|
||||
source_context: ContextIn
|
||||
target: ContextIn
|
||||
target_context: ContextIn | None = None
|
||||
chapter_id: UUID | None = None
|
||||
|
||||
|
||||
class AnnotationIn(APIModel):
|
||||
body: str = Field(min_length=1, max_length=4000)
|
||||
|
||||
|
||||
class DatesIn(APIModel):
|
||||
document_on: date | None = None
|
||||
sent_on: date | None = None
|
||||
received_on: date | None = None
|
||||
|
||||
|
||||
class ExternalIn(APIModel):
|
||||
title: str = Field(min_length=1, max_length=200)
|
||||
source: Literal["paperless", "url"]
|
||||
external_id: str = Field(min_length=1, max_length=200)
|
||||
context: ContextIn
|
||||
placement: ContextIn | None = None
|
||||
chapter_id: UUID | None = None
|
||||
dates: DatesIn = DatesIn()
|
||||
|
||||
|
||||
class DeleteElementIn(APIModel):
|
||||
expected_version: int = Field(ge=1)
|
||||
|
||||
|
||||
class TaskIn(APIModel):
|
||||
title: str = Field(min_length=1, max_length=200)
|
||||
due_on: date | None = None
|
||||
matter_id: UUID | None = None
|
||||
context: ContextIn | None = None
|
||||
|
||||
|
||||
class TaskPatch(APIModel):
|
||||
expected_version: int = Field(ge=1)
|
||||
title: str | None = Field(default=None, min_length=1, max_length=200)
|
||||
due_on: date | None = None
|
||||
clear_due_on: bool = False
|
||||
status: Literal["open", "done"] | None = None
|
||||
context: ContextIn | None = None
|
||||
|
||||
|
||||
class AssigneeIn(APIModel):
|
||||
email: str | None = None
|
||||
context: ContextIn | None = None
|
||||
|
||||
|
||||
class DeadlineIn(APIModel):
|
||||
title: str = Field(min_length=1, max_length=200)
|
||||
due_on: date
|
||||
matter_id: UUID | None = None
|
||||
context: ContextIn | None = None
|
||||
|
||||
|
||||
class DeadlinePatch(APIModel):
|
||||
expected_version: int = Field(ge=1)
|
||||
title: str | None = Field(default=None, min_length=1, max_length=200)
|
||||
due_on: date | None = None
|
||||
context: ContextIn | None = None
|
||||
|
||||
|
||||
class FulfillIn(APIModel):
|
||||
expected_version: int = Field(ge=1)
|
||||
context: ContextIn | None = None
|
||||
|
||||
|
||||
class TaskDeadlineIn(APIModel):
|
||||
deadline_id: UUID
|
||||
context: ContextIn | None = None
|
||||
Reference in new issue
Block a user