fix: route ambiguitities and / in name
v1 and v2: - Use path convertor to consume entire document which MIGHT contain `/` - Drop string convertor, as it's the default - Dont merge slashes - avoid consuming something that's part of name v2: - `SI/BLAH/BLAH/submit` is not simple to parse without ambiguitity - `SI/BLAH/BLAH/method/submit` removes ambiguitity for 99.99% cases.
This commit is contained in:
parent
0c61e61743
commit
275f16060a
5 changed files with 20 additions and 16 deletions
|
|
@ -60,4 +60,5 @@ API_URL_MAP = Map(
|
|||
Submount("/api/v2", v2_rules),
|
||||
],
|
||||
strict_slashes=False, # Allows skipping trailing slashes
|
||||
merge_slashes=False,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ def update_doc(doctype: str, name: str):
|
|||
|
||||
|
||||
def delete_doc(doctype: str, name: str):
|
||||
# TODO: child doc handling
|
||||
frappe.delete_doc(doctype, name, ignore_missing=False)
|
||||
frappe.response.http_status_code = 202
|
||||
return "ok"
|
||||
|
|
|
|||
|
|
@ -54,11 +54,11 @@ def get_request_form_data():
|
|||
|
||||
|
||||
url_rules = [
|
||||
Rule("/method/<string:method>", endpoint=handle_rpc_call),
|
||||
Rule("/resource/<string:doctype>", methods=["GET"], endpoint=document_list),
|
||||
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=["PUT"], endpoint=update_doc),
|
||||
Rule("/resource/<string:doctype>/<string:name>", methods=["DELETE"], endpoint=delete_doc),
|
||||
Rule("/resource/<string:doctype>/<string:name>", methods=["POST"], endpoint=execute_doc_method),
|
||||
Rule("/method/<method>", endpoint=handle_rpc_call),
|
||||
Rule("/resource/<doctype>", methods=["GET"], endpoint=document_list),
|
||||
Rule("/resource/<doctype>", methods=["POST"], endpoint=create_doc),
|
||||
Rule("/resource/<doctype>/<path:name>/", methods=["GET"], endpoint=read_doc),
|
||||
Rule("/resource/<doctype>/<path:name>/", methods=["PUT"], endpoint=update_doc),
|
||||
Rule("/resource/<doctype>/<path:name>/", methods=["DELETE"], endpoint=delete_doc),
|
||||
Rule("/resource/<doctype>/<path:name>/", methods=["POST"], endpoint=execute_doc_method),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -42,15 +42,17 @@ def execute_doc_method(doctype: str, name: str, method: str | None = None):
|
|||
|
||||
|
||||
url_rules = [
|
||||
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=document_list),
|
||||
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=["PUT"], endpoint=update_doc),
|
||||
Rule("/resource/<string:doctype>/<string:name>", methods=["DELETE"], endpoint=delete_doc),
|
||||
Rule("/method/<method>", endpoint=handle_rpc_call),
|
||||
Rule("/method/<doctype>/<method>", endpoint=handle_rpc_call),
|
||||
Rule("/resource/<doctype>", methods=["GET"], endpoint=document_list),
|
||||
# TODO: bulk insert with array
|
||||
Rule("/resource/<doctype>", methods=["POST"], endpoint=create_doc),
|
||||
# TODO: get_value
|
||||
Rule("/resource/<doctype>/<path:name>/", methods=["GET"], endpoint=read_doc),
|
||||
Rule("/resource/<doctype>/<path:name>/", methods=["PUT"], endpoint=update_doc),
|
||||
Rule("/resource/<doctype>/<path:name>/", methods=["DELETE"], endpoint=delete_doc),
|
||||
Rule(
|
||||
"/resource/<string:doctype>/<string:name>/<string:method>",
|
||||
"/resource/<doctype>/<path:name>/method/<method>/",
|
||||
methods=["GET", "POST"],
|
||||
endpoint=execute_doc_method,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ class TestConnectedApp(FrappeTestCase):
|
|||
def delete_if_exists(attribute):
|
||||
doc = getattr(self, attribute, None)
|
||||
if doc:
|
||||
doc.delete()
|
||||
doc.delete(force=True)
|
||||
|
||||
delete_if_exists("token_cache")
|
||||
delete_if_exists("connected_app")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue