fix: allow blocked chat import drafts while keeping execution validation strict
This commit is contained in:
@@ -3,7 +3,7 @@ from pathlib import Path
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from fastapi.responses import FileResponse
|
||||
from pydantic import BaseModel, Field, field_validator, model_validator
|
||||
from pydantic import BaseModel, Field, ValidationInfo, field_validator, model_validator
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
@@ -79,9 +79,13 @@ class ProjectConfirm(BaseModel):
|
||||
return value.strip() if isinstance(value, str) else value
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_selection(self):
|
||||
def validate_selection(self, info: ValidationInfo):
|
||||
selected = [file for file in self.files if file.status != "ignored"]
|
||||
if not selected:
|
||||
# Only the chat preview builder supplies this context. HTTP imports,
|
||||
# edited previews and final execution always use strict validation.
|
||||
if (info.context or {}).get("allow_unselected_import_draft"):
|
||||
return self
|
||||
raise ValueError("至少选择1份资料")
|
||||
categories = [file.category for file in selected]
|
||||
if any(category not in CATEGORIES for category in categories):
|
||||
|
||||
Reference in New Issue
Block a user