Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor: split changes for api/controllers/console/explore/installed… (#29891)

Asuka Minato4cf65f0137d4
diff --git a/api/controllers/console/explore/installed_app.py b/api/controllers/console/explore/installed_app.py
index 3c95779475d..e42db10ba6f 100644
--- a/api/controllers/console/explore/installed_app.py
+++ b/api/controllers/console/explore/installed_app.py
@@ -2,7 +2,8 @@ import logging
from typing import Any
from flask import request
-from flask_restx import Resource, inputs, marshal_with, reqparse
+from flask_restx import Resource, marshal_with
+from pydantic import BaseModel
from sqlalchemy import and_, select
from werkzeug.exceptions import BadRequest, Forbidden, NotFound
@@ -18,6 +19,15 @@ from services.account_service import TenantService
from services.enterprise.enterprise_service import EnterpriseService
from services.feature_service import FeatureService
+
+class InstalledAppCreatePayload(BaseModel):
+ app_id: str
+
+
+class InstalledAppUpdatePayload(BaseModel):
+ is_pinned: bool | None = None
+
+
logger = logging.getLogger(__name__)
@@ -105,26 +115,25 @@ class InstalledAppsListApi(Resource):
@account_initialization_required
@cloud_edition_billing_resource_check("apps")
def post(self):
- parser = reqparse.RequestParser().add_argument("app_id", type=str, required=True, help="Invalid app_id")
- args = parser.parse_args()
+ payload = InstalledAppCreatePayload.model_validate(console_ns.payload or {})
- recommended_app = db.session.query(RecommendedApp).where(RecommendedApp.app_id == args["app_id"]).first()
+ recommended_app = db.session.query(RecommendedApp).where(RecommendedApp.app_id == payload.app_id).first()
if recommended_app is None:
- raise NotFound("App not found")
+ raise NotFound("Recommended app not found")
_, current_tenant_id = current_account_with_tenant()
- app = db.session.query(App).where(App.id == args["app_id"]).first()
+ app = db.session.query(App).where(App.id == payload.app_id).first()
if app is None:
- raise NotFound("App not found")
+ raise NotFound("App entity not found")
if not app.is_public:
raise Forbidden("You can't install a non-public app")
installed_app = (
db.session.query(InstalledApp)
- .where(and_(InstalledApp.app_id == args["app_id"], InstalledApp.tenant_id == current_tenant_id))
+ .where(and_(InstalledApp.app_id == payload.app_id, InstalledApp.tenant_id == current_tenant_id))
.first()
)
@@ -133,7 +142,7 @@ class InstalledAppsListApi(Resource):
recommended_app.install_count += 1
new_installed_app = InstalledApp(
- app_id=args["app_id"],
+ app_id=payload.app_id,
tenant_id=current_tenant_id,
app_owner_tenant_id=app.tenant_id,
is_pinned=False,
@@ -163,12 +172,11 @@ class InstalledAppApi(InstalledAppResource):
return {"result": "success", "message": "App uninstalled successfully"}, 204
def patch(self, installed_app):
- parser = reqparse.RequestParser().add_argument("is_pinned", type=inputs.boolean)
- args = parser.parse_args()
+ payload = InstalledAppUpdatePayload.model_validate(console_ns.payload or {})
commit_args = False
- if "is_pinned" in args:
- installed_app.is_pinned = args["is_pinned"]
+ if payload.is_pinned is not None:
+ installed_app.is_pinned = payload.is_pinned
commit_args = True
if commit_args: