Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
b834070
Add endpoint_route_handler
simahawk Oct 25, 2021
73ab61c
endpoint_route_handler: reduce log noise
simahawk Nov 18, 2021
e63272a
endpoint_route_handler 14.0.1.0.1
OCA-git-bot Nov 18, 2021
b91e123
endpoint_route_handler: fix archive/unarchive
simahawk Dec 28, 2021
54abfc9
endpoint_route_handler: fix multi env handling
simahawk Dec 29, 2021
2cb48f8
endpoint_route_handler 14.0.1.0.2
OCA-git-bot Jan 12, 2022
072b7e6
Misc fix of authorship name
simahawk Jan 14, 2022
0679960
endpoint_route_handler 14.0.1.0.3
OCA-git-bot Jan 14, 2022
257c98a
endpoint_route_handler: fix rules by group
simahawk Jan 19, 2022
583310e
endpoint_route_handler 14.0.1.0.4
OCA-git-bot Jan 19, 2022
97792d6
endpoint_route_handler: dev status = Beta
simahawk Apr 4, 2022
a2e2228
endpoint_route_handler 14.0.1.1.0
OCA-git-bot Apr 4, 2022
287f6b2
endpoint_route_handler: move to OCA/web-api
simahawk Jun 15, 2022
3f9b060
[UPD] README.rst
OCA-git-bot Jul 15, 2022
b3db4bf
[UPD] Update endpoint_route_handler.pot
Jul 15, 2022
b0d5922
[UPD] Update endpoint_route_handler.pot
Jul 15, 2022
73c516a
endpoint_route_handler: fix cross worker lookup
simahawk Jun 15, 2022
7fada27
endpoint_route_handler: add flag to control sync
simahawk Jul 25, 2022
eb7482b
endpoint_route_handler: add constraints
simahawk Jul 27, 2022
8e64d15
endpoint_route_handler: add auto timestamp to routes
simahawk Nov 1, 2022
d780029
endpoint_route_handler: fix typo in validator
simahawk Jul 25, 2022
86c1b6a
endpoint_route_handler: add new tool model
simahawk Feb 16, 2023
7827769
endpoint_route_handler: use sequence as version
simahawk Mar 1, 2023
f9c71de
endpoint_route_handler: log table setup and wipe
simahawk Mar 8, 2023
a2d28ec
endpoint_route_handler: fail gracefully when sync field not ready
simahawk Mar 8, 2023
f8e1b8c
endpoint_route_handler: get rid of register_hook
simahawk Mar 27, 2023
0ba76e1
endpoint_route_handler: fix auto_not_found param
simahawk Apr 21, 2023
9401423
endpoint_route_handler: 14.0.2.0.0
simahawk May 11, 2023
7cdb056
[UPD] Update endpoint_route_handler.pot
May 11, 2023
2b2ca16
[UPD] README.rst
OCA-git-bot May 11, 2023
31e5c86
endpoint_route_handler: update ROADMAP
simahawk May 12, 2023
eadcc5c
[UPD] README.rst
OCA-git-bot May 12, 2023
121d4de
endpoint_route_handler 14.0.2.0.1
OCA-git-bot May 12, 2023
44bfbc7
[UPD] README.rst
OCA-git-bot Sep 3, 2023
f40da31
Added translation using Weblate (Italian)
mymage Feb 29, 2024
b55c972
[FIX] endpoint_route_handler: Use dedicated cursor for registry
grindtildeath Mar 4, 2024
ca32a78
[BOT] post-merge updates
OCA-git-bot Jul 4, 2024
7eeaa87
[IMP] endpoint_route_handler: add request_content_type application_js…
OriolMForgeFlow Jul 17, 2023
3d62564
[BOT] post-merge updates
OCA-git-bot Jul 8, 2024
d4949db
[IMP]endpoint_route_handler: black, isort, prettier
GuillemCForgeFlow Nov 7, 2024
604236d
[BKP][ADD]endpoint_route_handler
GuillemCForgeFlow Oct 29, 2024
bb4b98b
[IMP] endpoint_route_handler: pre-commit stuff
JordiMForgeFlow Nov 22, 2024
9f8fd39
[MIG] endpoint_route_handler: Migration to V12
JordiMForgeFlow Nov 22, 2024
5fd4287
Add endpoint module
simahawk Sep 13, 2021
8fbaee2
endpoint: add cross model constraint
simahawk Oct 14, 2021
735995d
endpoint: split out route handling
simahawk Oct 25, 2021
36534ae
[FIX] endpoint: fix loading of demo data
sebalix Nov 9, 2021
0aa3bb9
endpoint 14.0.1.0.1
OCA-git-bot Nov 9, 2021
8477dcf
endpoint: add tests for archive/unarchive
simahawk Dec 28, 2021
156cc64
endpoint: update tests
simahawk Dec 29, 2021
0a28f12
endpoint: improve search/tree views
simahawk Nov 12, 2021
4f8f1a5
endpoint 14.0.1.0.2
OCA-git-bot Jan 12, 2022
b4dd568
endpoint 14.0.1.1.0
OCA-git-bot Jan 12, 2022
bec80ec
Misc fix of authorship name
simahawk Jan 14, 2022
df2da5b
endpoint 14.0.1.1.1
OCA-git-bot Jan 14, 2022
0d4f2be
endpoint: block all RPC calls
simahawk Feb 18, 2022
6198822
endpoint 14.0.1.3.0
OCA-git-bot Mar 11, 2022
e114e17
endpoint: move to web-api
simahawk Jun 15, 2022
9b704e4
[UPD] Update endpoint.pot
Jul 15, 2022
1b3fbf0
[UPD] README.rst
OCA-git-bot Jul 15, 2022
aa88668
Added translation using Weblate (French)
klodr Sep 15, 2022
7877a66
endpoint: adapt to endpoint_route_handler
simahawk Jun 15, 2022
010de38
endpoint: use registry_sync flag and improve tests
simahawk Jul 25, 2022
1057dbf
endpoint: adapt to new sync behavior
simahawk Jul 26, 2022
ece03df
endpoint_route_handler: use sequence as version
simahawk Mar 1, 2023
ec5822c
endpoint: use model explicitly to find endpoints
simahawk Apr 21, 2023
4113243
endpoint: 14.0.2.0.0
simahawk May 11, 2023
88b6245
[UPD] Update endpoint.pot
May 11, 2023
620b9a4
[UPD] README.rst
OCA-git-bot May 11, 2023
00fbf6b
Update translation files
weblate May 11, 2023
25feab9
endpoint: update ROADMAP
simahawk May 12, 2023
c9d4701
[UPD] README.rst
OCA-git-bot May 12, 2023
ffc2a75
endpoint 14.0.2.0.1
OCA-git-bot May 12, 2023
4872933
endpoint: fix duplicate
simahawk May 25, 2023
b1fc363
endpoint 14.0.2.0.2
OCA-git-bot May 25, 2023
b30c7e7
[UPD] README.rst
OCA-git-bot Sep 3, 2023
135442f
Added translation using Weblate (Italian)
mymage Feb 29, 2024
3d895c6
endpoint: add log function
simahawk Jul 2, 2024
feacae2
[IMP] endpoint: endpoint multi-company
JordiMForgeFlow Jun 5, 2024
974d152
[BOT] post-merge updates
OCA-git-bot Jul 4, 2024
879b655
[UPD] Update endpoint.pot
Jul 4, 2024
d6f35ec
[BOT] post-merge updates
OCA-git-bot Jul 4, 2024
1f3dccc
Update translation files
weblate Jul 4, 2024
de17fc9
endpoint: add basic mixin view
simahawk Jul 23, 2024
5e7bfb7
[UPD] Update endpoint.pot
Jul 25, 2024
ed361b6
[BOT] post-merge updates
OCA-git-bot Jul 25, 2024
c056356
Update translation files
weblate Jul 25, 2024
97f7421
[IMP]endpoint: black, isort, prettier
GuillemCForgeFlow Nov 7, 2024
dbe2851
[BKP][ADD]endpoint
GuillemCForgeFlow Oct 29, 2024
c5a0178
[IMP] endpoint: pre-commit stuff
JordiMForgeFlow Nov 22, 2024
b5964a1
[MIG] endpoint: Migration to V12
JordiMForgeFlow Nov 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions endpoint/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
========
Endpoint
========

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2da9c7b7ea950dc9d9b00ebf3d2464b02005513cfb12202d9bc8b4b329f2af70
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb--api-lightgray.png?logo=github
:target: https://github.com/OCA/web-api/tree/14.0/endpoint
:alt: OCA/web-api
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-api-14-0/web-api-14-0-endpoint
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/web-api&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Provide an endpoint framework allowing users to define their own custom endpoint.

