Browse Source

[MIG] webhook: Migration to 10.0

pull/737/merge
Matthieu MÉQUIGNON 7 years ago
committed by Jairo Llopis
parent
commit
f748ae0656
  1. 2
      webhook/README.rst
  2. 3
      webhook/__manifest__.py
  3. 16
      webhook/controllers/main.py
  4. 16
      webhook/data/webhook_data.xml
  5. 16
      webhook/demo/webhook_demo.xml
  6. 8
      webhook/models/webhook.py
  7. 6
      webhook/tests/test_webhook_post.py
  8. 6
      webhook/views/webhook_views.xml

2
webhook/README.rst

@ -6,7 +6,7 @@
Webhook Webhook
======= =======
Module to receive .. _global webhooks: https://en.wikipedia.org/wiki/Webhook events.
Module to receive `webhook <https://en.wikipedia.org/wiki/Webhook>`_ events.
This module invoke methods to process webhook events. This module invoke methods to process webhook events.

3
webhook/__openerp__.py → webhook/__manifest__.py

@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
'name': 'Webhook', 'name': 'Webhook',
'version': '8.0.1.0.0',
'version': '10.0.1.0.0',
'author': 'Vauxoo, Odoo Community Association (OCA)', 'author': 'Vauxoo, Odoo Community Association (OCA)',
'category': 'Server Tools', 'category': 'Server Tools',
'website': 'https://www.vauxoo.com', 'website': 'https://www.vauxoo.com',
@ -20,7 +20,6 @@
'data': [ 'data': [
'security/ir.model.access.csv', 'security/ir.model.access.csv',
'views/webhook_views.xml', 'views/webhook_views.xml',
'data/webhook_data.xml',
], ],
'demo': [ 'demo': [
'demo/webhook_demo.xml', 'demo/webhook_demo.xml',

16
webhook/controllers/main.py

@ -4,10 +4,10 @@
import pprint import pprint
from openerp.addons.web import http
from openerp.http import request
from openerp import SUPERUSER_ID, exceptions
from openerp.tools.translate import _
from odoo import http
from odoo.http import request
from odoo import exceptions
from odoo.tools.translate import _
class WebhookController(http.Controller): class WebhookController(http.Controller):
@ -25,15 +25,11 @@ class WebhookController(http.Controller):
# Deprecated by webhook_name dynamic name # Deprecated by webhook_name dynamic name
# webhook = webhook_registry.search_with_request( # webhook = webhook_registry.search_with_request(
# cr, SUPERUSER_ID, request, context=context) # cr, SUPERUSER_ID, request, context=context)
webhook = request.env['webhook'].with_env(
request.env(user=SUPERUSER_ID)).search(
webhook = request.env['webhook'].sudo().search(
[('name', '=', webhook_name)], limit=1) [('name', '=', webhook_name)], limit=1)
# TODO: Add security by secret string or/and ip consumer # TODO: Add security by secret string or/and ip consumer
if not webhook: if not webhook:
remote_addr = ''
if hasattr(request, 'httprequest'):
if hasattr(request.httprequest, 'remote_addr'):
remote_addr = request.httprequest.remote_addr
remote_addr = getattr(request.httprequest, 'remote_addr', None)
raise exceptions.ValidationError(_( raise exceptions.ValidationError(_(
'webhook consumer [%s] from remote address [%s] ' 'webhook consumer [%s] from remote address [%s] '
'not found jsonrequest [%s]' % ( 'not found jsonrequest [%s]' % (

16
webhook/data/webhook_data.xml

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<!--webhook github data-->
<record model="webhook" id="webhook_github">
<field name="name">github</field>
<field name="python_code_get_event">request.httprequest.headers.get('X-Github-Event')</field>
</record>
<record model="webhook.address" id="webhook_address_github">
<field name="name">192.30.252.0/22</field>
<field name="webhook_id" ref="webhook_github"/>
</record>
</data>
</openerp>

16
webhook/demo/webhook_demo.xml

@ -1,6 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?> <?xml version='1.0' encoding='UTF-8'?>
<openerp>
<data noupdate="1">
<odoo noupdate="1">
<record id="webhook_test" model="webhook"> <record id="webhook_test" model="webhook">
<field name="name">wehook_test</field> <field name="name">wehook_test</field>
@ -13,5 +12,14 @@
<field name="webhook_id" ref="webhook_test"/> <field name="webhook_id" ref="webhook_test"/>
</record> </record>
</data>
</openerp>
<!--webhook github data-->
<record model="webhook" id="webhook_github">
<field name="name">github</field>
<field name="python_code_get_event">request.httprequest.headers.get('X-Github-Event')</field>
</record>
<record model="webhook.address" id="webhook_address_github">
<field name="name">192.30.252.0/22</field>
<field name="webhook_id" ref="webhook_github"/>
</record>
</odoo>

8
webhook/models/webhook.py

@ -5,9 +5,9 @@
import logging import logging
import traceback import traceback
from openerp import api, exceptions, fields, models, tools
from openerp.tools.safe_eval import safe_eval
from openerp.tools.translate import _
from odoo import api, exceptions, fields, models, tools
from odoo.tools.safe_eval import safe_eval
from odoo.tools.translate import _
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -111,7 +111,7 @@ class Webhook(models.Model):
:return: object of webhook found or :return: object of webhook found or
if not found then return False if not found then return False
""" """
for webhook in self.search([('active', '=', True)]):
for webhook in self.search([]):
remote_address = webhook.process_python_code( remote_address = webhook.process_python_code(
webhook.python_code_get_ip, request) webhook.python_code_get_ip, request)
if not remote_address: if not remote_address:

6
webhook/tests/test_webhook_post.py

@ -5,9 +5,9 @@
import json import json
import requests import requests
from openerp.tests.common import HttpCase
from openerp import api, exceptions, tools, models
from openerp.tools.translate import _
from odoo.tests.common import HttpCase
from odoo import api, exceptions, tools, models
from odoo.tools.translate import _
HOST = '127.0.0.1' HOST = '127.0.0.1'

6
webhook/views/webhook_views.xml

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<odoo>
<record id="view_webhook_form" model="ir.ui.view"> <record id="view_webhook_form" model="ir.ui.view">
<field name="name">view.webhook.form</field> <field name="name">view.webhook.form</field>
@ -40,5 +39,4 @@
</record> </record>
<menuitem id="webhook_menu_action" name="Webhook" parent="base.menu_automation" action="action_webhook"/> <menuitem id="webhook_menu_action" name="Webhook" parent="base.menu_automation" action="action_webhook"/>
</data>
</openerp>
</odoo>
Loading…
Cancel
Save