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
```
This commit is contained in:
Ankush Menat 2023-09-03 19:02:32 +05:30
parent 11dd961d81
commit b064d12440
2 changed files with 12 additions and 1 deletions

View file

@ -8,6 +8,8 @@ from frappe.utils.data import sbool
def handle_rpc_call(method: str): def handle_rpc_call(method: str):
import frappe.handler
# TODO: inline this weird circular calls # TODO: inline this weird circular calls
frappe.local.form_dict.cmd = method frappe.local.form_dict.cmd = method
return frappe.handler.handle() return frappe.handler.handle()

View file

@ -7,8 +7,16 @@ from frappe import _
from frappe.utils.data import sbool 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 # 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 frappe.local.form_dict.cmd = method
return frappe.handler.handle() return frappe.handler.handle()
@ -117,6 +125,7 @@ def get_request_form_data():
url_rules = [ url_rules = [
Rule("/method/<string:method>", endpoint=handle_rpc_call), Rule("/method/<string:method>", endpoint=handle_rpc_call),
Rule("/method/<string:doctype>/<string:method>", endpoint=handle_rpc_call),
Rule("/resource/<string:doctype>", methods=["GET"], endpoint=get_doc_list), Rule("/resource/<string:doctype>", methods=["GET"], endpoint=get_doc_list),
Rule("/resource/<string:doctype>", methods=["POST"], endpoint=create_doc), Rule("/resource/<string:doctype>", methods=["POST"], endpoint=create_doc),
Rule("/resource/<string:doctype>/<string:name>", methods=["GET"], endpoint=read_doc), Rule("/resource/<string:doctype>/<string:name>", methods=["GET"], endpoint=read_doc),