feat: Authorize attachment reads and message links (U4)

This commit is contained in:
Самохвалов Андрей Ремович
2026-10-02 14:00:53 +03:00
parent 412b465b85
commit 9347fe35ae
9 changed files with 282 additions and 24 deletions
+14 -7
View File
@@ -2,7 +2,7 @@
from uuid import UUID
from pydantic import BaseModel, ConfigDict, Field, field_validator
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
class StrictBody(BaseModel):
@@ -50,12 +50,19 @@ class CreateChat(StrictBody):
class CreateMessage(StrictBody):
text: str = Field(min_length=1, max_length=4000)
text: str = Field(max_length=4000)
attachment_ids: list[str] = Field(default_factory=list, max_length=10)
@field_validator("text")
@field_validator("attachment_ids")
@classmethod
def nonblank_text(cls, value: str) -> str:
if not value.strip():
raise ValueError("blank text")
return value
def valid_attachments(cls, value: list[str]) -> list[str]:
ids = [str(UUID(item)) for item in value]
if len(set(ids)) != len(ids):
raise ValueError("duplicate attachment")
return ids
@model_validator(mode="after")
def text_or_attachment(self):
if not self.text.strip() and not self.attachment_ids:
raise ValueError("message needs text or attachment")
return self