Skip to content

Commit 16e8ee3

Browse files
committed
[MIG] fastapi_auth_api_key: Migration to 19.0
1 parent 1756ff6 commit 16e8ee3

5 files changed

Lines changed: 26 additions & 15 deletions

File tree

fastapi_auth_api_key/README.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Fastapi Auth API Key
2121
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2222
:alt: License: AGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
24-
:target: https://github.com/OCA/rest-framework/tree/18.0/fastapi_auth_api_key
24+
:target: https://github.com/OCA/rest-framework/tree/19.0/fastapi_auth_api_key
2525
:alt: OCA/rest-framework
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-fastapi_auth_api_key
27+
:target: https://translation.odoo-community.org/projects/rest-framework-19-0/rest-framework-19-0-fastapi_auth_api_key
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -84,7 +84,7 @@ Bug Tracker
8484
Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/issues>`_.
8585
In case of trouble, please check there if your issue has already been reported.
8686
If you spotted it first, help us to smash it by providing a detailed and welcomed
87-
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20fastapi_auth_api_key%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
87+
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20fastapi_auth_api_key%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
8888

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

@@ -101,6 +101,7 @@ Contributors
101101

102102
- Matthieu Méquignon <matthieu.mequignon@camptocamp.com>
103103
- Son Ho <sonhd@trobz.com>
104+
- Giuseppe Ardoselli <agiuseppe28@gmail.com>
104105

105106
Other credits
106107
-------------
@@ -129,6 +130,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
129130

130131
|maintainer-mmequignon|
131132

132-
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/18.0/fastapi_auth_api_key>`_ project on GitHub.
133+
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/19.0/fastapi_auth_api_key>`_ project on GitHub.
133134

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

fastapi_auth_api_key/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
{
55
"name": "Fastapi Auth API Key",
6-
"version": "18.0.1.0.0",
6+
"version": "19.0.1.0.0",
77
"category": "Others",
88
"website": "https://github.com/OCA/rest-framework",
99
"author": "Camptocamp, Odoo Community Association (OCA)",

fastapi_auth_api_key/dependencies.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
import os
44
from typing import Annotated
55

6+
from fastapi.exceptions import HTTPException
7+
68
from odoo import SUPERUSER_ID
79
from odoo.api import Environment
810
from odoo.exceptions import ValidationError
911

1012
from odoo.addons.auth_api_key.models.auth_api_key import AuthApiKey
11-
from odoo.addons.base.models.res_partner import Partner
13+
from odoo.addons.base.models.res_partner import ResPartner
1214
from odoo.addons.fastapi.dependencies import fastapi_endpoint, odoo_env
1315
from odoo.addons.fastapi.models.fastapi_endpoint import FastapiEndpoint
1416

1517
from fastapi import Depends, status
16-
from fastapi.exceptions import HTTPException
1718
from fastapi.security import APIKeyHeader
1819

1920
HTTP_API_KEY_HEADER = os.environ.get("FASTAPI_AUTH_HTTP_API_KEY_HEADER", "HTTP-API-KEY")
@@ -27,8 +28,10 @@ def authenticated_auth_api_key(
2728
if not key:
2829
raise HTTPException(
2930
status_code=status.HTTP_401_UNAUTHORIZED,
30-
detail=env._("Missing %(HTTP_API_KEY_HEADER)s header")
31-
% {"HTTP_API_KEY_HEADER": HTTP_API_KEY_HEADER},
31+
detail=env._(
32+
"Missing %(HTTP_API_KEY_HEADER)s header",
33+
HTTP_API_KEY_HEADER=HTTP_API_KEY_HEADER,
34+
),
3235
headers={"WWW-Authenticate": HTTP_API_KEY_HEADER},
3336
)
3437
admin_env = Environment(env.cr, SUPERUSER_ID, {})
@@ -55,7 +58,7 @@ def authenticated_auth_api_key(
5558

5659
def authenticated_partner_by_api_key(
5760
auth_api_key: Annotated[AuthApiKey, Depends(authenticated_auth_api_key)],
58-
) -> Partner:
61+
) -> ResPartner:
5962
return auth_api_key.user_id.partner_id
6063

6164

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
- Matthieu Méquignon \<<matthieu.mequignon@camptocamp.com>\>
22
- Son Ho \<<sonhd@trobz.com>\>
3+
- Giuseppe Ardoselli \<<agiuseppe28@gmail.com>\>

fastapi_auth_api_key/tests/test_fastapi_api_key_dependencies.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from fastapi.exceptions import HTTPException
2+
13
from odoo.tests import tagged
24
from odoo.tests.common import TransactionCase
35

@@ -7,16 +9,20 @@
79
authenticated_partner_by_api_key,
810
)
911

10-
from fastapi.exceptions import HTTPException
11-
1212

1313
@tagged("-at_install", "post_install")
1414
class TestFastapiAuthApiKey(TransactionCase):
1515
@classmethod
1616
def setUpClass(cls):
1717
super().setUpClass()
1818
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
19-
demo_user = cls.env.ref("base.user_demo")
19+
# Odoo 19 no longer loads demo data by default, so we cannot rely on
20+
# ``base.user_demo``; create a dedicated user instead.
21+
demo_user = (
22+
cls.env["res.users"]
23+
.with_context(no_reset_password=True)
24+
.create({"name": "Endpoint Demo User", "login": "endpoint_demo_user"})
25+
)
2026
cls.demo_env = demo_user.with_user(demo_user).env
2127
cls.demo_endpoint = cls.env["fastapi.endpoint"].create(
2228
{
@@ -79,7 +85,7 @@ def test_authenticated_auth_api_key_no_api_key_found(self):
7985
# An exception is raised when no api key record is found
8086
with self.assertRaises(HTTPException) as error:
8187
authenticated_auth_api_key("404", self.demo_env, self.demo_endpoint)
82-
self.assertEqual(error.exception.detail, ("The key 404 is not allowed",))
88+
self.assertEqual(error.exception.detail, ("The key '404' is not allowed",))
8389

8490
def test_authenticated_auth_api_key_unauthorized_key(self):
8591
# An exception is raised when unauthorized api key record is found

0 commit comments

Comments
 (0)