fix: allow blocked chat import drafts while keeping execution validation strict
This commit is contained in:
@@ -6,6 +6,7 @@ from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
from fastapi import HTTPException
|
||||
from pydantic import ValidationError
|
||||
from sqlalchemy import select
|
||||
|
||||
from . import services
|
||||
@@ -149,7 +150,12 @@ def prepare(db, conversation: Conversation, kind: str, payload: dict, *, teacher
|
||||
raise HTTPException(400, "整批 Excel 导出须在未限定学生项目的会话中准备")
|
||||
if kind == "import":
|
||||
from .api import ImportConfirm
|
||||
data = ImportConfirm.model_validate(payload)
|
||||
try:
|
||||
data = ImportConfirm.model_validate(payload, context={
|
||||
"allow_unselected_import_draft": not teacher_edited})
|
||||
except ValidationError as exc:
|
||||
messages = [error["msg"] for error in exc.errors(include_input=False, include_context=False)]
|
||||
raise HTTPException(400, "导入资料尚未满足确认条件:" + ";".join(messages)) from exc
|
||||
payload = data.model_dump()
|
||||
require_scope(db, conversation, version_id=data.course_version_id)
|
||||
if teacher_edited and any(item.student_no == "00000" or item.name == "待确认" or item.topic == "待确认" for item in data.projects):
|
||||
@@ -164,9 +170,10 @@ def prepare(db, conversation: Conversation, kind: str, payload: dict, *, teacher
|
||||
scanned.append(match)
|
||||
if match["status"] != "recognized" or match["warnings"] or any(f["status"] != "recognized" for f in match["files"]):
|
||||
ambiguous.append(item.relative_dir)
|
||||
unselected = any(not any(file.status != "ignored" for file in item.files) for item in data.projects)
|
||||
preview = {"course_version_id": data.course_version_id, "projects": scanned,
|
||||
"selection": payload["projects"], "ambiguous": ambiguous,
|
||||
"requires_edit": bool(ambiguous) and not teacher_edited}
|
||||
"requires_edit": (bool(ambiguous) or unselected) and not teacher_edited}
|
||||
elif kind == "course_ingest":
|
||||
require_scope(db, conversation, version_id=payload["course_version_id"])
|
||||
preview = {"course_version_id": payload["course_version_id"], "templates":
|
||||
|
||||
Reference in New Issue
Block a user