diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 41f1049e9c..7e8a015431 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,7 +26,6 @@ exclude: | ^shopinvader_api_wishlist/| ^shopinvader_delivery_state/| ^shopinvader_fastapi_auth_jwt/| - ^shopinvader_fastapi_auth_partner/| ^shopinvader_sale_cart/| ^shopinvader_sale_cart_anonymous_partner/| ^shopinvader_sale_state/| diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index bad8d6dadf..0000000000 --- a/requirements.txt +++ /dev/null @@ -1,11 +0,0 @@ -# generated from manifests external_dependencies -cerberus -extendable-pydantic>=1.2.0 -extendable_pydantic>=1.0.0 -extendable_pydantic>=1.2.0 -fastapi -openupgradelib -pydantic>=2.0.0 -python-slugify -slugify -unidecode diff --git a/shopinvader_fastapi_auth_partner/README.rst b/shopinvader_fastapi_auth_partner/README.rst index b33e81a3f3..570e5d8ba0 100644 --- a/shopinvader_fastapi_auth_partner/README.rst +++ b/shopinvader_fastapi_auth_partner/README.rst @@ -17,13 +17,14 @@ Shopinvader Auth Partner authentication for FastAPI endpoints :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-shopinvader%2Fodoo--shopinvader-lightgray.png?logo=github - :target: https://github.com/shopinvader/odoo-shopinvader/tree/16.0/shopinvader_fastapi_auth_partner + :target: https://github.com/shopinvader/odoo-shopinvader/tree/18.0/shopinvader_fastapi_auth_partner :alt: shopinvader/odoo-shopinvader |badge1| |badge2| |badge3| -This module provides the ``auth_jwt_authenticated_or_anonymous_partner`` and -``auth_jwt_authenticated_or_anonymous_partner_auto_create`` FastAPI dependencies. +This module provides the ``auth_jwt_authenticated_or_anonymous_partner`` +and ``auth_jwt_authenticated_or_anonymous_partner_auto_create`` FastAPI +dependencies. **Table of contents** @@ -37,26 +38,28 @@ This module provide the following FastAPI dependencies: ``def auth_jwt_authenticated_or_anonymous_partner() -> Partner`` - This dependency returns the authenticated partner from ``fast_api_auth_jwt`` - ``auth_jwt_optionally_authenticated_partner``. If not authenticated or no partner is - found, look for the ``shopinvader_anonymous_partner`` cookie in the request and return - the corresponding partner. + This dependency returns the authenticated partner from + ``fast_api_auth_jwt`` ``auth_jwt_optionally_authenticated_partner``. + If not authenticated or no partner is found, look for the + ``shopinvader_anonymous_partner`` cookie in the request and return + the corresponding partner. - If not partner is found, raise a 401 (unauthorized). + If not partner is found, raise a 401 (unauthorized). ``def auth_jwt_authenticated_or_anonymous_partner_auto_create() -> Partner`` - This dependency returns the authenticated partner from ``fast_api_auth_jwt`` - ``auth_jwt_optionally_authenticated_partner``. If not authenticated or no partner is - found, look for the ``shopinvader_anonymous_partner`` cookie in the request and return - the corresponding partner. + This dependency returns the authenticated partner from + ``fast_api_auth_jwt`` ``auth_jwt_optionally_authenticated_partner``. + If not authenticated or no partner is found, look for the + ``shopinvader_anonymous_partner`` cookie in the request and return + the corresponding partner. - If no partner is found, create an anonymous partner, set the corresponding cookie and - return the newly created partner. + If no partner is found, create an anonymous partner, set the + corresponding cookie and return the newly created partner. -The record sets returned from these functions are bound either to the Odoo user defined -on the JWT validaator (if authenticated), or to the Odoo user defined on the FastAPI -endpoint. +The record sets returned from these functions are bound either to the +Odoo user defined on the JWT validaator (if authenticated), or to the +Odoo user defined on the FastAPI endpoint. These dependencies are suitable and intended to override the ``odoo.addon.fastapi.dependencies.authenticated_partner_impl``. @@ -67,7 +70,7 @@ Bug Tracker 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. @@ -75,13 +78,13 @@ Credits ======= Authors -~~~~~~~ +------- * Akretion Maintainers -~~~~~~~~~~~ +----------- -This module is part of the `shopinvader/odoo-shopinvader `_ project on GitHub. +This module is part of the `shopinvader/odoo-shopinvader `_ project on GitHub. You are welcome to contribute. diff --git a/shopinvader_fastapi_auth_partner/__manifest__.py b/shopinvader_fastapi_auth_partner/__manifest__.py index 9a0b1b3d18..5d2350f06a 100644 --- a/shopinvader_fastapi_auth_partner/__manifest__.py +++ b/shopinvader_fastapi_auth_partner/__manifest__.py @@ -6,14 +6,16 @@ { "name": "Shopinvader Auth Partner authentication for FastAPI endpoints", "summary": """ - Provide Partner and Anonymous Partner authentication to FastAPI routes.""", - "version": "16.0.1.0.0", + Provide Partner and Anonymous Partner authentication to FastAPI routes. + """, + "version": "18.0.1.0.0", "license": "AGPL-3", "author": "Akretion", "maintainers": [], "website": "https://github.com/shopinvader/odoo-shopinvader", - "depends": ["fastapi_auth_partner", "shopinvader_anonymous_partner"], - "data": [], - "demo": [], - 'installable': False, + "depends": [ + "fastapi_auth_partner", + "shopinvader_anonymous_partner", + ], + "installable": True, } diff --git a/shopinvader_fastapi_auth_partner/dependencies.py b/shopinvader_fastapi_auth_partner/dependencies.py index ac29863b80..4da1d05b1a 100644 --- a/shopinvader_fastapi_auth_partner/dependencies.py +++ b/shopinvader_fastapi_auth_partner/dependencies.py @@ -4,7 +4,7 @@ import logging -import sys +from typing import Annotated from fastapi import Depends, HTTPException, Request, Response, status @@ -16,11 +16,6 @@ auth_partner_optionally_authenticated_partner, ) -if sys.version_info >= (3, 9): - from typing import Annotated -else: - from typing_extensions import Annotated - _logger = logging.getLogger(__name__) diff --git a/shopinvader_fastapi_auth_partner/pyproject.toml b/shopinvader_fastapi_auth_partner/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/shopinvader_fastapi_auth_partner/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/shopinvader_fastapi_auth_partner/readme/DESCRIPTION.md b/shopinvader_fastapi_auth_partner/readme/DESCRIPTION.md new file mode 100644 index 0000000000..89b3f44edc --- /dev/null +++ b/shopinvader_fastapi_auth_partner/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module provides the `auth_jwt_authenticated_or_anonymous_partner` +and `auth_jwt_authenticated_or_anonymous_partner_auto_create` FastAPI +dependencies. diff --git a/shopinvader_fastapi_auth_partner/readme/DESCRIPTION.rst b/shopinvader_fastapi_auth_partner/readme/DESCRIPTION.rst deleted file mode 100644 index d1dd86e70e..0000000000 --- a/shopinvader_fastapi_auth_partner/readme/DESCRIPTION.rst +++ /dev/null @@ -1,2 +0,0 @@ -This module provides the ``auth_jwt_authenticated_or_anonymous_partner`` and -``auth_jwt_authenticated_or_anonymous_partner_auto_create`` FastAPI dependencies. diff --git a/shopinvader_fastapi_auth_partner/readme/USAGE.md b/shopinvader_fastapi_auth_partner/readme/USAGE.md new file mode 100644 index 0000000000..969c03cd7f --- /dev/null +++ b/shopinvader_fastapi_auth_partner/readme/USAGE.md @@ -0,0 +1,29 @@ +This module provide the following FastAPI dependencies: + +`def auth_jwt_authenticated_or_anonymous_partner() -> Partner` + +> This dependency returns the authenticated partner from +> `fast_api_auth_jwt` `auth_jwt_optionally_authenticated_partner`. If +> not authenticated or no partner is found, look for the +> `shopinvader_anonymous_partner` cookie in the request and return the +> corresponding partner. +> +> If not partner is found, raise a 401 (unauthorized). + +`def auth_jwt_authenticated_or_anonymous_partner_auto_create() -> Partner` + +> This dependency returns the authenticated partner from +> `fast_api_auth_jwt` `auth_jwt_optionally_authenticated_partner`. If +> not authenticated or no partner is found, look for the +> `shopinvader_anonymous_partner` cookie in the request and return the +> corresponding partner. +> +> If no partner is found, create an anonymous partner, set the +> corresponding cookie and return the newly created partner. + +The record sets returned from these functions are bound either to the +Odoo user defined on the JWT validaator (if authenticated), or to the +Odoo user defined on the FastAPI endpoint. + +These dependencies are suitable and intended to override the +`odoo.addon.fastapi.dependencies.authenticated_partner_impl`. diff --git a/shopinvader_fastapi_auth_partner/readme/USAGE.rst b/shopinvader_fastapi_auth_partner/readme/USAGE.rst deleted file mode 100644 index b97c66a4eb..0000000000 --- a/shopinvader_fastapi_auth_partner/readme/USAGE.rst +++ /dev/null @@ -1,27 +0,0 @@ -This module provide the following FastAPI dependencies: - -``def auth_jwt_authenticated_or_anonymous_partner() -> Partner`` - - This dependency returns the authenticated partner from ``fast_api_auth_jwt`` - ``auth_jwt_optionally_authenticated_partner``. If not authenticated or no partner is - found, look for the ``shopinvader_anonymous_partner`` cookie in the request and return - the corresponding partner. - - If not partner is found, raise a 401 (unauthorized). - -``def auth_jwt_authenticated_or_anonymous_partner_auto_create() -> Partner`` - - This dependency returns the authenticated partner from ``fast_api_auth_jwt`` - ``auth_jwt_optionally_authenticated_partner``. If not authenticated or no partner is - found, look for the ``shopinvader_anonymous_partner`` cookie in the request and return - the corresponding partner. - - If no partner is found, create an anonymous partner, set the corresponding cookie and - return the newly created partner. - -The record sets returned from these functions are bound either to the Odoo user defined -on the JWT validaator (if authenticated), or to the Odoo user defined on the FastAPI -endpoint. - -These dependencies are suitable and intended to override the -``odoo.addon.fastapi.dependencies.authenticated_partner_impl``. diff --git a/shopinvader_fastapi_auth_partner/static/description/index.html b/shopinvader_fastapi_auth_partner/static/description/index.html new file mode 100644 index 0000000000..f91ed3fa2f --- /dev/null +++ b/shopinvader_fastapi_auth_partner/static/description/index.html @@ -0,0 +1,440 @@ + + + + + +Shopinvader Auth Partner authentication for FastAPI endpoints + + + +
+

