From c46a53babf77ee1d212b8dc7993ed7dd25c20346 Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Wed, 3 Apr 2024 15:54:44 +0200 Subject: [PATCH] [MIG] base_external_system_oath: migration to 16.0 --- base_external_system_oauth/README.rst | 38 +++++++++++-------- base_external_system_oauth/__init__.py | 2 +- base_external_system_oauth/__manifest__.py | 13 ++++--- .../models/auth_oauth_provider.py | 19 ++++++---- .../models/external_system_adapter_oauth.py | 13 ++----- .../readme/CONTRIBUTORS.md | 1 + .../readme/CONTRIBUTORS.rst | 1 - .../readme/DESCRIPTION.md | 2 + .../readme/DESCRIPTION.rst | 2 - .../static/description/index.html | 16 ++++---- .../odoo/addons/base_external_system_oauth | 1 + setup/base_external_system_oauth/setup.py | 6 +++ 12 files changed, 66 insertions(+), 48 deletions(-) create mode 100644 base_external_system_oauth/readme/CONTRIBUTORS.md delete mode 100644 base_external_system_oauth/readme/CONTRIBUTORS.rst create mode 100644 base_external_system_oauth/readme/DESCRIPTION.md delete mode 100644 base_external_system_oauth/readme/DESCRIPTION.rst create mode 120000 setup/base_external_system_oauth/odoo/addons/base_external_system_oauth create mode 100644 setup/base_external_system_oauth/setup.py diff --git a/base_external_system_oauth/README.rst b/base_external_system_oauth/README.rst index 3f9fb2c45..b8c82f24b 100644 --- a/base_external_system_oauth/README.rst +++ b/base_external_system_oauth/README.rst @@ -7,7 +7,7 @@ Base External System - oauth systems !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:b7bcb98052072b585356539a42b3f52c0a030e9a943f1cb3ea63866911106c7e + !! source digest: sha256:77d7250a4605033a74e2d37e252c7ed0fe7f4b957ddabafc8437b671c4a9563b !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -16,20 +16,20 @@ Base External System - oauth systems .. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 -.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github - :target: https://github.com/OCA/server-tools/tree/16.0/base_external_system_oauth - :alt: OCA/server-tools +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--backend-lightgray.png?logo=github + :target: https://github.com/OCA/server-backend/tree/16.0/base_external_system_oauth + :alt: OCA/server-backend .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-base_external_system_oauth + :target: https://translation.odoo-community.org/projects/server-backend-16-0/server-backend-16-0-base_external_system_oauth :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/server-tools&target_branch=16.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/server-backend&target_branch=16.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| -This module adds the oauth authentication method to connect -to remote systems. +This module adds the oauth authentication method to connect to remote +systems. **Table of contents** @@ -39,10 +39,10 @@ to remote systems. Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. +Bugs are tracked on `GitHub 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -50,17 +50,17 @@ Credits ======= Authors -~~~~~~~ +------- * Therp BV Contributors -~~~~~~~~~~~~ +------------ -* Ronald Portier +- Ronald Portier Maintainers -~~~~~~~~~~~ +----------- This module is maintained by the OCA. @@ -72,6 +72,14 @@ 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. -This module is part of the `OCA/server-tools `_ project on GitHub. +.. |maintainer-NL66278| image:: https://github.com/NL66278.png?size=40px + :target: https://github.com/NL66278 + :alt: NL66278 + +Current `maintainer `__: + +|maintainer-NL66278| + +This module is part of the `OCA/server-backend `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_external_system_oauth/__init__.py b/base_external_system_oauth/__init__.py index 75d792451..83e553ac4 100644 --- a/base_external_system_oauth/__init__.py +++ b/base_external_system_oauth/__init__.py @@ -1,3 +1,3 @@ -# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models diff --git a/base_external_system_oauth/__manifest__.py b/base_external_system_oauth/__manifest__.py index ff35aa1c4..94461d84f 100644 --- a/base_external_system_oauth/__manifest__.py +++ b/base_external_system_oauth/__manifest__.py @@ -1,16 +1,15 @@ -# Copyright 2023 Therp BV . +# Copyright 2023-2024 Therp BV . # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Base External System - oauth systems", - "summary": "Connect to external systems trough oauth authentication.", - "version": "10.0.1.0.0", + "summary": "Connect to external systems through oauth authentication.", + "version": "16.0.1.0.0", "category": "Base", - "website": "https://github.com/OCA/server-tools", + "website": "https://github.com/OCA/server-backend", "author": "Therp BV, Odoo Community Association (OCA)", + "maintainers": ["NL66278"], "license": "AGPL-3", - "application": False, - "installable": True, "depends": [ "auth_oauth", "base_external_system_http", @@ -19,4 +18,6 @@ "views/external_system.xml", "views/auth_oauth_provider.xml", ], + "application": False, + "installable": True, } diff --git a/base_external_system_oauth/models/auth_oauth_provider.py b/base_external_system_oauth/models/auth_oauth_provider.py index 09749257a..8dad755aa 100644 --- a/base_external_system_oauth/models/auth_oauth_provider.py +++ b/base_external_system_oauth/models/auth_oauth_provider.py @@ -7,7 +7,7 @@ import requests from requests.auth import HTTPBasicAuth -from odoo import fields, models +from odoo import _, fields, models from odoo.exceptions import UserError _logger = logging.getLogger(__name__) # pylint: disable=invalid-name @@ -46,7 +46,7 @@ def _get_access_token_basic(self): } basic = HTTPBasicAuth(self.client_id, self.client_secret) response = requests.post( - url=self.auth_endpoint, params=login_params, auth=basic + url=self.auth_endpoint, params=login_params, auth=basic, timeout=16 ) self._check_response(response) return response.json()["access_token"] @@ -68,7 +68,7 @@ def _get_access_token_microsoft_client_secret(self): } login_headers = {"Content-Type": "application/x-www-form-urlencoded"} response = requests.post( - url=login_url, headers=login_headers, data=login_params + url=login_url, headers=login_headers, data=login_params, timeout=16 ) self._check_response(response) return response.json()["access_token"] @@ -77,10 +77,15 @@ def _check_response(self, response): """Check response from oauth provider.""" if response.status_code != 200: raise UserError( - "Error at login to OAuth provider:\n" - "Status_code: %(status_code)s\n" - "Response: %(response)s" - % {"status_code": response.status_code, "response": response.content} + _( + "Error at login to OAuth provider:\n" + "Status_code: %(status_code)s\n" + "Response: %(response)s" + ) + % { + "status_code": response.status_code, + "response": response.content, + } ) _logger.debug( "Oauth status_code %s, response content %s", diff --git a/base_external_system_oauth/models/external_system_adapter_oauth.py b/base_external_system_oauth/models/external_system_adapter_oauth.py index 26e46feac..14888250e 100644 --- a/base_external_system_oauth/models/external_system_adapter_oauth.py +++ b/base_external_system_oauth/models/external_system_adapter_oauth.py @@ -4,7 +4,7 @@ """Extend external system with oauth authentication.""" import logging -from odoo import _, api, models +from odoo import _, models from odoo.exceptions import UserError # You must initialize logging, otherwise you'll not see debug output. @@ -44,15 +44,13 @@ class ExternalSystemAdapterOAuth(models.AbstractModel): token = None - @api.multi def external_get_client(self): """Return token that can be used to access remote system.""" - client = super(ExternalSystemAdapterOAuth, self).external_get_client() + client = super().external_get_client() oauth = self.system_id.oauth_definition_id self.token = oauth.get_access_token() return client - @api.multi def external_destroy_client(self, client): """Perform any logic necessary to destroy the client connection. @@ -62,22 +60,19 @@ def external_destroy_client(self, client): """ if self.token: self.token = None - super(ExternalSystemAdapterOAuth, self).external_destroy_client(client) def post(self, endpoint=None, data=None, json=None, **kwargs): """Send post request.""" headers = kwargs.pop("headers", {}) self._set_oauth_headers(headers) - return super(ExternalSystemAdapterOAuth, self).post( + return super().post( endpoint=endpoint, data=data, json=json, headers=headers, **kwargs ) def get_json(self, endpoint=None, params=None, **kwargs): """Get json formatted data from remote system.""" self._set_oauth_headers(**kwargs) - return super(ExternalSystemAdapterOAuth, self).get( - endpoint=endpoint, params=params, **kwargs - ) + return super().get(endpoint=endpoint, params=params, **kwargs) def _set_oauth_headers(self, headers): """Set headers in keyword arguments.""" diff --git a/base_external_system_oauth/readme/CONTRIBUTORS.md b/base_external_system_oauth/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..c2a6ea2eb --- /dev/null +++ b/base_external_system_oauth/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Ronald Portier \<\> diff --git a/base_external_system_oauth/readme/CONTRIBUTORS.rst b/base_external_system_oauth/readme/CONTRIBUTORS.rst deleted file mode 100644 index 4e07c28e1..000000000 --- a/base_external_system_oauth/readme/CONTRIBUTORS.rst +++ /dev/null @@ -1 +0,0 @@ -* Ronald Portier diff --git a/base_external_system_oauth/readme/DESCRIPTION.md b/base_external_system_oauth/readme/DESCRIPTION.md new file mode 100644 index 000000000..2d8127886 --- /dev/null +++ b/base_external_system_oauth/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module adds the oauth authentication method to connect to remote +systems. diff --git a/base_external_system_oauth/readme/DESCRIPTION.rst b/base_external_system_oauth/readme/DESCRIPTION.rst deleted file mode 100644 index 16723bd3a..000000000 --- a/base_external_system_oauth/readme/DESCRIPTION.rst +++ /dev/null @@ -1,2 +0,0 @@ -This module adds the oauth authentication method to connect -to remote systems. diff --git a/base_external_system_oauth/static/description/index.html b/base_external_system_oauth/static/description/index.html index a687debd9..cf9338d6e 100644 --- a/base_external_system_oauth/static/description/index.html +++ b/base_external_system_oauth/static/description/index.html @@ -367,11 +367,11 @@

