fix:修复提示词工坊相关功能 6
This commit is contained in:
@@ -533,9 +533,14 @@ async def get_my_submissions(
|
|||||||
async def withdraw_submission(
|
async def withdraw_submission(
|
||||||
submission_id: str,
|
submission_id: str,
|
||||||
request: Request,
|
request: Request,
|
||||||
|
force: bool = False,
|
||||||
db: AsyncSession = Depends(get_db)
|
db: AsyncSession = Depends(get_db)
|
||||||
):
|
):
|
||||||
"""撤回待审核的提交"""
|
"""
|
||||||
|
删除提交记录
|
||||||
|
- 待审核(pending)的提交可以直接撤回
|
||||||
|
- 已审核(approved/rejected)的提交需要 force=True 参数才能删除
|
||||||
|
"""
|
||||||
user_identifier = get_user_identifier_from_request(request)
|
user_identifier = get_user_identifier_from_request(request)
|
||||||
|
|
||||||
if is_workshop_server():
|
if is_workshop_server():
|
||||||
@@ -549,16 +554,21 @@ async def withdraw_submission(
|
|||||||
|
|
||||||
if not submission:
|
if not submission:
|
||||||
raise HTTPException(status_code=404, detail="提交记录不存在")
|
raise HTTPException(status_code=404, detail="提交记录不存在")
|
||||||
if submission.status != "pending":
|
|
||||||
raise HTTPException(status_code=400, detail="只能撤回待审核的提交")
|
# 待审核的可以直接撤回,已审核的需要 force 参数
|
||||||
|
if submission.status != "pending" and not force:
|
||||||
|
raise HTTPException(status_code=400, detail="只能撤回待审核的提交,删除已审核记录请使用 force 参数")
|
||||||
|
|
||||||
await db.delete(submission)
|
await db.delete(submission)
|
||||||
await db.commit()
|
await db.commit()
|
||||||
|
|
||||||
return {"success": True, "message": "撤回成功"}
|
if submission.status == "pending":
|
||||||
|
return {"success": True, "message": "撤回成功"}
|
||||||
|
else:
|
||||||
|
return {"success": True, "message": "删除成功"}
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
return await workshop_client.withdraw_submission(submission_id, user_identifier)
|
return await workshop_client.withdraw_submission(submission_id, user_identifier, force)
|
||||||
except WorkshopClientError as e:
|
except WorkshopClientError as e:
|
||||||
raise HTTPException(status_code=503, detail=str(e))
|
raise HTTPException(status_code=503, detail=str(e))
|
||||||
|
|
||||||
|
|||||||
@@ -157,12 +157,17 @@ class WorkshopClient:
|
|||||||
async def withdraw_submission(
|
async def withdraw_submission(
|
||||||
self,
|
self,
|
||||||
submission_id: str,
|
submission_id: str,
|
||||||
user_identifier: str
|
user_identifier: str,
|
||||||
|
force: bool = False
|
||||||
) -> Dict:
|
) -> Dict:
|
||||||
"""撤回提交"""
|
"""撤回/删除提交"""
|
||||||
|
params = {}
|
||||||
|
if force:
|
||||||
|
params["force"] = "true"
|
||||||
return await self._request(
|
return await self._request(
|
||||||
"DELETE",
|
"DELETE",
|
||||||
f"/submissions/{submission_id}",
|
f"/submissions/{submission_id}",
|
||||||
|
params=params if params else None,
|
||||||
user_identifier=user_identifier
|
user_identifier=user_identifier
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ export default function PromptWorkshop() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 撤回提交
|
// 撤回提交(pending状态)
|
||||||
const handleWithdraw = async (submissionId: string) => {
|
const handleWithdraw = async (submissionId: string) => {
|
||||||
try {
|
try {
|
||||||
await promptWorkshopApi.withdrawSubmission(submissionId);
|
await promptWorkshopApi.withdrawSubmission(submissionId);
|
||||||
@@ -253,6 +253,27 @@ export default function PromptWorkshop() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 删除提交记录(已审核状态)
|
||||||
|
const handleDeleteSubmission = async (submission: PromptSubmission) => {
|
||||||
|
Modal.confirm({
|
||||||
|
title: '删除提交记录',
|
||||||
|
content: `确定要删除「${submission.name}」的提交记录吗?此操作不可恢复。`,
|
||||||
|
okText: '删除',
|
||||||
|
okType: 'danger',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: async () => {
|
||||||
|
try {
|
||||||
|
await promptWorkshopApi.deleteSubmission(submission.id);
|
||||||
|
message.success('删除成功');
|
||||||
|
loadMySubmissions();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to delete submission:', error);
|
||||||
|
message.error('删除失败');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// 查看详情
|
// 查看详情
|
||||||
const handleViewDetail = async (item: PromptWorkshopItem) => {
|
const handleViewDetail = async (item: PromptWorkshopItem) => {
|
||||||
try {
|
try {
|
||||||
@@ -569,17 +590,30 @@ export default function PromptWorkshop() {
|
|||||||
提交时间: {sub.created_at ? new Date(sub.created_at).toLocaleDateString() : '-'}
|
提交时间: {sub.created_at ? new Date(sub.created_at).toLocaleDateString() : '-'}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{sub.status === 'pending' && (
|
<Space>
|
||||||
<Button
|
{sub.status === 'pending' && (
|
||||||
type="link"
|
<Button
|
||||||
danger
|
type="link"
|
||||||
size="small"
|
danger
|
||||||
icon={<DeleteOutlined />}
|
size="small"
|
||||||
onClick={() => handleWithdraw(sub.id)}
|
icon={<DeleteOutlined />}
|
||||||
>
|
onClick={() => handleWithdraw(sub.id)}
|
||||||
撤回
|
>
|
||||||
</Button>
|
撤回
|
||||||
)}
|
</Button>
|
||||||
|
)}
|
||||||
|
{sub.status !== 'pending' && (
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
danger
|
||||||
|
size="small"
|
||||||
|
icon={<DeleteOutlined />}
|
||||||
|
onClick={() => handleDeleteSubmission(sub)}
|
||||||
|
>
|
||||||
|
删除记录
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
</Space>
|
</Space>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
|
|||||||
@@ -695,10 +695,16 @@ export const promptWorkshopApi = {
|
|||||||
{ params: { status } }
|
{ params: { status } }
|
||||||
),
|
),
|
||||||
|
|
||||||
// 撤回提交
|
// 撤回提交(pending状态)
|
||||||
withdrawSubmission: (submissionId: string) =>
|
withdrawSubmission: (submissionId: string) =>
|
||||||
api.delete<unknown, { success: boolean; message: string }>(`/prompt-workshop/submissions/${submissionId}`),
|
api.delete<unknown, { success: boolean; message: string }>(`/prompt-workshop/submissions/${submissionId}`),
|
||||||
|
|
||||||
|
// 删除提交记录(所有状态,需要 force=true)
|
||||||
|
deleteSubmission: (submissionId: string) =>
|
||||||
|
api.delete<unknown, { success: boolean; message: string }>(`/prompt-workshop/submissions/${submissionId}`, {
|
||||||
|
params: { force: true }
|
||||||
|
}),
|
||||||
|
|
||||||
// ========== 管理员 API(仅服务端模式可用) ==========
|
// ========== 管理员 API(仅服务端模式可用) ==========
|
||||||
|
|
||||||
// 获取待审核列表
|
// 获取待审核列表
|
||||||
|
|||||||
Reference in New Issue
Block a user