Shopinvader Auth Partner authentication for FastAPI endpoints

+ + +

Beta License: AGPL-3 shopinvader/odoo-shopinvader

+

This module provides the auth_jwt_authenticated_or_anonymous_partner +and auth_jwt_authenticated_or_anonymous_partner_auto_create FastAPI +dependencies.

+

Table of contents

+ +
+

Usage

+

This module provide the following FastAPI dependencies:

+

def auth_jwt_authenticated_or_anonymous_partner() -> Partner

+
+

This dependency returns the authenticated partner from +fast_api_auth_jwt auth_jwt_optionally_authenticated_partner. +If not authenticated or no partner is found, look for the +shopinvader_anonymous_partner cookie in the request and return +the corresponding partner.

+

If not partner is found, raise a 401 (unauthorized).

+
+

def auth_jwt_authenticated_or_anonymous_partner_auto_create() -> Partner

+
+

This dependency returns the authenticated partner from +fast_api_auth_jwt auth_jwt_optionally_authenticated_partner. +If not authenticated or no partner is found, look for the +shopinvader_anonymous_partner cookie in the request and return +the corresponding partner.

+

If no partner is found, create an anonymous partner, set the +corresponding cookie and return the newly created partner.

+
+

The record sets returned from these functions are bound either to the +Odoo user defined on the JWT validaator (if authenticated), or to the +Odoo user defined on the FastAPI endpoint.

