Skip to content

Commit

Permalink
[MIG] webhook: Migration to 10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mmequignon authored and yajo committed Sep 1, 2017
1 parent c3436ec commit f748ae0
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 45 deletions.
2 changes: 1 addition & 1 deletion webhook/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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.


Expand Down
3 changes: 1 addition & 2 deletions webhook/__openerp__.py → webhook/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Webhook',
'version': '8.0.1.0.0',
'version': '10.0.1.0.0',
'author': 'Vauxoo, Odoo Community Association (OCA)',
'category': 'Server Tools',
'website': 'https://www.vauxoo.com',
Expand All @@ -20,7 +20,6 @@
'data': [
'security/ir.model.access.csv',
'views/webhook_views.xml',
'data/webhook_data.xml',
],
'demo': [
'demo/webhook_demo.xml',
Expand Down
18 changes: 7 additions & 11 deletions webhook/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

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):
Expand All @@ -25,15 +25,11 @@ def webhook(self, webhook_name, **post):
# Deprecated by webhook_name dynamic name
# webhook = webhook_registry.search_with_request(
# cr, SUPERUSER_ID, request, context=context)
webhook = request.env['webhook'].with_env(
request.env(user=SUPERUSER_ID)).search(
[('name', '=', webhook_name)], limit=1)
webhook = request.env['webhook'].sudo().search(
[('name', '=', webhook_name)], limit=1)
# TODO: Add security by secret string or/and ip consumer
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(_(
'webhook consumer [%s] from remote address [%s] '
'not found jsonrequest [%s]' % (
Expand Down
16 changes: 0 additions & 16 deletions webhook/data/webhook_data.xml

This file was deleted.

16 changes: 12 additions & 4 deletions webhook/demo/webhook_demo.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<openerp>
<data noupdate="1">
<odoo noupdate="1">

<record id="webhook_test" model="webhook">
<field name="name">wehook_test</field>
Expand All @@ -13,5 +12,14 @@
<field name="webhook_id" ref="webhook_test"/>
</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 changes: 4 additions & 4 deletions webhook/models/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import logging
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__)

Expand Down Expand Up @@ -111,7 +111,7 @@ def search_with_request(self, request):
:return: object of webhook found or
if not found then return False
"""
for webhook in self.search([('active', '=', True)]):
for webhook in self.search([]):
remote_address = webhook.process_python_code(
webhook.python_code_get_ip, request)
if not remote_address:
Expand Down
6 changes: 3 additions & 3 deletions webhook/tests/test_webhook_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import json
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'
Expand Down
6 changes: 2 additions & 4 deletions webhook/views/webhook_views.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<odoo>

<record id="view_webhook_form" model="ir.ui.view">
<field name="name">view.webhook.form</field>
Expand Down Expand Up @@ -40,5 +39,4 @@
</record>
<menuitem id="webhook_menu_action" name="Webhook" parent="base.menu_automation" action="action_webhook"/>

</data>
</openerp>
</odoo>

0 comments on commit f748ae0

Please sign in to comment.