| 
									
										
										
										
											2024-04-24 15:02:29 +08:00
										 |  |  | import uuid | 
					
						
							| 
									
										
										
										
											2024-11-22 15:05:04 +08:00
										 |  |  | from typing import cast | 
					
						
							| 
									
										
										
										
											2024-04-24 15:02:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-24 18:38:51 +08:00
										 |  |  | from flask_login import current_user  # type: ignore | 
					
						
							|  |  |  | from flask_restful import Resource, inputs, marshal, marshal_with, reqparse  # type: ignore | 
					
						
							| 
									
										
										
										
											2024-11-22 15:05:04 +08:00
										 |  |  | from sqlalchemy import select | 
					
						
							|  |  |  | from sqlalchemy.orm import Session | 
					
						
							| 
									
										
										
										
											2024-04-24 15:02:29 +08:00
										 |  |  | from werkzeug.exceptions import BadRequest, Forbidden, abort | 
					
						
							| 
									
										
										
										
											2024-02-06 13:21:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | from controllers.console import api | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | from controllers.console.app.wraps import get_app_model | 
					
						
							| 
									
										
										
										
											2024-11-01 15:51:22 +08:00
										 |  |  | from controllers.console.wraps import ( | 
					
						
							|  |  |  |     account_initialization_required, | 
					
						
							|  |  |  |     cloud_edition_billing_resource_check, | 
					
						
							| 
									
										
										
										
											2024-11-15 17:59:36 +08:00
										 |  |  |     enterprise_license_required, | 
					
						
							| 
									
										
										
										
											2024-11-01 15:51:22 +08:00
										 |  |  |     setup_required, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2024-06-26 17:33:29 +08:00
										 |  |  | from core.ops.ops_trace_manager import OpsTraceManager | 
					
						
							| 
									
										
										
										
											2024-11-22 15:05:04 +08:00
										 |  |  | from extensions.ext_database import db | 
					
						
							| 
									
										
										
										
											2024-02-06 13:21:13 +08:00
										 |  |  | from fields.app_fields import ( | 
					
						
							|  |  |  |     app_detail_fields, | 
					
						
							|  |  |  |     app_detail_fields_with_site, | 
					
						
							|  |  |  |     app_pagination_fields, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2024-01-12 12:34:01 +08:00
										 |  |  | from libs.login import login_required | 
					
						
							| 
									
										
										
										
											2024-11-22 15:05:04 +08:00
										 |  |  | from models import Account, App | 
					
						
							|  |  |  | from services.app_dsl_service import AppDslService, ImportMode | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | from services.app_service import AppService | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  | ALLOW_CREATE_APP_MODES = ["chat", "agent-chat", "advanced-chat", "workflow", "completion"] | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class AppListApi(Resource): | 
					
						
							|  |  |  |     @setup_required | 
					
						
							|  |  |  |     @login_required | 
					
						
							|  |  |  |     @account_initialization_required | 
					
						
							| 
									
										
										
										
											2024-11-15 17:59:36 +08:00
										 |  |  |     @enterprise_license_required | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     def get(self): | 
					
						
							|  |  |  |         """Get app list""" | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-24 15:02:29 +08:00
										 |  |  |         def uuid_list(value): | 
					
						
							|  |  |  |             try: | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |                 return [str(uuid.UUID(v)) for v in value.split(",")] | 
					
						
							| 
									
										
										
										
											2024-04-24 15:02:29 +08:00
										 |  |  |             except ValueError: | 
					
						
							|  |  |  |                 abort(400, message="Invalid UUID format in tag_ids.") | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         parser = reqparse.RequestParser() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         parser.add_argument("page", type=inputs.int_range(1, 99999), required=False, default=1, location="args") | 
					
						
							|  |  |  |         parser.add_argument("limit", type=inputs.int_range(1, 100), required=False, default=20, location="args") | 
					
						
							|  |  |  |         parser.add_argument( | 
					
						
							|  |  |  |             "mode", | 
					
						
							|  |  |  |             type=str, | 
					
						
							|  |  |  |             choices=["chat", "workflow", "agent-chat", "channel", "all"], | 
					
						
							|  |  |  |             default="all", | 
					
						
							|  |  |  |             location="args", | 
					
						
							|  |  |  |             required=False, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         parser.add_argument("name", type=str, location="args", required=False) | 
					
						
							|  |  |  |         parser.add_argument("tag_ids", type=uuid_list, location="args", required=False) | 
					
						
							| 
									
										
										
										
											2025-01-03 16:38:36 +09:00
										 |  |  |         parser.add_argument("is_created_by_me", type=inputs.boolean, location="args", required=False) | 
					
						
							| 
									
										
										
										
											2024-04-24 15:02:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         args = parser.parse_args() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         # get app list | 
					
						
							|  |  |  |         app_service = AppService() | 
					
						
							| 
									
										
										
										
											2025-01-03 16:38:36 +09:00
										 |  |  |         app_pagination = app_service.get_paginate_apps(current_user.id, current_user.current_tenant_id, args) | 
					
						
							| 
									
										
										
										
											2024-04-24 15:02:29 +08:00
										 |  |  |         if not app_pagination: | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |             return {"data": [], "total": 0, "page": 1, "limit": 20, "has_more": False} | 
					
						
							| 
									
										
										
										
											2024-01-23 19:58:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-24 15:02:29 +08:00
										 |  |  |         return marshal(app_pagination, app_pagination_fields) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     @setup_required | 
					
						
							|  |  |  |     @login_required | 
					
						
							|  |  |  |     @account_initialization_required | 
					
						
							|  |  |  |     @marshal_with(app_detail_fields) | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |     @cloud_edition_billing_resource_check("apps") | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     def post(self): | 
					
						
							|  |  |  |         """Create app""" | 
					
						
							|  |  |  |         parser = reqparse.RequestParser() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         parser.add_argument("name", type=str, required=True, location="json") | 
					
						
							|  |  |  |         parser.add_argument("description", type=str, location="json") | 
					
						
							|  |  |  |         parser.add_argument("mode", type=str, choices=ALLOW_CREATE_APP_MODES, location="json") | 
					
						
							|  |  |  |         parser.add_argument("icon_type", type=str, location="json") | 
					
						
							|  |  |  |         parser.add_argument("icon", type=str, location="json") | 
					
						
							|  |  |  |         parser.add_argument("icon_background", type=str, location="json") | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         args = parser.parse_args() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-14 07:34:25 -05:00
										 |  |  |         # The role of the current user in the ta table must be admin, owner, or editor | 
					
						
							|  |  |  |         if not current_user.is_editor: | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |             raise Forbidden() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         if "mode" not in args or args["mode"] is None: | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |             raise BadRequest("mode is required") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         app_service = AppService() | 
					
						
							|  |  |  |         app = app_service.create_app(current_user.current_tenant_id, args, current_user) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return app, 201 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class AppApi(Resource): | 
					
						
							|  |  |  |     @setup_required | 
					
						
							|  |  |  |     @login_required | 
					
						
							|  |  |  |     @account_initialization_required | 
					
						
							| 
									
										
										
										
											2024-11-15 17:59:36 +08:00
										 |  |  |     @enterprise_license_required | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     @get_app_model | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     @marshal_with(app_detail_fields_with_site) | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     def get(self, app_model): | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         """Get app detail""" | 
					
						
							| 
									
										
										
										
											2024-04-23 15:22:42 +08:00
										 |  |  |         app_service = AppService() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         app_model = app_service.get_app(app_model) | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return app_model | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @setup_required | 
					
						
							|  |  |  |     @login_required | 
					
						
							|  |  |  |     @account_initialization_required | 
					
						
							|  |  |  |     @get_app_model | 
					
						
							|  |  |  |     @marshal_with(app_detail_fields_with_site) | 
					
						
							|  |  |  |     def put(self, app_model): | 
					
						
							|  |  |  |         """Update app""" | 
					
						
							| 
									
										
										
										
											2024-06-17 03:06:32 -05:00
										 |  |  |         # The role of the current user in the ta table must be admin, owner, or editor | 
					
						
							|  |  |  |         if not current_user.is_editor: | 
					
						
							|  |  |  |             raise Forbidden() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         parser = reqparse.RequestParser() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         parser.add_argument("name", type=str, required=True, nullable=False, location="json") | 
					
						
							|  |  |  |         parser.add_argument("description", type=str, location="json") | 
					
						
							|  |  |  |         parser.add_argument("icon_type", type=str, location="json") | 
					
						
							|  |  |  |         parser.add_argument("icon", type=str, location="json") | 
					
						
							|  |  |  |         parser.add_argument("icon_background", type=str, location="json") | 
					
						
							|  |  |  |         parser.add_argument("max_active_requests", type=int, location="json") | 
					
						
							| 
									
										
										
										
											2024-09-02 21:00:41 +09:00
										 |  |  |         parser.add_argument("use_icon_as_answer_icon", type=bool, location="json") | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         args = parser.parse_args() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         app_service = AppService() | 
					
						
							|  |  |  |         app_model = app_service.update_app(app_model, args) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return app_model | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     @setup_required | 
					
						
							|  |  |  |     @login_required | 
					
						
							|  |  |  |     @account_initialization_required | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     @get_app_model | 
					
						
							|  |  |  |     def delete(self, app_model): | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         """Delete app""" | 
					
						
							| 
									
										
										
										
											2024-06-17 03:06:32 -05:00
										 |  |  |         # The role of the current user in the ta table must be admin, owner, or editor | 
					
						
							| 
									
										
										
										
											2024-06-14 07:34:25 -05:00
										 |  |  |         if not current_user.is_editor: | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |             raise Forbidden() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         app_service = AppService() | 
					
						
							|  |  |  |         app_service.delete_app(app_model) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         return {"result": "success"}, 204 | 
					
						
							| 
									
										
										
										
											2023-08-12 14:18:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class AppCopyApi(Resource): | 
					
						
							|  |  |  |     @setup_required | 
					
						
							|  |  |  |     @login_required | 
					
						
							|  |  |  |     @account_initialization_required | 
					
						
							|  |  |  |     @get_app_model | 
					
						
							|  |  |  |     @marshal_with(app_detail_fields_with_site) | 
					
						
							|  |  |  |     def post(self, app_model): | 
					
						
							|  |  |  |         """Copy app""" | 
					
						
							| 
									
										
										
										
											2024-06-14 07:34:25 -05:00
										 |  |  |         # The role of the current user in the ta table must be admin, owner, or editor | 
					
						
							|  |  |  |         if not current_user.is_editor: | 
					
						
							| 
									
										
										
										
											2023-08-12 14:18:21 +08:00
										 |  |  |             raise Forbidden() | 
					
						
							| 
									
										
										
										
											2023-08-21 13:57:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         parser = reqparse.RequestParser() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         parser.add_argument("name", type=str, location="json") | 
					
						
							|  |  |  |         parser.add_argument("description", type=str, location="json") | 
					
						
							|  |  |  |         parser.add_argument("icon_type", type=str, location="json") | 
					
						
							|  |  |  |         parser.add_argument("icon", type=str, location="json") | 
					
						
							|  |  |  |         parser.add_argument("icon_background", type=str, location="json") | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         args = parser.parse_args() | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-22 15:05:04 +08:00
										 |  |  |         with Session(db.engine) as session: | 
					
						
							|  |  |  |             import_service = AppDslService(session) | 
					
						
							|  |  |  |             yaml_content = import_service.export_dsl(app_model=app_model, include_secret=True) | 
					
						
							|  |  |  |             account = cast(Account, current_user) | 
					
						
							|  |  |  |             result = import_service.import_app( | 
					
						
							|  |  |  |                 account=account, | 
					
						
							|  |  |  |                 import_mode=ImportMode.YAML_CONTENT.value, | 
					
						
							|  |  |  |                 yaml_content=yaml_content, | 
					
						
							|  |  |  |                 name=args.get("name"), | 
					
						
							|  |  |  |                 description=args.get("description"), | 
					
						
							|  |  |  |                 icon_type=args.get("icon_type"), | 
					
						
							|  |  |  |                 icon=args.get("icon"), | 
					
						
							|  |  |  |                 icon_background=args.get("icon_background"), | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |             session.commit() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-26 13:42:13 +08:00
										 |  |  |             stmt = select(App).where(App.id == result.app_id) | 
					
						
							| 
									
										
										
										
											2024-11-22 15:05:04 +08:00
										 |  |  |             app = session.scalar(stmt) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         return app, 201 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | class AppExportApi(Resource): | 
					
						
							|  |  |  |     @setup_required | 
					
						
							|  |  |  |     @login_required | 
					
						
							|  |  |  |     @account_initialization_required | 
					
						
							|  |  |  |     @get_app_model | 
					
						
							|  |  |  |     def get(self, app_model): | 
					
						
							|  |  |  |         """Export app""" | 
					
						
							| 
									
										
										
										
											2024-07-02 13:37:37 +08:00
										 |  |  |         # The role of the current user in the ta table must be admin, owner, or editor | 
					
						
							|  |  |  |         if not current_user.is_editor: | 
					
						
							|  |  |  |             raise Forbidden() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |         # Add include_secret params | 
					
						
							|  |  |  |         parser = reqparse.RequestParser() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         parser.add_argument("include_secret", type=inputs.boolean, default=False, location="args") | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |         args = parser.parse_args() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         return {"data": AppDslService.export_dsl(app_model=app_model, include_secret=args["include_secret"])} | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class AppNameApi(Resource): | 
					
						
							|  |  |  |     @setup_required | 
					
						
							|  |  |  |     @login_required | 
					
						
							|  |  |  |     @account_initialization_required | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     @get_app_model | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     @marshal_with(app_detail_fields) | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     def post(self, app_model): | 
					
						
							| 
									
										
										
										
											2024-06-17 03:06:32 -05:00
										 |  |  |         # The role of the current user in the ta table must be admin, owner, or editor | 
					
						
							|  |  |  |         if not current_user.is_editor: | 
					
						
							|  |  |  |             raise Forbidden() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         parser = reqparse.RequestParser() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         parser.add_argument("name", type=str, required=True, location="json") | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         args = parser.parse_args() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         app_service = AppService() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         app_model = app_service.update_app_name(app_model, args.get("name")) | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return app_model | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class AppIconApi(Resource): | 
					
						
							|  |  |  |     @setup_required | 
					
						
							|  |  |  |     @login_required | 
					
						
							|  |  |  |     @account_initialization_required | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     @get_app_model | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     @marshal_with(app_detail_fields) | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     def post(self, app_model): | 
					
						
							| 
									
										
										
										
											2024-06-17 03:06:32 -05:00
										 |  |  |         # The role of the current user in the ta table must be admin, owner, or editor | 
					
						
							|  |  |  |         if not current_user.is_editor: | 
					
						
							|  |  |  |             raise Forbidden() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         parser = reqparse.RequestParser() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         parser.add_argument("icon", type=str, location="json") | 
					
						
							|  |  |  |         parser.add_argument("icon_background", type=str, location="json") | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         args = parser.parse_args() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         app_service = AppService() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         app_model = app_service.update_app_icon(app_model, args.get("icon"), args.get("icon_background")) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         return app_model | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class AppSiteStatus(Resource): | 
					
						
							|  |  |  |     @setup_required | 
					
						
							|  |  |  |     @login_required | 
					
						
							|  |  |  |     @account_initialization_required | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     @get_app_model | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     @marshal_with(app_detail_fields) | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     def post(self, app_model): | 
					
						
							| 
									
										
										
										
											2024-06-14 07:34:25 -05:00
										 |  |  |         # The role of the current user in the ta table must be admin, owner, or editor | 
					
						
							|  |  |  |         if not current_user.is_editor: | 
					
						
							|  |  |  |             raise Forbidden() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         parser = reqparse.RequestParser() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         parser.add_argument("enable_site", type=bool, required=True, location="json") | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         args = parser.parse_args() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         app_service = AppService() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         app_model = app_service.update_app_site_status(app_model, args.get("enable_site")) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         return app_model | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class AppApiStatus(Resource): | 
					
						
							|  |  |  |     @setup_required | 
					
						
							|  |  |  |     @login_required | 
					
						
							|  |  |  |     @account_initialization_required | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     @get_app_model | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     @marshal_with(app_detail_fields) | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     def post(self, app_model): | 
					
						
							| 
									
										
										
										
											2024-06-14 07:34:25 -05:00
										 |  |  |         # The role of the current user in the ta table must be admin or owner | 
					
						
							|  |  |  |         if not current_user.is_admin_or_owner: | 
					
						
							|  |  |  |             raise Forbidden() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         parser = reqparse.RequestParser() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         parser.add_argument("enable_api", type=bool, required=True, location="json") | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         args = parser.parse_args() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         app_service = AppService() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         app_model = app_service.update_app_api_status(app_model, args.get("enable_api")) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         return app_model | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-26 17:33:29 +08:00
										 |  |  | class AppTraceApi(Resource): | 
					
						
							|  |  |  |     @setup_required | 
					
						
							|  |  |  |     @login_required | 
					
						
							|  |  |  |     @account_initialization_required | 
					
						
							|  |  |  |     def get(self, app_id): | 
					
						
							|  |  |  |         """Get app trace""" | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         app_trace_config = OpsTraceManager.get_app_tracing_config(app_id=app_id) | 
					
						
							| 
									
										
										
										
											2024-06-26 17:33:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return app_trace_config | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @setup_required | 
					
						
							|  |  |  |     @login_required | 
					
						
							|  |  |  |     @account_initialization_required | 
					
						
							|  |  |  |     def post(self, app_id): | 
					
						
							|  |  |  |         # add app trace | 
					
						
							|  |  |  |         if not current_user.is_admin_or_owner: | 
					
						
							|  |  |  |             raise Forbidden() | 
					
						
							|  |  |  |         parser = reqparse.RequestParser() | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |         parser.add_argument("enabled", type=bool, required=True, location="json") | 
					
						
							|  |  |  |         parser.add_argument("tracing_provider", type=str, required=True, location="json") | 
					
						
							| 
									
										
										
										
											2024-06-26 17:33:29 +08:00
										 |  |  |         args = parser.parse_args() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         OpsTraceManager.update_app_tracing_config( | 
					
						
							|  |  |  |             app_id=app_id, | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |             enabled=args["enabled"], | 
					
						
							|  |  |  |             tracing_provider=args["tracing_provider"], | 
					
						
							| 
									
										
										
										
											2024-06-26 17:33:29 +08:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return {"result": "success"} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  | api.add_resource(AppListApi, "/apps") | 
					
						
							|  |  |  | api.add_resource(AppApi, "/apps/<uuid:app_id>") | 
					
						
							|  |  |  | api.add_resource(AppCopyApi, "/apps/<uuid:app_id>/copy") | 
					
						
							|  |  |  | api.add_resource(AppExportApi, "/apps/<uuid:app_id>/export") | 
					
						
							|  |  |  | api.add_resource(AppNameApi, "/apps/<uuid:app_id>/name") | 
					
						
							|  |  |  | api.add_resource(AppIconApi, "/apps/<uuid:app_id>/icon") | 
					
						
							|  |  |  | api.add_resource(AppSiteStatus, "/apps/<uuid:app_id>/site-enable") | 
					
						
							|  |  |  | api.add_resource(AppApiStatus, "/apps/<uuid:app_id>/api-enable") | 
					
						
							|  |  |  | api.add_resource(AppTraceApi, "/apps/<uuid:app_id>/trace") |