merge: 合并远程 ft_wyt 分支,解决权限与日志模块冲突
- 冲突解决原则:本地权限治理(require_admin/current_user/资源ACL)与远程 op_log 日志装饰器双向保留 - platform.py: 9 处冲突,@op_log 与管理员校验叠加,避免远程丢失 require_admin 的安全回归 - logging.py: 合并 get_client_ip 与 user_id_var,X-Trace-Id 优先 + ContextVar 卫生处理 - op_log.py: 采纳远程将变量计算上移到函数顶部的结构 - compute_poller.py: 中文日志 + 失败去重限流/断连重置逻辑 - data_process.py: 保留租户归属字段 + biz_logger 成功日志
This commit is contained in:
@@ -41,8 +41,12 @@ from app.core.auth import (
|
||||
has_resource_access,
|
||||
is_admin,
|
||||
)
|
||||
|
||||
from app.core.logging import get_structured_logger
|
||||
|
||||
from app.core.config import get_settings
|
||||
from app.db.platform_store import get_platform_store
|
||||
|
||||
from app.modules.data_process.algorithms import (
|
||||
ParsedText,
|
||||
canonical_record_json,
|
||||
@@ -117,6 +121,7 @@ from app.schemas.data_process import (
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
biz_logger = get_structured_logger("app.biz.data_process")
|
||||
MAX_SOURCE_FILE_BYTES = 200 * 1024 * 1024
|
||||
MAX_SOURCE_FILE_COUNT = 20
|
||||
MAX_SOURCE_BATCH_BYTES = 500 * 1024 * 1024
|
||||
@@ -292,7 +297,7 @@ def _commit_source_batch(
|
||||
except Exception:
|
||||
# 文件系统回滚失败不能覆盖数据库抛出的根因,并继续清理其余对象。
|
||||
logger.exception(
|
||||
"failed to roll back data process source object task_id=%s",
|
||||
"数据处理源对象回滚失败 task_id=%s",
|
||||
task_id,
|
||||
)
|
||||
raise
|
||||
@@ -662,7 +667,7 @@ def _run_generation(
|
||||
) -> None:
|
||||
started_at = time.perf_counter()
|
||||
logger.info(
|
||||
"data process generation worker started task_id=%s generation_run_id=%s",
|
||||
"数据处理生成任务开始 task_id=%s generation_run_id=%s",
|
||||
task_id,
|
||||
generation_run_id,
|
||||
)
|
||||
@@ -670,8 +675,7 @@ def _run_generation(
|
||||
task = store.get_task(task_id)
|
||||
if not store.generation_is_running(task_id, generation_run_id):
|
||||
logger.info(
|
||||
"data process generation worker skipped inactive run task_id=%s "
|
||||
"generation_run_id=%s",
|
||||
"数据处理生成任务跳过(非活跃运行) task_id=%s generation_run_id=%s",
|
||||
task_id,
|
||||
generation_run_id,
|
||||
)
|
||||
@@ -761,8 +765,7 @@ def _run_generation(
|
||||
len(preview_items),
|
||||
):
|
||||
logger.info(
|
||||
"data process generation stopped before completion task_id=%s "
|
||||
"generation_run_id=%s",
|
||||
"数据处理生成任务被中止 task_id=%s generation_run_id=%s",
|
||||
task_id,
|
||||
generation_run_id,
|
||||
)
|
||||
@@ -853,9 +856,7 @@ def _run_generation(
|
||||
"created_by": (store.get_task(task_id) or {}).get("created_by"),
|
||||
})
|
||||
logger.info(
|
||||
"data process generation completed task_id=%s generation_run_id=%s "
|
||||
"output_count=%s filtered_count=%s duplicate_count=%s error_count=%s "
|
||||
"duration_ms=%.2f",
|
||||
"数据处理生成完成 task_id=%s generation_run_id=%s output_count=%s filtered_count=%s duplicate_count=%s error_count=%s duration_ms=%.2f",
|
||||
task_id,
|
||||
generation_run_id,
|
||||
completed.get("output_count", len(accepted)),
|
||||
@@ -866,14 +867,13 @@ def _run_generation(
|
||||
)
|
||||
else:
|
||||
logger.info(
|
||||
"data process generation stopped before result persistence task_id=%s "
|
||||
"generation_run_id=%s",
|
||||
"数据处理生成任务在持久化前被停止 task_id=%s generation_run_id=%s",
|
||||
task_id,
|
||||
generation_run_id,
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.exception(
|
||||
"data process generation failed task_id=%s generation_run_id=%s duration_ms=%.2f",
|
||||
"数据处理生成失败 task_id=%s generation_run_id=%s duration_ms=%.2f",
|
||||
task_id,
|
||||
generation_run_id,
|
||||
(time.perf_counter() - started_at) * 1000,
|
||||
@@ -887,8 +887,7 @@ def _run_generation(
|
||||
)
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"failed to persist data process generation failure task_id=%s "
|
||||
"generation_run_id=%s",
|
||||
"数据处理生成失败持久化异常 task_id=%s generation_run_id=%s",
|
||||
task_id,
|
||||
generation_run_id,
|
||||
)
|
||||
@@ -943,6 +942,7 @@ def create_task(
|
||||
values["tenant_id"] = current_user.get("tenant_id") or "default"
|
||||
get_platform_store().assert_active_tenant(values["tenant_id"])
|
||||
task = store.create_task(values)
|
||||
biz_logger.info("用户创建数据处理任务成功", taskId=task["id"], processType=task.get("process_type", ""))
|
||||
return ok(task, "data process task created")
|
||||
|
||||
|
||||
@@ -968,10 +968,9 @@ def update_task(
|
||||
store: DataProcessStore = Depends(get_data_process_store),
|
||||
) -> dict[str, Any]:
|
||||
with api_errors():
|
||||
return ok(
|
||||
store.update_task(task_id, payload.model_dump(exclude_unset=True, mode="json")),
|
||||
"data process task updated",
|
||||
)
|
||||
result = store.update_task(task_id, payload.model_dump(exclude_unset=True, mode="json"))
|
||||
biz_logger.info("用户更新数据处理任务成功", taskId=task_id)
|
||||
return ok(result, "data process task updated")
|
||||
|
||||
|
||||
@router.put("/{task_id}/workflow-step")
|
||||
@@ -1060,7 +1059,7 @@ def _remove_repeated_storage_objects(
|
||||
)
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"failed to roll back repeated data process source object task_id=%s",
|
||||
"数据处理源对象重复回滚失败 task_id=%s",
|
||||
task_id,
|
||||
)
|
||||
|
||||
@@ -1136,6 +1135,7 @@ def delete_task(
|
||||
) -> dict[str, Any]:
|
||||
with api_errors():
|
||||
store.delete_task(task_id)
|
||||
biz_logger.info("用户删除数据处理任务成功", taskId=task_id)
|
||||
return ok({"deleted": task_id}, "data process task deleted")
|
||||
|
||||
|
||||
@@ -1448,13 +1448,12 @@ def delete_source_file(
|
||||
expected_source_file_id=file_id,
|
||||
)
|
||||
except Exception:
|
||||
# 数据库软删除已经提交,不能再向客户端返回可重试的失败;保留逻辑引用,
|
||||
# 由后续存储清理任务重试物理删除。
|
||||
cleanup_pending = True
|
||||
logger.exception(
|
||||
"failed to remove data process source object after soft deletion",
|
||||
"数据处理源对象软删除后存储清理失败",
|
||||
extra={"task_id": task_id, "source_file_id": file_id},
|
||||
)
|
||||
biz_logger.info("用户删除数据处理源文件成功", taskId=task_id, fileId=file_id, storageCleanupPending=cleanup_pending)
|
||||
return ok(
|
||||
{"deleted": file_id, "storage_cleanup_pending": cleanup_pending},
|
||||
"source file removed",
|
||||
@@ -1727,7 +1726,7 @@ def _prepare_preview_items(
|
||||
extracted_text = "\n\n".join(page.text for page in pages if page.text)
|
||||
if extracted_text != str(source.get("content") or ""):
|
||||
logger.warning(
|
||||
"skip PDF document noise detection because stored offsets differ for %s",
|
||||
"跳过PDF文档噪声检测(存储偏移量不一致) source_id=%s",
|
||||
source["id"],
|
||||
)
|
||||
continue
|
||||
@@ -1750,7 +1749,7 @@ def _run_preview(
|
||||
|
||||
started_at = time.perf_counter()
|
||||
logger.info(
|
||||
"data process preview started task_id=%s preview_run_id=%s total_files=%s",
|
||||
"数据处理预览开始 task_id=%s preview_run_id=%s total_files=%s",
|
||||
task_id,
|
||||
preview_run_id,
|
||||
len(source_file_ids),
|
||||
@@ -1759,7 +1758,7 @@ def _run_preview(
|
||||
is_unstructured = store.get_task(task_id).get("process_type") == "unstructured"
|
||||
if not store.mark_preview_running(task_id, preview_run_id):
|
||||
logger.info(
|
||||
"data process preview skipped inactive run task_id=%s preview_run_id=%s",
|
||||
"数据处理预览跳过(非活跃运行) task_id=%s preview_run_id=%s",
|
||||
task_id,
|
||||
preview_run_id,
|
||||
)
|
||||
@@ -1769,8 +1768,7 @@ def _run_preview(
|
||||
for completed_files, source_file_id in enumerate(source_file_ids, start=1):
|
||||
if not store.preview_is_running(task_id, preview_run_id):
|
||||
logger.info(
|
||||
"data process preview cancelled task_id=%s preview_run_id=%s "
|
||||
"completed_files=%s total_files=%s",
|
||||
"数据处理预览被取消 task_id=%s preview_run_id=%s completed_files=%s total_files=%s",
|
||||
task_id,
|
||||
preview_run_id,
|
||||
completed_files - 1,
|
||||
@@ -1801,8 +1799,7 @@ def _run_preview(
|
||||
total_files,
|
||||
):
|
||||
logger.info(
|
||||
"data process preview stopped before progress update task_id=%s "
|
||||
"preview_run_id=%s completed_files=%s total_files=%s",
|
||||
"数据处理预览在进度更新前被停止 task_id=%s preview_run_id=%s completed_files=%s total_files=%s",
|
||||
task_id,
|
||||
preview_run_id,
|
||||
completed_files,
|
||||
@@ -1811,8 +1808,7 @@ def _run_preview(
|
||||
return
|
||||
if store.complete_preview(task_id, preview_run_id):
|
||||
logger.info(
|
||||
"data process preview completed task_id=%s preview_run_id=%s "
|
||||
"total_files=%s total_items=%s duration_ms=%.2f",
|
||||
"数据处理预览完成 task_id=%s preview_run_id=%s total_files=%s total_items=%s duration_ms=%.2f",
|
||||
task_id,
|
||||
preview_run_id,
|
||||
total_files,
|
||||
@@ -1821,14 +1817,13 @@ def _run_preview(
|
||||
)
|
||||
else:
|
||||
logger.info(
|
||||
"data process preview completion ignored for inactive run task_id=%s "
|
||||
"preview_run_id=%s",
|
||||
"数据处理预览完成但运行已失效 task_id=%s preview_run_id=%s",
|
||||
task_id,
|
||||
preview_run_id,
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.exception(
|
||||
"data process preview failed task_id=%s preview_run_id=%s duration_ms=%.2f",
|
||||
"数据处理预览失败 task_id=%s preview_run_id=%s duration_ms=%.2f",
|
||||
task_id,
|
||||
preview_run_id,
|
||||
(time.perf_counter() - started_at) * 1000,
|
||||
@@ -1842,8 +1837,7 @@ def _run_preview(
|
||||
)
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"failed to persist data process preview failure task_id=%s "
|
||||
"preview_run_id=%s",
|
||||
"数据处理预览失败持久化异常 task_id=%s preview_run_id=%s",
|
||||
task_id,
|
||||
preview_run_id,
|
||||
)
|
||||
@@ -2053,6 +2047,7 @@ def stop(
|
||||
) -> dict[str, Any]:
|
||||
with api_errors():
|
||||
store.stop_task(task_id)
|
||||
biz_logger.info("用户停止数据处理任务成功", taskId=task_id)
|
||||
return ok(store.progress(task_id), "data process task stopped")
|
||||
|
||||
|
||||
@@ -2094,7 +2089,9 @@ def confirm_results(
|
||||
store: DataProcessStore = Depends(get_data_process_store),
|
||||
) -> dict[str, Any]:
|
||||
with api_errors():
|
||||
return ok(store.confirm_results(task_id), "data process results confirmed")
|
||||
result = store.confirm_results(task_id)
|
||||
biz_logger.info("用户确认数据处理结果成功", taskId=task_id)
|
||||
return ok(result, "data process results confirmed")
|
||||
|
||||
|
||||
@router.put("/{task_id}/results/{result_id}")
|
||||
@@ -2443,8 +2440,7 @@ def regenerate_results_batch(
|
||||
}))
|
||||
|
||||
logger.info(
|
||||
"data process result batch regeneration started batch_id=%s task_id=%s "
|
||||
"requested=%s prepared=%s concurrency=%s",
|
||||
"数据处理结果批量重新生成开始 batch_id=%s task_id=%s requested=%s prepared=%s concurrency=%s",
|
||||
batch_id,
|
||||
task_id,
|
||||
len(payload.items),
|
||||
@@ -2512,8 +2508,7 @@ def regenerate_results_batch(
|
||||
except Exception as exc: # pragma: no cover - defensive boundary
|
||||
outcome = "internal_error"
|
||||
logger.exception(
|
||||
"data process result batch regeneration crashed "
|
||||
"batch_id=%s task_id=%s result_id=%s",
|
||||
"数据处理结果批量重新生成崩溃 batch_id=%s task_id=%s result_id=%s",
|
||||
batch_id,
|
||||
task_id,
|
||||
result_id,
|
||||
@@ -2524,8 +2519,7 @@ def regenerate_results_batch(
|
||||
"message": _safe_regeneration_error(exc),
|
||||
}))
|
||||
logger.info(
|
||||
"data process result batch item finished batch_id=%s task_id=%s "
|
||||
"result_id=%s outcome=%s duration_ms=%.2f",
|
||||
"数据处理结果批量项完成 batch_id=%s task_id=%s result_id=%s outcome=%s duration_ms=%.2f",
|
||||
batch_id,
|
||||
task_id,
|
||||
result_id,
|
||||
@@ -2545,8 +2539,7 @@ def regenerate_results_batch(
|
||||
)
|
||||
duration_ms = (time.perf_counter() - started_at) * 1000
|
||||
logger.info(
|
||||
"data process result batch regeneration completed batch_id=%s task_id=%s "
|
||||
"succeeded=%s failed=%s remaining_invalid=%s duration_ms=%.2f",
|
||||
"数据处理结果批量重新生成完成 batch_id=%s task_id=%s succeeded=%s failed=%s remaining_invalid=%s duration_ms=%.2f",
|
||||
batch_id,
|
||||
task_id,
|
||||
len(success_items),
|
||||
@@ -2593,8 +2586,7 @@ def evaluate_results_batch(
|
||||
evaluation_model = store.get_generation_model(str(model_id))
|
||||
except NotFoundError:
|
||||
logger.warning(
|
||||
"data process evaluation model unavailable, judge layer "
|
||||
"skipped task_id=%s model_id=%s",
|
||||
"数据处理评测模型不可用,跳过评测层 task_id=%s model_id=%s",
|
||||
task_id,
|
||||
model_id,
|
||||
)
|
||||
@@ -2642,8 +2634,7 @@ def evaluate_results_batch(
|
||||
}))
|
||||
|
||||
logger.info(
|
||||
"data process result batch evaluation started batch_id=%s task_id=%s "
|
||||
"requested=%s prepared=%s judge_enabled=%s",
|
||||
"数据处理结果批量评测开始 batch_id=%s task_id=%s requested=%s prepared=%s judge_enabled=%s",
|
||||
batch_id,
|
||||
task_id,
|
||||
len(payload.items),
|
||||
@@ -2660,8 +2651,7 @@ def evaluate_results_batch(
|
||||
semantic_embedding_model()
|
||||
except Exception:
|
||||
logger.warning(
|
||||
"data process semantic embedding unavailable, semantic layer "
|
||||
"will be skipped batch_id=%s",
|
||||
"数据处理语义嵌入模型不可用,语义层将跳过 batch_id=%s",
|
||||
batch_id,
|
||||
)
|
||||
request_timeout = _result_regeneration_timeout(config)
|
||||
@@ -2714,8 +2704,7 @@ def evaluate_results_batch(
|
||||
"message": _safe_regeneration_error(exc),
|
||||
}))
|
||||
logger.info(
|
||||
"data process result batch evaluation item finished "
|
||||
"batch_id=%s task_id=%s result_id=%s outcome=%s duration_ms=%.2f",
|
||||
"数据处理结果批量评测项完成 batch_id=%s task_id=%s result_id=%s outcome=%s duration_ms=%.2f",
|
||||
batch_id,
|
||||
task_id,
|
||||
result_id,
|
||||
@@ -2727,8 +2716,7 @@ def evaluate_results_batch(
|
||||
failure_items = [item for _, item in sorted(failures, key=lambda pair: pair[0])]
|
||||
duration_ms = (time.perf_counter() - started_at) * 1000
|
||||
logger.info(
|
||||
"data process result batch evaluation completed batch_id=%s task_id=%s "
|
||||
"succeeded=%s failed=%s duration_ms=%.2f",
|
||||
"数据处理结果批量评测完成 batch_id=%s task_id=%s succeeded=%s failed=%s duration_ms=%.2f",
|
||||
batch_id,
|
||||
task_id,
|
||||
len(success_items),
|
||||
@@ -2784,8 +2772,7 @@ def regenerate_result(
|
||||
)
|
||||
except _ResultRegenerationFailed as exc:
|
||||
logger.warning(
|
||||
"data process result regeneration failed task_id=%s result_id=%s "
|
||||
"duration_ms=%.2f reason=%s",
|
||||
"数据处理结果重新生成失败 task_id=%s result_id=%s duration_ms=%.2f reason=%s",
|
||||
task_id,
|
||||
result_id,
|
||||
(time.perf_counter() - started_at) * 1000,
|
||||
@@ -2793,7 +2780,7 @@ def regenerate_result(
|
||||
)
|
||||
raise
|
||||
logger.info(
|
||||
"data process result regenerated task_id=%s result_id=%s duration_ms=%.2f",
|
||||
"数据处理结果重新生成完成 task_id=%s result_id=%s duration_ms=%.2f",
|
||||
task_id,
|
||||
result_id,
|
||||
(time.perf_counter() - started_at) * 1000,
|
||||
@@ -2809,5 +2796,6 @@ def publish(
|
||||
) -> dict[str, Any]:
|
||||
with api_errors():
|
||||
result = store.publish(task_id, payload.model_dump(mode="json"))
|
||||
biz_logger.info("用户发布数据处理任务成功", taskId=task_id, datasetId=result.get("dataset_id", ""))
|
||||
message = "dataset published" if result["created"] else "dataset already published"
|
||||
return ok(result, message)
|
||||
|
||||
@@ -913,6 +913,7 @@ async def _fine_tune_preflight_with_job_payload(
|
||||
|
||||
|
||||
@router.post("/login")
|
||||
@op_log(module=OpModule.SYSTEM, action=OpAction.LOGIN, target_type="user", target_name_param="username")
|
||||
async def login(payload: dict[str, Any] = Body(...), request: Request = None) -> dict[str, Any]:
|
||||
store = get_platform_store()
|
||||
ip = request.client.host if request and request.client else "unknown"
|
||||
@@ -930,6 +931,7 @@ async def login(payload: dict[str, Any] = Body(...), request: Request = None) ->
|
||||
|
||||
|
||||
@router.post("/logout")
|
||||
@op_log(module=OpModule.SYSTEM, action=OpAction.LOGOUT, target_type="user")
|
||||
async def logout(payload: dict[str, Any] = Body(...), current_user: dict = Depends(get_current_user)) -> dict[str, Any]:
|
||||
store = get_platform_store()
|
||||
session_id = payload.get("session_id", "")
|
||||
@@ -1179,6 +1181,7 @@ async def users(current_user: dict = Depends(require_admin)) -> dict[str, Any]:
|
||||
|
||||
|
||||
@router.post("/users")
|
||||
@op_log(module=OpModule.SYSTEM, action=OpAction.CREATE, target_type="user", target_name_param="username")
|
||||
async def create_user(payload: dict[str, Any] = Body(...), current_user: dict = Depends(require_admin)) -> dict[str, Any]:
|
||||
payload = dict(payload)
|
||||
payload.setdefault("password", "123456")
|
||||
@@ -1187,6 +1190,7 @@ async def create_user(payload: dict[str, Any] = Body(...), current_user: dict =
|
||||
|
||||
|
||||
@router.put("/users/{user_id}")
|
||||
@op_log(module=OpModule.SYSTEM, action=OpAction.UPDATE, target_type="user", target_name_param="user_id")
|
||||
async def update_user(user_id: str, payload: dict[str, Any] = Body(...), current_user: dict = Depends(require_admin)) -> dict[str, Any]:
|
||||
try:
|
||||
return ok(get_platform_store().update_user(user_id, payload))
|
||||
@@ -1195,6 +1199,7 @@ async def update_user(user_id: str, payload: dict[str, Any] = Body(...), current
|
||||
|
||||
|
||||
@router.delete("/users/{user_id}")
|
||||
@op_log(module=OpModule.SYSTEM, action=OpAction.DELETE, target_type="user", target_name_param="user_id")
|
||||
async def delete_user(user_id: str, current_username: str | None = Query(default=None), current_user: dict = Depends(require_admin)) -> dict[str, Any]:
|
||||
try:
|
||||
get_platform_store().delete_user(user_id, deleted_by=str(current_user.get("id") or "system"))
|
||||
@@ -1212,6 +1217,7 @@ async def delete_user(user_id: str, current_username: str | None = Query(default
|
||||
|
||||
|
||||
@router.post("/users/{user_id}/reset-password")
|
||||
@op_log(module=OpModule.SYSTEM, action=OpAction.UPDATE, target_type="user_password", target_name_param="user_id")
|
||||
async def reset_user_password(
|
||||
user_id: str,
|
||||
payload: dict[str, Any] = Body(default={}),
|
||||
@@ -1228,6 +1234,7 @@ async def reset_user_password(
|
||||
|
||||
|
||||
@router.post("/users/me/password")
|
||||
@op_log(module=OpModule.SYSTEM, action=OpAction.UPDATE, target_type="user_password")
|
||||
async def change_my_password(
|
||||
payload: dict[str, Any] = Body(...),
|
||||
current_user: dict = Depends(get_current_user),
|
||||
@@ -1310,6 +1317,7 @@ async def trained_models(current_user: dict = Depends(get_current_user)) -> dict
|
||||
|
||||
|
||||
@router.delete("/model-manage/trained-models/{model_id}")
|
||||
@op_log(module=OpModule.MODEL_MANAGE, action=OpAction.DELETE, target_type="trained_model", target_name_param="model_id")
|
||||
async def delete_trained_model(model_id: str, type: str = Query(default="merged"), current_user: dict = Depends(get_current_user)) -> dict[str, Any]:
|
||||
if not has_resource_access("trained_model", model_id, current_user, "delete"):
|
||||
raise fail(403, "no permission to delete this trained model")
|
||||
@@ -1424,6 +1432,7 @@ async def test_online_model(payload: dict[str, Any] = Body(...), current_user: d
|
||||
|
||||
|
||||
@router.post("/model-manage")
|
||||
@op_log(module=OpModule.MODEL_MANAGE, action=OpAction.CREATE, target_type="model", target_name_param="name")
|
||||
@audit_log(
|
||||
action=AuditActions.CREATE_MODEL,
|
||||
target_type="model",
|
||||
@@ -1465,6 +1474,7 @@ async def model_detail(model_id: str, current_user: dict = Depends(get_current_u
|
||||
|
||||
|
||||
@router.put("/model-manage/{model_id}")
|
||||
@op_log(module=OpModule.MODEL_MANAGE, action=OpAction.UPDATE, target_type="model", target_name_param="model_id")
|
||||
@audit_log(
|
||||
action=AuditActions.UPDATE_MODEL,
|
||||
target_type="model",
|
||||
@@ -1481,6 +1491,7 @@ async def update_model(model_id: str, payload: dict[str, Any] = Body(...), curre
|
||||
|
||||
|
||||
@router.put("/model-manage/{model_id}/purpose")
|
||||
@op_log(module=OpModule.MODEL_MANAGE, action=OpAction.UPDATE, target_type="model_purpose", target_name_param="model_id")
|
||||
async def update_model_purpose(model_id: str, payload: dict[str, Any] = Body(...), current_user: dict = Depends(get_current_user)) -> dict[str, Any]:
|
||||
# 基座模型(配置模型)只有管理员可以修改用途
|
||||
if not is_admin(current_user):
|
||||
@@ -1492,6 +1503,7 @@ async def update_model_purpose(model_id: str, payload: dict[str, Any] = Body(...
|
||||
|
||||
|
||||
@router.delete("/model-manage/{model_id}")
|
||||
@op_log(module=OpModule.MODEL_MANAGE, action=OpAction.DELETE, target_type="model", target_name_param="model_id")
|
||||
async def delete_model(model_id: str, current_user: dict = Depends(get_current_user)) -> dict[str, Any]:
|
||||
# 基座模型(配置模型)只有管理员可以删除
|
||||
if not is_admin(current_user):
|
||||
@@ -1691,6 +1703,7 @@ async def dataset_version_content(file_id: str, version_id: str, current_user: d
|
||||
|
||||
|
||||
@router.post("/dataset-manage/versions/{file_id}")
|
||||
@op_log(module=OpModule.DATASET, action=OpAction.CREATE, target_type="dataset_version", target_name_param="file_id")
|
||||
async def create_dataset_version(file_id: str, payload: dict[str, Any] = Body(...), current_user: dict = Depends(get_current_user)) -> dict[str, Any]:
|
||||
try:
|
||||
store = get_platform_store()
|
||||
@@ -1715,6 +1728,7 @@ async def activate_dataset_version(file_id: str, payload: dict[str, Any] = Body(
|
||||
|
||||
|
||||
@router.delete("/dataset-manage/versions/{file_id}/{version_id}")
|
||||
@op_log(module=OpModule.DATASET, action=OpAction.DELETE, target_type="dataset_version", target_name_param="version_id")
|
||||
async def delete_dataset_version(file_id: str, version_id: str, current_user: dict = Depends(get_current_user)) -> dict[str, Any]:
|
||||
try:
|
||||
store = get_platform_store()
|
||||
@@ -1913,6 +1927,7 @@ async def _sync_training_dataset_to_compute_node(
|
||||
|
||||
|
||||
@router.post("/dataset-manage/upload/{dataset_id}")
|
||||
@op_log(module=OpModule.DATASET, action=OpAction.UPLOAD, target_type="dataset_file", target_name_param="dataset_id")
|
||||
async def upload_dataset_files(
|
||||
dataset_id: str,
|
||||
files: list[UploadFile] = File(default=[]),
|
||||
@@ -2080,6 +2095,7 @@ async def dataset_list(current_user: dict = Depends(get_current_user)) -> dict[s
|
||||
|
||||
|
||||
@router.post("/dataset-manage")
|
||||
@op_log(module=OpModule.DATASET, action=OpAction.CREATE, target_type="dataset", target_name_param="name")
|
||||
@audit_log(
|
||||
action=AuditActions.CREATE_DATASET,
|
||||
target_type="dataset",
|
||||
@@ -2110,6 +2126,7 @@ async def dataset_detail(dataset_id: str, current_user: dict = Depends(get_curre
|
||||
|
||||
|
||||
@router.put("/dataset-manage/{dataset_id}")
|
||||
@op_log(module=OpModule.DATASET, action=OpAction.UPDATE, target_type="dataset", target_name_param="dataset_id")
|
||||
@audit_log(
|
||||
action=AuditActions.UPDATE_DATASET,
|
||||
target_type="dataset",
|
||||
@@ -2175,6 +2192,7 @@ async def fine_tune_list(current_user: dict = Depends(get_current_user)) -> dict
|
||||
|
||||
|
||||
@router.post("/fine-tune")
|
||||
@op_log(module=OpModule.FINE_TUNE, action=OpAction.CREATE, target_type="fine_tune", target_name_param="name")
|
||||
@audit_log(
|
||||
action=AuditActions.CREATE_FINE_TUNE,
|
||||
target_type="fine_tune",
|
||||
@@ -2418,6 +2436,7 @@ async def fine_tune_gpu_status(task_id: str, current_user: dict[str, Any] = Depe
|
||||
|
||||
|
||||
@router.put("/fine-tune/{task_id}")
|
||||
@op_log(module=OpModule.FINE_TUNE, action=OpAction.UPDATE, target_type="fine_tune", target_name_param="task_id")
|
||||
async def update_fine_tune(task_id: str, payload: dict[str, Any] = Body(...), current_user: dict = Depends(get_current_user)) -> dict[str, Any]:
|
||||
if not has_resource_access("fine-tune", task_id, current_user, "write"):
|
||||
raise fail(403, "no permission to update this task")
|
||||
@@ -2452,6 +2471,7 @@ async def stop_fine_tune_alt(task_id: str, current_user: dict = Depends(get_curr
|
||||
|
||||
|
||||
@router.post("/fine-tune/{task_id}/retry")
|
||||
@op_log(module=OpModule.FINE_TUNE, action=OpAction.RETRY, target_type="fine_tune", target_name_param="task_id")
|
||||
async def retry_fine_tune(task_id: str, payload: dict[str, Any] | None = Body(default=None), current_user: dict = Depends(get_current_user)) -> dict[str, Any]:
|
||||
store = get_platform_store()
|
||||
payload = payload or {}
|
||||
@@ -2883,6 +2903,7 @@ async def model_eval_start(payload: dict[str, Any] = Body(...), current_user: di
|
||||
|
||||
|
||||
@router.delete("/model-eval/{task_id}")
|
||||
@op_log(module=OpModule.MODEL_EVAL, action=OpAction.DELETE, target_type="eval_task", target_name_param="task_id")
|
||||
async def model_eval_delete(task_id: str, current_user: dict = Depends(get_current_user)) -> dict[str, Any]:
|
||||
if not has_resource_access("eval", task_id, current_user, "delete"):
|
||||
raise fail(403, "no permission to delete this eval task")
|
||||
@@ -2902,6 +2923,7 @@ async def dimension_list(current_user: dict = Depends(get_current_user)) -> dict
|
||||
|
||||
|
||||
@router.post("/dimension")
|
||||
@op_log(module=OpModule.MODEL_EVAL, action=OpAction.CREATE, target_type="dimension", target_name_param="name")
|
||||
async def dimension_create(payload: dict[str, Any] = Body(...), current_user: dict = Depends(require_admin)) -> dict[str, Any]:
|
||||
return ok(get_platform_store().create_dimension(payload))
|
||||
|
||||
@@ -2915,6 +2937,7 @@ async def dimension_detail(dimension_id: str, current_user: dict = Depends(get_c
|
||||
|
||||
|
||||
@router.put("/dimension/{dimension_id}")
|
||||
@op_log(module=OpModule.MODEL_EVAL, action=OpAction.UPDATE, target_type="dimension", target_name_param="dimension_id")
|
||||
async def dimension_update(dimension_id: str, payload: dict[str, Any] = Body(...), current_user: dict = Depends(require_admin)) -> dict[str, Any]:
|
||||
try:
|
||||
return ok(get_platform_store().update_dimension(dimension_id, payload))
|
||||
@@ -2923,6 +2946,7 @@ async def dimension_update(dimension_id: str, payload: dict[str, Any] = Body(...
|
||||
|
||||
|
||||
@router.delete("/dimension/{dimension_id}")
|
||||
@op_log(module=OpModule.MODEL_EVAL, action=OpAction.DELETE, target_type="dimension", target_name_param="dimension_id")
|
||||
async def dimension_delete(dimension_id: str, current_user: dict = Depends(require_admin)) -> dict[str, Any]:
|
||||
get_platform_store().delete_dimension(dimension_id)
|
||||
return ok({"deleted": dimension_id})
|
||||
@@ -2943,6 +2967,7 @@ async def model_compare_list(current_user: dict = Depends(get_current_user)) ->
|
||||
|
||||
|
||||
@router.post("/model-compare")
|
||||
@op_log(module=OpModule.INFERENCE, action=OpAction.CREATE, target_type="compare_task", target_name_param="name")
|
||||
async def model_compare_create(payload: dict[str, Any] = Body(...), current_user: dict = Depends(get_current_user)) -> dict[str, Any]:
|
||||
bind_active_tenant(payload, current_user)
|
||||
payload.setdefault("created_by", current_user.get("id"))
|
||||
@@ -3785,6 +3810,7 @@ async def compute_node_detail(node_id: str, current_user: dict = Depends(get_cur
|
||||
|
||||
|
||||
@router.post("/compute/nodes")
|
||||
@op_log(module=OpModule.COMPUTE, action=OpAction.CREATE, target_type="compute_node", target_name_param="name")
|
||||
async def create_compute_node(payload: dict[str, Any] = Body(...), current_user: dict = Depends(get_current_user)) -> dict[str, Any]:
|
||||
if not is_admin(current_user):
|
||||
raise fail(403, "admin permission required")
|
||||
@@ -3797,6 +3823,7 @@ async def create_compute_node(payload: dict[str, Any] = Body(...), current_user:
|
||||
|
||||
|
||||
@router.put("/compute/nodes/{node_id}")
|
||||
@op_log(module=OpModule.COMPUTE, action=OpAction.UPDATE, target_type="compute_node", target_name_param="node_id")
|
||||
async def update_compute_node(node_id: str, payload: dict[str, Any] = Body(...), current_user: dict = Depends(get_current_user)) -> dict[str, Any]:
|
||||
if not is_admin(current_user):
|
||||
raise fail(403, "admin permission required")
|
||||
@@ -3809,6 +3836,7 @@ async def update_compute_node(node_id: str, payload: dict[str, Any] = Body(...),
|
||||
|
||||
|
||||
@router.delete("/compute/nodes/{node_id}")
|
||||
@op_log(module=OpModule.COMPUTE, action=OpAction.DELETE, target_type="compute_node", target_name_param="node_id")
|
||||
async def delete_compute_node(node_id: str, current_user: dict = Depends(get_current_user)) -> dict[str, Any]:
|
||||
if not is_admin(current_user):
|
||||
raise fail(403, "admin permission required")
|
||||
@@ -4123,6 +4151,7 @@ async def compute_job_detail(job_id: str, current_user: dict = Depends(get_curre
|
||||
|
||||
|
||||
@router.post("/compute/jobs/{job_id}/stop")
|
||||
@op_log(module=OpModule.COMPUTE, action=OpAction.STOP, target_type="compute_job", target_name_param="job_id")
|
||||
async def compute_job_stop(job_id: str, current_user: dict = Depends(get_current_user)) -> dict[str, Any]:
|
||||
task = _task_for_compute_job(job_id)
|
||||
if task and not has_resource_access("fine-tune", task["id"], current_user, "write"):
|
||||
@@ -4166,6 +4195,7 @@ async def compute_job_logs(
|
||||
|
||||
|
||||
@router.post("/compute/jobs/{job_id}/retry")
|
||||
@op_log(module=OpModule.COMPUTE, action=OpAction.RETRY, target_type="compute_job", target_name_param="job_id")
|
||||
async def compute_job_retry(job_id: str, payload: dict[str, Any] | None = Body(default=None), current_user: dict = Depends(get_current_user)) -> dict[str, Any]:
|
||||
store = get_platform_store()
|
||||
payload = payload or {}
|
||||
|
||||
Reference in New Issue
Block a user