Skip to content

Commit 30dbcf6

Browse files
authored
Merge branch '14.0' into 14.0-base-rest-pydantic-lmi
2 parents 0af96bb + 1f67797 commit 30dbcf6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1334
-238
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
exclude: |
22
(?x)
33
# NOT INSTALLABLE ADDONS
4-
^graphql_base/|
5-
^graphql_demo/|
64
# END NOT INSTALLABLE ADDONS
75
# Files and folders generated by bots, to avoid loops
86
^setup/|/static/description/index\.html$|

README.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,18 @@ Available addons
1919
----------------
2020
addon | version | maintainers | summary
2121
--- | --- | --- | ---
22-
[base_rest](base_rest/) | 14.0.4.3.1 | [![lmignon](https://github.com/lmignon.png?size=30px)](https://github.com/lmignon) | Develop your own high level REST APIs for Odoo thanks to this addon.
22+
[base_rest](base_rest/) | 14.0.4.5.1 | [![lmignon](https://github.com/lmignon.png?size=30px)](https://github.com/lmignon) | Develop your own high level REST APIs for Odoo thanks to this addon.
2323
[base_rest_auth_api_key](base_rest_auth_api_key/) | 14.0.1.0.2 | [![lmignon](https://github.com/lmignon.png?size=30px)](https://github.com/lmignon) | Base Rest: Add support for the auth_api_key security policy into the openapi documentation
2424
[base_rest_auth_jwt](base_rest_auth_jwt/) | 14.0.1.1.0 | [![lmignon](https://github.com/lmignon.png?size=30px)](https://github.com/lmignon) | Base Rest: Add support for the auth_jwt security policy into the openapi documentation
25-
[base_rest_auth_user_service](base_rest_auth_user_service/) | 14.0.1.0.1 | | Login/logout from session using a REST call
25+
[base_rest_auth_user_service](base_rest_auth_user_service/) | 14.0.1.1.0 | | Login/logout from session using a REST call
2626
[base_rest_datamodel](base_rest_datamodel/) | 14.0.4.1.0 | | Datamodel binding for base_rest
2727
[base_rest_demo](base_rest_demo/) | 14.0.4.1.0 | [![lmignon](https://github.com/lmignon.png?size=30px)](https://github.com/lmignon) | Demo addon for Base REST
28-
[datamodel](datamodel/) | 14.0.3.0.4 | [![lmignon](https://github.com/lmignon.png?size=30px)](https://github.com/lmignon) | This addon allows you to define simple data models supporting serialization/deserialization
28+
[datamodel](datamodel/) | 14.0.3.0.5 | [![lmignon](https://github.com/lmignon.png?size=30px)](https://github.com/lmignon) | This addon allows you to define simple data models supporting serialization/deserialization
29+
[extendable](extendable/) | 14.0.1.0.0 | [![lmignon](https://github.com/lmignon.png?size=30px)](https://github.com/lmignon) | Extendable classes registry loader for Odoo
30+
[graphql_base](graphql_base/) | 14.0.1.0.0 | [![sbidoul](https://github.com/sbidoul.png?size=30px)](https://github.com/sbidoul) | Base GraphQL/GraphiQL controller
31+
[graphql_demo](graphql_demo/) | 14.0.1.0.0 | [![sbidoul](https://github.com/sbidoul.png?size=30px)](https://github.com/sbidoul) | GraphQL Demo
2932
[model_serializer](model_serializer/) | 14.0.1.0.0 | | Automatically translate Odoo models into Datamodels for (de)serialization
30-
[rest_log](rest_log/) | 14.0.1.0.2 | [![simahawk](https://github.com/simahawk.png?size=30px)](https://github.com/simahawk) | Track REST API calls into DB
31-
32-
33-
Unported addons
34-
---------------
35-
addon | version | maintainers | summary
36-
--- | --- | --- | ---
37-
[graphql_base](graphql_base/) | 13.0.1.0.0 (unported) | [![sbidoul](https://github.com/sbidoul.png?size=30px)](https://github.com/sbidoul) | Base GraphQL/GraphiQL controller
38-
[graphql_demo](graphql_demo/) | 13.0.1.0.0 (unported) | [![sbidoul](https://github.com/sbidoul.png?size=30px)](https://github.com/sbidoul) | GraphQL Demo
33+
[rest_log](rest_log/) | 14.0.1.1.2 | [![simahawk](https://github.com/simahawk.png?size=30px)](https://github.com/simahawk) | Track REST API calls into DB
3934

4035
[//]: # (end addons)
4136

base_rest/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"summary": """
77
Develop your own high level REST APIs for Odoo thanks to this addon.
88
""",
9-
"version": "14.0.4.3.1",
9+
"version": "14.0.4.5.1",
1010
"development_status": "Beta",
1111
"license": "LGPL-3",
1212
"author": "ACSONE SA/NV, " "Odoo Community Association (OCA)",

base_rest/apispec/base_rest_service_apispec.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ def __init__(self, service_component, **params):
2929
)
3030
},
3131
servers=self._get_servers(),
32-
plugins=[
33-
RestApiMethodRoutePlugin(self._service),
34-
RestMethodParamPlugin(self._service),
35-
RestMethodSecurityPlugin(self._service),
36-
],
32+
plugins=self._get_plugins(),
3733
)
3834
self._params = params
3935

@@ -57,6 +53,13 @@ def _get_servers(self):
5753
}
5854
]
5955

56+
def _get_plugins(self):
57+
return [
58+
RestApiMethodRoutePlugin(self._service),
59+
RestMethodParamPlugin(self._service),
60+
RestMethodSecurityPlugin(self._service),
61+
]
62+
6063
def _add_method_path(self, method):
6164
description = textwrap.dedent(method.__doc__ or "")
6265
routing = method.routing

base_rest/apispec/rest_method_security_plugin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ class RestMethodSecurityPlugin(BasePlugin):
99
APISpec plugin to generate path security from a services method
1010
"""
1111

12-
def __init__(self, service):
12+
def __init__(self, service, user_auths=("user",)):
1313
super(RestMethodSecurityPlugin, self).__init__()
1414
self._service = service
15+
self._supported_user_auths = user_auths
1516

1617
def init_spec(self, spec):
1718
super(RestMethodSecurityPlugin, self).init_spec(spec)
@@ -29,7 +30,7 @@ def operation_helper(self, path=None, operations=None, **kwargs):
2930
if not operations:
3031
return
3132
auth = routing.get("auth", self.spec._params.get("default_auth"))
32-
if auth == "user":
33+
if auth in self._supported_user_auths:
3334
for _method, params in operations.items():
3435
security = params.setdefault("security", [])
3536
security.append({"user": []})

base_rest/controllers/api_docs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ def make_json_response(self, data, headers=None, cookies=None):
2929
def index(self, **params):
3030
self._get_api_urls()
3131
primary_name = params.get("urls.primaryName")
32-
values = {"api_urls": self._get_api_urls(), "primary_name": primary_name}
32+
swagger_settings = {
33+
"urls": self._get_api_urls(),
34+
"urls.primaryName": primary_name,
35+
}
36+
values = {"swagger_settings": swagger_settings}
3337
return request.render("base_rest.openapi", values)
3438

3539
@route("/api-docs/<path:collection>/<string:service_name>.json", auth="public")
@@ -107,7 +111,3 @@ def work_on_component(self, collection_name):
107111
def _get_services_specs(self, path):
108112
services_registry = _rest_services_databases.get(request.env.cr.dbname, {})
109113
return services_registry["/" + path + "/"]
110-
111-
def _get_collection_name(self, name):
112-
services_registry = _rest_services_databases.get(request.env.cr.dbname, {})
113-
return services_registry["/" + name + "/"]["collection_name"]

base_rest/controllers/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717

1818

1919
class _PseudoCollection(object):
20-
__slots__ = "_name", "env"
20+
__slots__ = "_name", "env", "id"
2121

2222
def __init__(self, name, env):
2323
self._name = name
2424
self.env = env
25+
self.id = None
2526

2627

2728
class RestControllerType(ControllerType):

base_rest/static/src/js/swagger_ui.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@ odoo.define("base_rest.swagger_ui", function (require) {
55
var core = require("web.core");
66

77
var SwaggerUI = core.Class.extend({
8-
init: function (api_urls, primary_name) {
9-
this.api_urls = api_urls;
10-
this.primary_name = primary_name;
8+
init: function (selector) {
9+
this.selector = selector;
10+
this.$el = $(this.selector);
1111
},
12-
13-
start: function (dom_id) {
14-
this.ui = SwaggerUIBundle({
15-
urls: this.api_urls,
16-
dom_id: dom_id,
12+
_swagger_bundle_settings: function () {
13+
const defaults = {
14+
dom_id: this.selector,
1715
deepLinking: true,
1816
presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset],
1917
plugins: [SwaggerUIBundle.plugins.DownloadUrl],
2018
layout: "StandaloneLayout",
21-
"urls.primaryName": this.primary_name,
2219
operationsSorter: function (a, b) {
2320
var methodsOrder = [
2421
"get",
@@ -46,7 +43,12 @@ odoo.define("base_rest.swagger_ui", function (require) {
4643
$(".topbar").prepend(this.web_btn);
4744
}
4845
},
49-
});
46+
};
47+
const config = this.$el.data("settings");
48+
return Object.assign({}, defaults, config);
49+
},
50+
start: function () {
51+
this.ui = SwaggerUIBundle(this._swagger_bundle_settings());
5052
},
5153
});
5254

base_rest/tests/common.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,19 @@ def _setup_registry(class_or_instance):
105105
# registered outside tests
106106
class_or_instance._collection_name = "base.rest.test"
107107

108+
BaseTestController = class_or_instance._get_test_controller(class_or_instance)
109+
110+
class_or_instance._BaseTestController = BaseTestController
111+
class_or_instance._controller_route_method_names = {
112+
"my_controller_route_without",
113+
"my_controller_route_with",
114+
"my_controller_route_without_auth_2",
115+
}
116+
117+
@staticmethod
118+
def _get_test_controller(class_or_instance, root_path="/test_controller/"):
108119
class BaseTestController(RestController):
109-
_root_path = "/test_controller/"
120+
_root_path = root_path
110121
_collection_name = class_or_instance._collection_name
111122
_default_auth = "public"
112123

@@ -128,12 +139,7 @@ def my_controller_route_with(self):
128139
def my_controller_route_without_auth_2(self):
129140
return {}
130141

131-
class_or_instance._BaseTestController = BaseTestController
132-
class_or_instance._controller_route_method_names = {
133-
"my_controller_route_without",
134-
"my_controller_route_with",
135-
"my_controller_route_without_auth_2",
136-
}
142+
return BaseTestController
137143

138144
@staticmethod
139145
def _teardown_registry(class_or_instance):

base_rest/views/openapi_template.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,14 @@
4444
</t>
4545

4646
<body>
47-
<div id="swagger-ui" />
47+
<div id="swagger-ui" t-att-data-settings='json.dumps(swagger_settings)' />
4848

4949
<script>
5050
odoo.define('base_rest.swagger', function (require) {
5151
var SwaggerUi = require('base_rest.swagger_ui');
52-
var swagger_ui = new SwaggerUi(<t t-esc="api_urls" />, '<t
53-
t-esc="primary_name"
54-
/>');
52+
var swagger_ui = new SwaggerUi('#swagger-ui');
5553
$(function() {
56-
swagger_ui.start('#swagger-ui');
54+
swagger_ui.start();
5755
});
5856
return swagger_ui;
5957
});

0 commit comments

Comments
 (0)