You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.6 KiB

  1. # Copyright 2020 Coop IT Easy SCRL fs
  2. # Robin Keunen <robin@coopiteasy.be>
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. import re
  5. from odoo import http
  6. from odoo.http import route
  7. from odoo.addons.base_rest.controllers import main
  8. def patch_for_json(path_re):
  9. # this is to avoid Odoo, which assumes json always means json+rpc,
  10. # complaining about "function declared as capable of handling request
  11. # of type 'http' but called with a request of type 'json'"
  12. # cf rest-framework/graphql_base/controllers/main.py
  13. path_re = re.compile(path_re)
  14. orig_get_request = http.Root.get_request
  15. def get_request(self, httprequest):
  16. if path_re.match(httprequest.path):
  17. return http.HttpRequest(httprequest)
  18. return orig_get_request(self, httprequest)
  19. http.Root.get_request = get_request
  20. class UserController(main.RestController):
  21. _root_path = "/api/"
  22. _collection_name = "emc.services"
  23. _default_auth = "api_key"
  24. @route(
  25. _root_path + "<string:_service_name>/test",
  26. methods=["GET"],
  27. auth="public",
  28. csrf=False,
  29. )
  30. def test(self, _service_name):
  31. return self._process_method(
  32. _service_name, "test", _id=None, params=None
  33. )
  34. @route(
  35. _root_path + "<string:_service_name>/<int:_id>/validate",
  36. methods=["POST"],
  37. csrf=False,
  38. )
  39. def validate(self, _service_name, _id, **params):
  40. return self._process_method(
  41. _service_name, "validate", _id=_id, params=params
  42. )
  43. patch_for_json("^/api/subscription-request/[0-9]*/validate$")