Base External System - oauth systems

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:b7bcb98052072b585356539a42b3f52c0a030e9a943f1cb3ea63866911106c7e +!! source digest: sha256:77d7250a4605033a74e2d37e252c7ed0fe7f4b957ddabafc8437b671c4a9563b !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runboat

-

This module adds the oauth authentication method to connect -to remote systems.

+

Beta License: AGPL-3 OCA/server-backend Translate me on Weblate Try me on Runboat

+

This module adds the oauth authentication method to connect to remote +systems.

Table of contents

    @@ -386,10 +386,10 @@

    Base External System - oauth systems

Bug Tracker

-

Bugs are tracked on GitHub Issues. +

Bugs are tracked on GitHub 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.

+feedback.

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

@@ -413,7 +413,9 @@

Maintainers

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.

-

This module is part of the OCA/server-tools project on GitHub.

+

Current maintainer:

+

NL66278

+

This module is part of the OCA/server-backend project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/setup/base_external_system_oauth/odoo/addons/base_external_system_oauth b/setup/base_external_system_oauth/odoo/addons/base_external_system_oauth new file mode 120000 index 000000000..f8f53fe46 --- /dev/null +++ b/setup/base_external_system_oauth/odoo/addons/base_external_system_oauth @@ -0,0 +1 @@ +../../../../base_external_system_oauth \ No newline at end of file diff --git a/setup/base_external_system_oauth/setup.py b/setup/base_external_system_oauth/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/base_external_system_oauth/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)