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.

fix: accept icon type in app icon updates (#35360)

hyl64ceec00e1729f
diff --git a/api/controllers/console/app/app.py b/api/controllers/console/app/app.py
index 051d08aa36f..9102983d869 100644
--- a/api/controllers/console/app/app.py
+++ b/api/controllers/console/app/app.py
@@ -129,6 +129,7 @@ class AppNamePayload(BaseModel):
class AppIconPayload(BaseModel):
icon: str | None = Field(default=None, description="Icon data")
+ icon_type: IconType | None = Field(default=None, description="Icon type")
icon_background: str | None = Field(default=None, description="Icon background color")
@@ -729,7 +730,12 @@ class AppIconApi(Resource):
args = AppIconPayload.model_validate(console_ns.payload or {})
app_service = AppService()
- app_model = app_service.update_app_icon(app_model, args.icon or "", args.icon_background or "")
+ app_model = app_service.update_app_icon(
+ app_model,
+ args.icon or "",
+ args.icon_background or "",
+ args.icon_type,
+ )
response_model = AppDetail.model_validate(app_model, from_attributes=True)
return response_model.model_dump(mode="json")
diff --git a/api/services/app_service.py b/api/services/app_service.py
index 038c59633af..a046b909b38 100644
--- a/api/services/app_service.py
+++ b/api/services/app_service.py
@@ -303,17 +303,22 @@ class AppService:
return app
- def update_app_icon(self, app: App, icon: str, icon_background: str) -> App:
+ def update_app_icon(
+ self, app: App, icon: str, icon_background: str, icon_type: IconType | str | None = None
+ ) -> App:
"""
Update app icon
:param app: App instance
:param icon: new icon
:param icon_background: new icon_background
+ :param icon_type: new icon type
:return: App instance
"""
assert current_user is not None
app.icon = icon
app.icon_background = icon_background
+ if icon_type is not None:
+ app.icon_type = icon_type if isinstance(icon_type, IconType) else IconType(icon_type)
app.updated_by = current_user.id
app.updated_at = naive_utc_now()
db.session.commit()
diff --git a/api/tests/test_containers_integration_tests/controllers/console/app/test_app_apis.py b/api/tests/test_containers_integration_tests/controllers/console/app/test_app_apis.py
index 15dec06311a..18755ef012d 100644
--- a/api/tests/test_containers_integration_tests/controllers/console/app/test_app_apis.py
+++ b/api/tests/test_containers_integration_tests/controllers/console/app/test_app_apis.py
@@ -234,6 +234,35 @@ class TestAppEndpoints:
}
)
+ def test_app_icon_post_should_forward_icon_type(self, app, monkeypatch):
+ api = app_module.AppIconApi()
+ method = _unwrap(api.post)
+ payload = {
+ "icon": "https://example.com/icon.png",
+ "icon_type": "image",
+ "icon_background": "#FFFFFF",
+ }
+ app_service = MagicMock()
+ app_service.update_app_icon.return_value = SimpleNamespace()
+ response_model = MagicMock()
+ response_model.model_dump.return_value = {"id": "app-1"}
+
+ monkeypatch.setattr(app_module, "AppService", lambda: app_service)
+ monkeypatch.setattr(app_module.AppDetail, "model_validate", MagicMock(return_value=response_model))
+
+ with (
+ app.test_request_context("/console/api/apps/app-1/icon", method="POST", json=payload),
+ patch.object(type(console_ns), "payload", payload),
+ ):
+ response = method(app_model=SimpleNamespace())
+
+ assert response == {"id": "app-1"}
+ assert app_service.update_app_icon.call_args.args[1:] == (
+ payload["icon"],
+ payload["icon_background"],
+ app_module.IconType.IMAGE,
+ )
+
class TestOpsTraceEndpoints:
@pytest.fixture
diff --git a/api/tests/test_containers_integration_tests/services/test_app_service.py b/api/tests/test_containers_integration_tests/services/test_app_service.py
index fa57dd4a6ff..b695ae9fd9e 100644
--- a/api/tests/test_containers_integration_tests/services/test_app_service.py
+++ b/api/tests/test_containers_integration_tests/services/test_app_service.py
@@ -658,15 +658,17 @@ class TestAppService:
# Update app icon
new_icon = "🌟"
new_icon_background = "#FFD93D"
+ new_icon_type = "image"
mock_current_user = create_autospec(Account, instance=True)
mock_current_user.id = account.id
mock_current_user.current_tenant_id = account.current_tenant_id
with patch("services.app_service.current_user", mock_current_user):
- updated_app = app_service.update_app_icon(app, new_icon, new_icon_background)
+ updated_app = app_service.update_app_icon(app, new_icon, new_icon_background, new_icon_type)
assert updated_app.icon == new_icon
assert updated_app.icon_background == new_icon_background
+ assert str(updated_app.icon_type).lower() == new_icon_type
assert updated_app.updated_by == account.id
# Verify other fields remain unchanged