From 5c89acced68717d96ed5f941fd8b1139b19c2231 Mon Sep 17 00:00:00 2001 From: wwq Date: Fri, 24 Apr 2026 10:29:41 +0800 Subject: [PATCH] fix(api_key): validate application publication status before key generation - Ensure the application exists and is published when resource_id is present; raise an exception otherwise. --- api/app/services/api_key_service.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/app/services/api_key_service.py b/api/app/services/api_key_service.py index 49b07121..e4367e98 100644 --- a/api/app/services/api_key_service.py +++ b/api/app/services/api_key_service.py @@ -65,6 +65,11 @@ class ApiKeyService: BizCode.BAD_REQUEST ) + if data.resource_id: + app = db.get(App, data.resource_id) + if not app or not app.current_release_id: + raise BusinessException("该应用未发布", BizCode.APP_NOT_PUBLISHED) + # 生成 API Key api_key = generate_api_key(data.type)