security: bound Campaign editor metadata
This commit is contained in:
@@ -3,9 +3,13 @@ from __future__ import annotations
|
||||
from datetime import datetime
|
||||
from typing import Any, Literal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
||||
from pydantic import BaseModel, ConfigDict, Field, ValidationInfo, field_validator, model_validator
|
||||
|
||||
from govoplan_core.api.v1.schemas import DeltaDeletedItem
|
||||
from govoplan_campaign.backend.campaign.mail_profile_boundary import (
|
||||
public_campaign_editor_state,
|
||||
validate_campaign_editor_state,
|
||||
)
|
||||
from govoplan_campaign.backend.response_security import (
|
||||
public_campaign_configuration,
|
||||
public_campaign_payload,
|
||||
@@ -55,6 +59,11 @@ class CampaignVersionUpdateRequest(BaseModel):
|
||||
source_base_path: str | None = None
|
||||
migrate_legacy_mail_settings: bool = False
|
||||
|
||||
@field_validator("editor_state")
|
||||
@classmethod
|
||||
def validate_editor_state(cls, value: dict[str, Any] | None) -> dict[str, Any] | None:
|
||||
return validate_campaign_editor_state(value) if value is not None else None
|
||||
|
||||
|
||||
class CampaignVersionSetStepRequest(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
@@ -104,6 +113,14 @@ class CampaignVersionResponse(BaseModel):
|
||||
execution_snapshot_hash: str | None = None
|
||||
execution_snapshot_at: datetime | None = None
|
||||
|
||||
@field_validator("editor_state", mode="before")
|
||||
@classmethod
|
||||
def remove_unsupported_editor_state(cls, value: Any, info: ValidationInfo) -> dict[str, Any]:
|
||||
return public_campaign_editor_state(
|
||||
value,
|
||||
include_diagnostics=bool((info.context or {}).get("include_diagnostics")),
|
||||
)
|
||||
|
||||
@field_validator("source_filename", mode="before")
|
||||
@classmethod
|
||||
def remove_source_directory(cls, value: Any) -> str | None:
|
||||
|
||||
Reference in New Issue
Block a user