diff --git a/frappe/api/v2.py b/frappe/api/v2.py index c08707267c..dafb0923f5 100644 --- a/frappe/api/v2.py +++ b/frappe/api/v2.py @@ -32,10 +32,6 @@ def handle_rpc_call(method: str, doctype: str | None = None): module = load_doctype_module(doctype) method = module.__name__ + "." + method - if method == "login": - # Login works implicitly right now. - return - for hook in reversed(frappe.get_hooks("override_whitelisted_methods", {}).get(method, [])): # override using the last hook method = hook @@ -57,6 +53,16 @@ def handle_rpc_call(method: str, doctype: str | None = None): return frappe.call(method, **frappe.form_dict) +def login(): + """Login happens implicitly, this function doesn't do anything.""" + pass + + +def logout(): + frappe.local.login_manager.logout() + frappe.db.commit() + + def read_doc(doctype: str, name: str): doc = frappe.get_doc(doctype, name) doc.check_permission("read") @@ -150,6 +156,9 @@ def run_doc_method(method: str, document: dict[str, Any] | str, kwargs=None): url_rules = [ + Rule("/method/login", endpoint=login), + Rule("/method/logout", endpoint=logout), + Rule("/method/ping", endpoint=frappe.ping), Rule("/method/", endpoint=handle_rpc_call), Rule( "/method/run_doc_method", diff --git a/frappe/tests/test_api.py b/frappe/tests/test_api.py index a5025a7c98..e6bc617192 100644 --- a/frappe/tests/test_api.py +++ b/frappe/tests/test_api.py @@ -333,7 +333,7 @@ class TestMethodAPIV2(FrappeAPITestCase): return super().setUp() def test_ping(self): - response = self.get(self.method_path("frappe.ping")) + response = self.get(self.method_path("ping")) self.assertEqual(response.status_code, 200) self.assertIsInstance(response.json, dict) self.assertEqual(response.json["data"], "pong") @@ -373,6 +373,11 @@ class TestMethodAPIV2(FrappeAPITestCase): ) self.assertEqual(expanded_response.data, shorthand_response.data) + def test_logout(self): + self.post(self.method_path("logout"), {"sid": self.sid}) + response = self.get(self.method_path("ping")) + self.assertFalse(response.request.cookies["sid"]) + def test_run_doc_method_in_memory(self): dns = frappe.get_doc("Document Naming Settings")