+

These dependencies are suitable and intended to override the +odoo.addon.fastapi.dependencies.authenticated_partner_impl.

+
+
+

Bug Tracker

+

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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
+
+
+

Maintainers

+

This module is part of the shopinvader/odoo-shopinvader project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/shopinvader_fastapi_auth_partner/tests/test_auth_partner_or_anonymous.py b/shopinvader_fastapi_auth_partner/tests/test_auth_partner_or_anonymous.py index 7884eebd2c..d1d8b67fb1 100644 --- a/shopinvader_fastapi_auth_partner/tests/test_auth_partner_or_anonymous.py +++ b/shopinvader_fastapi_auth_partner/tests/test_auth_partner_or_anonymous.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -import sys +from typing import Annotated from unittest import mock from fastapi import Depends, FastAPI, status @@ -17,11 +17,6 @@ auth_partner_authenticated_or_anonymous_partner_autocreate, ) -if sys.version_info >= (3, 9): - from typing import Annotated -else: - from typing_extensions import Annotated - app = FastAPI() @@ -78,7 +73,6 @@ def _add_anonymous_cookie(self, client, force_value=None): ) -@tests.tagged("post_install", "-at_install") class TestAuthPartnerOrAnonymous(TestBase): def test_unauthenticated(self) -> None: # unauthenticated returns 401 diff --git a/test-requirements.txt b/test-requirements.txt index d9de7263d8..968a165200 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,3 +5,7 @@ vcrpy-unittest unittest2 # For shopinvader test_controller, which inherits component odoo-test-helper httpx # For FastAPI tests + +odoo-addon-auth-partner @ git+https://github.com/OCA/rest-framework.git@refs/pull/580/head#subdirectory=auth_partner +odoo-addon-fastapi-auth-partner @ git+https://github.com/OCA/rest-framework.git@refs/pull/581/head#subdirectory=fastapi_auth_partner +odoo-addon-shopinvader_anonymous_partner @ git+https://github.com/shopinvader/odoo-shopinvader@refs/pull/1643/head#subdirectory=shopinvader_anonymous_partner