feat: Authorize attachment reads and message links (U4)
This commit is contained in:
+14
-7
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user