From 7cf0f55f99f2f1d3cece3367eaeb74e84dc5b609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Diot?= Date: Sat, 6 Apr 2024 09:51:43 +0100 Subject: [PATCH] Refactor main.py to handle Response objects in run_action and custom_plugin functions --- src/ui/main.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ui/main.py b/src/ui/main.py index a06d2f5b7..4142f3f06 100755 --- a/src/ui/main.py +++ b/src/ui/main.py @@ -340,6 +340,9 @@ def run_action(plugin: str, function_name: str = ""): if message or not isinstance(res, dict) and not res: return {"status": "ko", "code": 500, "message": message or "The plugin did not return a valid response"} + if isinstance(res, Response): + return res + return {"status": "ok", "code": 200, "data": res} @@ -1625,11 +1628,19 @@ def custom_plugin(plugin: str): ) action_result = run_action(plugin) + + if isinstance(action_result, Response): + app.logger.info(f"Plugin {plugin} action executed successfully") + return action_result + # case error if action_result["status"] == "ko": return error_message(action_result["message"]), action_result["code"] app.logger.info(f"Plugin {plugin} action executed successfully") + + if request.content_type == "application/x-www-form-urlencoded": + return redirect(f"{url_for('plugins')}/{plugin}", code=303) return jsonify({"message": "ok", "data": action_result["data"]}), 200