From b064d124408a56c8264fa8376632ccc6ce20753b Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sun, 3 Sep 2023 19:02:32 +0530 Subject: [PATCH] feat: Shorthand for whitelisted function call in controllers ```diff - GET /api/method/frappe.core.doctype.user.user.get_timezones + GET /api/method/User/get_timezones ``` --- frappe/api/v1.py | 2 ++ frappe/api/v2.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/frappe/api/v1.py b/frappe/api/v1.py index 0d1de01da7..d6fa5a365c 100644 --- a/frappe/api/v1.py +++ b/frappe/api/v1.py @@ -8,6 +8,8 @@ from frappe.utils.data import sbool def handle_rpc_call(method: str): + import frappe.handler + # TODO: inline this weird circular calls frappe.local.form_dict.cmd = method return frappe.handler.handle() diff --git a/frappe/api/v2.py b/frappe/api/v2.py index 1b3896df00..8a00770e55 100644 --- a/frappe/api/v2.py +++ b/frappe/api/v2.py @@ -7,8 +7,16 @@ from frappe import _ from frappe.utils.data import sbool -def handle_rpc_call(method: str): +def handle_rpc_call(method: str, doctype: str | None = None): # TODO: inline this weird circular calls + import frappe.handler + from frappe.modules.utils import load_doctype_module + + if doctype: + # TODO: HACKY implementation, simplify all this before merge + module = load_doctype_module(doctype) + method = module.__name__ + "." + method + frappe.local.form_dict.cmd = method return frappe.handler.handle() @@ -117,6 +125,7 @@ def get_request_form_data(): url_rules = [ Rule("/method/", endpoint=handle_rpc_call), + Rule("/method//", endpoint=handle_rpc_call), Rule("/resource/", methods=["GET"], endpoint=get_doc_list), Rule("/resource/", methods=["POST"], endpoint=create_doc), Rule("/resource//", methods=["GET"], endpoint=read_doc),