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.

40 lines
1.5 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Vauxoo - https://www.vauxoo.com/
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. import pprint
  5. from odoo import http
  6. from odoo.http import request
  7. from odoo import exceptions
  8. from odoo.tools.translate import _
  9. class WebhookController(http.Controller):
  10. @http.route(['/webhook/<webhook_name>'], type='json',
  11. auth='none', method=['POST'])
  12. def webhook(self, webhook_name, **post):
  13. '''
  14. :params string webhook_name: Name of webhook to use
  15. Webhook odoo controller to receive json request and send to
  16. driver method.
  17. You will need create your webhook with http://0.0.0.0:0000/webhook
  18. NOTE: Important use --db-filter params in odoo start.
  19. '''
  20. # Deprecated by webhook_name dynamic name
  21. # webhook = webhook_registry.search_with_request(
  22. # cr, SUPERUSER_ID, request, context=context)
  23. webhook = request.env['webhook'].sudo().search(
  24. [('name', '=', webhook_name)], limit=1)
  25. # TODO: Add security by secret string or/and ip consumer
  26. if not webhook:
  27. remote_addr = getattr(request.httprequest, 'remote_addr', None)
  28. raise exceptions.ValidationError(_(
  29. 'webhook consumer [%s] from remote address [%s] '
  30. 'not found jsonrequest [%s]' % (
  31. webhook_name,
  32. remote_addr,
  33. pprint.pformat(request.jsonrequest)[:450]
  34. )))
  35. webhook.run_webhook(request)