fix: align web reports with current rules
This commit is contained in:
1 parent
cffaaac755
commit
aecbb3bf6a
10 files changed
+47
-12
No files matched your search
@@ -235,6 +235,7 @@ def calculate_payload(payload: dict[str, Any]) -> dict[str, Any]:
|
||||
escort_id=_int(payload, "escort_id"),
|
||||
kitten_name=str(_required(payload, "kitten_name")),
|
||||
kitten_id=_int(payload, "kitten_id"),
|
||||
date=str(payload.get("date", "")),
|
||||
)
|
||||
result = calculate_training(session)
|
||||
return {"mode": mode, "result": asdict(result), "message": render_training(session, result)}
|
||||
|
||||
@@ -230,6 +230,7 @@ class TrainingSession:
|
||||
escort_id: int
|
||||
kitten_name: str
|
||||
kitten_id: int
|
||||
date: str = ""
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
"""Валидирует данные сессии тренировки."""
|
||||
@@ -238,6 +239,8 @@ class TrainingSession:
|
||||
raise ValueError("Имена участников не могут быть пустыми")
|
||||
_positive_id(self.escort_id, "ID сопровождающего")
|
||||
_positive_id(self.kitten_id, "ID котёнка")
|
||||
if self.date:
|
||||
parse_report_date(self.date)
|
||||
if self.escort_id == self.kitten_id:
|
||||
raise ValueError("Сопровождающий и котёнок должны быть разными персонажами")
|
||||
|
||||
|
||||
@@ -108,11 +108,11 @@ def render_training(session: TrainingSession, result: TrainingResult | None = No
|
||||
Имя [ID], провёл(-ла) урок Котёнок [ID].
|
||||
"""
|
||||
result = result or TrainingResult()
|
||||
return (
|
||||
"#урок\n"
|
||||
f"{session.escort_name} [{session.escort_id}], провёл(-ла) урок "
|
||||
f"{session.kitten_name} [{session.kitten_id}]."
|
||||
)
|
||||
lines = ["#урок"]
|
||||
if session.date:
|
||||
lines.append(session.date)
|
||||
lines.append(f"{session.escort_name} [{session.escort_id}], провёл(-ла) урок {session.kitten_name} [{session.kitten_id}].")
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def render_inspection(report: InspectionReport, result: InspectionResult | None = None) -> str:
|
||||
|
||||
+12
-2
@@ -102,6 +102,16 @@ def validate_web_attachments(value: object, *, now: float | None = None) -> list
|
||||
return attachments
|
||||
|
||||
|
||||
def validate_web_report_attachments(payload: dict) -> list[dict]:
|
||||
"""Apply the web rule: screenshots are required only for an inspection."""
|
||||
attachments = validate_web_attachments(payload.get("attachments", []))
|
||||
if payload.get("mode") == "inspection" and not attachments:
|
||||
raise ApiError("Для осмотра приложите хотя бы один скриншот")
|
||||
if payload.get("mode") != "inspection" and attachments:
|
||||
raise ApiError("Скриншоты прикладываются только к осмотрам")
|
||||
return attachments
|
||||
|
||||
|
||||
def allow_admin_auth_attempt(client_ip: str, *, now: float | None = None) -> bool:
|
||||
"""Apply a bounded per-source budget to the password-only admin login."""
|
||||
timestamp = time.monotonic() if now is None else now
|
||||
@@ -531,13 +541,13 @@ class Handler(BaseHTTPRequestHandler):
|
||||
elif self.path == "/api/resolve-identity":
|
||||
self._json(200, resolve_identity_payload(payload))
|
||||
elif self.path == "/api/applications":
|
||||
payload["attachments"] = validate_web_attachments(payload.get("attachments", []))
|
||||
payload["attachments"] = validate_web_report_attachments(payload)
|
||||
application = validate_application(payload)
|
||||
application_id = application_store().create(application=application, actor_id=None, reply_peer_id=None, source="web")
|
||||
sync_application_exports()
|
||||
self._json(201, {"id": application_id, "status": "pending", "message": "Заявка отправлена на рассмотрение."})
|
||||
elif self.path == "/api/calculate":
|
||||
payload["attachments"] = validate_web_attachments(payload.get("attachments", []))
|
||||
payload["attachments"] = validate_web_report_attachments(payload)
|
||||
self._json(200, calculate_payload(payload))
|
||||
else:
|
||||
payload["attachments"] = validate_web_attachments(payload.get("attachments", []))
|
||||
|
||||
Reference in new issue
Block a user