|
|
|
@@ -62,7 +62,7 @@ def canvas_list(): |
|
|
|
@login_required |
|
|
|
def rm(): |
|
|
|
for i in request.json["canvas_ids"]: |
|
|
|
if not UserCanvasService.query(user_id=current_user.id,id=i): |
|
|
|
if not UserCanvasService.accessible(i, current_user.id): |
|
|
|
return get_json_result( |
|
|
|
data=False, message='Only owner of canvas authorized for this operation.', |
|
|
|
code=RetCode.OPERATING_ERROR) |
|
|
|
@@ -86,7 +86,7 @@ def save(): |
|
|
|
if not UserCanvasService.save(**req): |
|
|
|
return get_data_error_result(message="Fail to save canvas.") |
|
|
|
else: |
|
|
|
if not UserCanvasService.query(user_id=current_user.id, id=req["id"]): |
|
|
|
if not UserCanvasService.accessible(req["id"], current_user.id): |
|
|
|
return get_json_result( |
|
|
|
data=False, message='Only owner of canvas authorized for this operation.', |
|
|
|
code=RetCode.OPERATING_ERROR) |
|
|
|
@@ -100,10 +100,9 @@ def save(): |
|
|
|
@manager.route('/get/<canvas_id>', methods=['GET']) # noqa: F821 |
|
|
|
@login_required |
|
|
|
def get(canvas_id): |
|
|
|
e, c = UserCanvasService.get_by_tenant_id(canvas_id) |
|
|
|
tids = [t.tenant_id for t in UserTenantService.query(user_id=current_user.id)] |
|
|
|
if not e or (c["user_id"] != current_user.id and c["user_id"] not in tids): |
|
|
|
if not UserCanvasService.accessible(canvas_id, current_user.id): |
|
|
|
return get_data_error_result(message="canvas not found.") |
|
|
|
e, c = UserCanvasService.get_by_tenant_id(canvas_id) |
|
|
|
return get_json_result(data=c) |
|
|
|
|
|
|
|
|
|
|
|
@@ -132,14 +131,15 @@ def run(): |
|
|
|
files = req.get("files", []) |
|
|
|
inputs = req.get("inputs", {}) |
|
|
|
user_id = req.get("user_id", current_user.id) |
|
|
|
e, cvs = UserCanvasService.get_by_id(req["id"]) |
|
|
|
if not e: |
|
|
|
return get_data_error_result(message="canvas not found.") |
|
|
|
if not UserCanvasService.query(user_id=current_user.id, id=req["id"]): |
|
|
|
if not UserCanvasService.accessible(req["id"], current_user.id): |
|
|
|
return get_json_result( |
|
|
|
data=False, message='Only owner of canvas authorized for this operation.', |
|
|
|
code=RetCode.OPERATING_ERROR) |
|
|
|
|
|
|
|
e, cvs = UserCanvasService.get_by_id(req["id"]) |
|
|
|
if not e: |
|
|
|
return get_data_error_result(message="canvas not found.") |
|
|
|
|
|
|
|
if not isinstance(cvs.dsl, str): |
|
|
|
cvs.dsl = json.dumps(cvs.dsl, ensure_ascii=False) |
|
|
|
|
|
|
|
@@ -173,14 +173,14 @@ def run(): |
|
|
|
@login_required |
|
|
|
def reset(): |
|
|
|
req = request.json |
|
|
|
if not UserCanvasService.accessible(req["id"], current_user.id): |
|
|
|
return get_json_result( |
|
|
|
data=False, message='Only owner of canvas authorized for this operation.', |
|
|
|
code=RetCode.OPERATING_ERROR) |
|
|
|
try: |
|
|
|
e, user_canvas = UserCanvasService.get_by_id(req["id"]) |
|
|
|
if not e: |
|
|
|
return get_data_error_result(message="canvas not found.") |
|
|
|
if not UserCanvasService.query(user_id=current_user.id, id=req["id"]): |
|
|
|
return get_json_result( |
|
|
|
data=False, message='Only owner of canvas authorized for this operation.', |
|
|
|
code=RetCode.OPERATING_ERROR) |
|
|
|
|
|
|
|
canvas = Canvas(json.dumps(user_canvas.dsl), current_user.id) |
|
|
|
canvas.reset() |
|
|
|
@@ -291,15 +291,12 @@ def input_form(): |
|
|
|
@login_required |
|
|
|
def debug(): |
|
|
|
req = request.json |
|
|
|
if not UserCanvasService.accessible(req["id"], current_user.id): |
|
|
|
return get_json_result( |
|
|
|
data=False, message='Only owner of canvas authorized for this operation.', |
|
|
|
code=RetCode.OPERATING_ERROR) |
|
|
|
try: |
|
|
|
e, user_canvas = UserCanvasService.get_by_id(req["id"]) |
|
|
|
if not e: |
|
|
|
return get_data_error_result(message="canvas not found.") |
|
|
|
if not UserCanvasService.query(user_id=current_user.id, id=req["id"]): |
|
|
|
return get_json_result( |
|
|
|
data=False, message='Only owner of canvas authorized for this operation.', |
|
|
|
code=RetCode.OPERATING_ERROR) |
|
|
|
|
|
|
|
canvas = Canvas(json.dumps(user_canvas.dsl), current_user.id) |
|
|
|
canvas.reset() |
|
|
|
canvas.message_id = get_uuid() |
|
|
|
@@ -405,6 +402,12 @@ def list_kbs(): |
|
|
|
def setting(): |
|
|
|
req = request.json |
|
|
|
req["user_id"] = current_user.id |
|
|
|
|
|
|
|
if not UserCanvasService.accessible(req["id"], current_user.id): |
|
|
|
return get_json_result( |
|
|
|
data=False, message='Only owner of canvas authorized for this operation.', |
|
|
|
code=RetCode.OPERATING_ERROR) |
|
|
|
|
|
|
|
e,flow = UserCanvasService.get_by_id(req["id"]) |
|
|
|
if not e: |
|
|
|
return get_data_error_result(message="canvas not found.") |
|
|
|
@@ -416,10 +419,7 @@ def setting(): |
|
|
|
flow["permission"] = req["permission"] |
|
|
|
if req["avatar"]: |
|
|
|
flow["avatar"] = req["avatar"] |
|
|
|
if not UserCanvasService.query(user_id=current_user.id, id=req["id"]): |
|
|
|
return get_json_result( |
|
|
|
data=False, message='Only owner of canvas authorized for this operation.', |
|
|
|
code=RetCode.OPERATING_ERROR) |
|
|
|
|
|
|
|
num= UserCanvasService.update_by_id(req["id"], flow) |
|
|
|
return get_json_result(data=num) |
|
|
|
|
|
|
|
@@ -442,8 +442,10 @@ def trace(): |
|
|
|
@login_required |
|
|
|
def sessions(canvas_id): |
|
|
|
tenant_id = current_user.id |
|
|
|
if not UserCanvasService.query(user_id=tenant_id, id=canvas_id): |
|
|
|
return get_error_data_result(message=f"You don't own the agent {canvas_id}.") |
|
|
|
if not UserCanvasService.accessible(canvas_id, tenant_id): |
|
|
|
return get_json_result( |
|
|
|
data=False, message='Only owner of canvas authorized for this operation.', |
|
|
|
code=RetCode.OPERATING_ERROR) |
|
|
|
|
|
|
|
user_id = request.args.get("user_id") |
|
|
|
page_number = int(request.args.get("page", 1)) |