Thanks to endpoint mixin the endpoint records are automatically registered as real Odoo routes.

You can easily code what you want in the code snippet.

NOTE: for security reasons any kind of RPC call is blocked on endpoint records.

**Table of contents**

.. contents::
:local:

Configuration
=============

Go to "Technical -> Endpoints" and create a new endpoint.

Known issues / Roadmap
======================

* add validation of request data
* add api docs generation
* handle multiple routes per endpoint

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/web-api/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web-api/issues/new?body=module:%20endpoint%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Camptocamp

Contributors
~~~~~~~~~~~~

* Simone Orsi <simone.orsi@camptocamp.com>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-simahawk| image:: https://github.com/simahawk.png?size=40px
:target: https://github.com/simahawk
:alt: simahawk

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-simahawk|

This module is part of the `OCA/web-api <https://github.com/OCA/web-api/tree/14.0/endpoint>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions endpoint/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .hooks import post_init_hook
from . import controllers
from . import models
from . import tools
21 changes: 21 additions & 0 deletions endpoint/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2021 Camptocamp SA
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "Endpoint",
"summary": """Provide custom endpoint machinery.""",
"version": "12.0.1.0.0",
"license": "LGPL-3",
"development_status": "Beta",
"author": "Camptocamp,Odoo Community Association (OCA)",
"maintainers": ["simahawk"],
"website": "https://github.com/OCA/web-api",
"depends": ["endpoint_route_handler", "rpc_helper"],
"data": [
"security/ir.model.access.csv",
"security/ir_rule.xml",
"views/endpoint_view.xml",
],
"demo": ["demo/endpoint_demo.xml"],
"post_init_hook": "post_init_hook",
}
1 change: 1 addition & 0 deletions endpoint/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
57 changes: 57 additions & 0 deletions endpoint/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2021 Camptocamp SA
# @author: Simone Orsi <simone.orsi@camptocamp.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).


import json

from werkzeug.exceptions import NotFound

from odoo import http
from odoo.http import Response, request


class EndpointControllerMixin:
def _handle_endpoint(self, env, model, endpoint_route, **params):
endpoint = self._find_endpoint(env, model, endpoint_route)
if not endpoint:
raise NotFound()
endpoint._validate_request(request)
result = endpoint._handle_request(request)
return self._handle_result(result)

def _handle_result(self, result):
response = result.get("response")
if isinstance(response, Response):
# Full response already provided
return response
payload = result.get("payload", "")
status = result.get("status_code", 200)
headers = result.get("headers", {})
return self._make_json_response(payload, headers=headers, status=status)

# TODO: probably not needed anymore as controllers are automatically registered
def _make_json_response(self, payload, headers=None, status=200, **kw):
# TODO: guess out type?
data = json.dumps(payload)
if headers is None:
headers = {}
headers["Content-Type"] = "application/json"
if request._request_type == "http":
resp = request.make_response(data, headers=headers)
else:
resp = request._json_response(data)
resp.status = str(status)
return resp

def _find_endpoint(self, env, model, endpoint_route):
return env[model]._find_endpoint(endpoint_route)

def auto_endpoint(self, model, endpoint_route, **params):
"""Default method to handle auto-generated endpoints"""
env = request.env
return self._handle_endpoint(env, model, endpoint_route, **params)


class EndpointController(http.Controller, EndpointControllerMixin):
pass
86 changes: 86 additions & 0 deletions endpoint/demo/endpoint_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">

<record id="endpoint_demo_1" model="endpoint.endpoint">
<field name="name">Demo Endpoint 1</field>
<field name="route">/demo/one</field>
<field name="request_method">GET</field>
<field name="exec_mode">code</field>
<field name="code_snippet">
result = {"response": Response("ok")}
</field>
</record>

<record id="endpoint_demo_2" model="endpoint.endpoint">
<field name="name">Demo Endpoint 2</field>
<field name="route">/demo/as_demo_user</field>
<field name="request_method">GET</field>
<field name="auth_type">public</field>
<field name="exec_as_user_id" ref="base.user_demo" />
<field name="exec_mode">code</field>
<field name="code_snippet">
result = {"response": Response("My name is: " + user.name)}
</field>
</record>

<record id="endpoint_demo_3" model="endpoint.endpoint">
<field name="name">Demo Endpoint 3</field>
<field name="route">/demo/json_data</field>
<field name="request_method">GET</field>
<field name="auth_type">public</field>
<field name="exec_as_user_id" ref="base.user_demo" />
<field name="exec_mode">code</field>
<field name="code_snippet">
result = {"payload": {"a": 1, "b": 2}}
</field>
</record>

<record id="endpoint_demo_4" model="endpoint.endpoint">
<field name="name">Demo Endpoint 4</field>
<field name="route">/demo/raise_not_found</field>
<field name="request_method">GET</field>
<field name="auth_type">public</field>
<field name="exec_as_user_id" ref="base.user_demo" />
<field name="exec_mode">code</field>
<field name="code_snippet">
raise werkzeug.exceptions.NotFound()
</field>
</record>

<record id="endpoint_demo_5" model="endpoint.endpoint">
<field name="name">Demo Endpoint 5</field>
<field name="route">/demo/raise_validation_error</field>
<field name="request_method">GET</field>
<field name="auth_type">public</field>
<field name="exec_as_user_id" ref="base.user_demo" />
<field name="exec_mode">code</field>
<field name="code_snippet">
raise exceptions.ValidationError("Sorry, you cannot do this!")
</field>
</record>

<record id="endpoint_demo_6" model="endpoint.endpoint">
<field name="name">Demo Endpoint 6</field>
<field name="route">/demo/value_from_request</field>
<field name="request_method">GET</field>
<field name="auth_type">public</field>
<field name="exec_as_user_id" ref="base.user_demo" />
<field name="exec_mode">code</field>
<field name="code_snippet">
result = {"response": Response(request.params.get("your_name", ""))}
</field>
</record>

<record id="endpoint_demo_7" model="endpoint.endpoint">
<field name="name">Demo Endpoint 7</field>
<field name="route">/demo/bad_method</field>
<field name="request_method">GET</field>
<field name="exec_mode">code</field>
<field name="auth_type">public</field>
<field name="exec_as_user_id" ref="base.user_demo" />
<field name="code_snippet">
result = {"payload": "Method used:" + request.httprequest.method}
</field>
</record>

</odoo>
70 changes: 70 additions & 0 deletions endpoint/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2021 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

import logging

from odoo import SUPERUSER_ID, api, tools

from odoo.addons.base.models.ir_model import query_insert

_logger = logging.getLogger(__file__)


def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
_init_server_action(env)


def _init_server_action(env):
"""Create server action if missing."""
# This is actually a trick to work around this error:
#
# psycopg2.IntegrityError: null value in column "activity_user_type"
# violates not-null constraint
#
# which happens when `mail` is installed,
# since it adds this field as required in DB.
#
# We DO NOT want to depend on mail for this problem...
# hence, here we go with this crazy dance :S
#
# Moreover, we are forced to use a query for this
# because if you use `model.create` you get
#
# ValueError: Invalid field 'activity_user_type' on model 'ir.actions.server'
#
# because the field is not yet in the env if the mail modules is not loaded 1st.
xid = "endpoint.server_action_registry_sync"
rec = env.ref(xid, False)
if rec:
return
model = env.ref("endpoint.model_endpoint_endpoint")
values = {
"name": "Sync registry",
"type": "ir.actions.server",
"model_id": model.id,
"model_name": model.model,
"binding_model_id": model.id,
"binding_type": "action",
"usage": "ir_actions_server",
"state": "code",
"code": """
records.filtered(lambda x: not x.registry_sync).write({"registry_sync": True})
""",
}
if tools.sql.column_exists(env.cr, "ir_act_server", "activity_user_type"):
values["activity_user_type"] = "specific"
ids = query_insert(env.cr, "ir_act_server", [values])

# Finally add an xmlid
module, id_ = xid.split(".", 1)
env["ir.model.data"].create(
{
"name": id_,
"module": module,
"model": "ir.actions.server",
"res_id": ids[0],
"noupdate": True,
}
)
_logger.info("Server action created")
Loading
Loading