Skip to content

Commit ae3d34c

Browse files
author
sonhd91
committed
[MIG] fastapi_auth_api_key: Migration to 17.0
1 parent f93f936 commit ae3d34c

File tree

7 files changed

+34
-14
lines changed

7 files changed

+34
-14
lines changed

fastapi_auth_api_key/README.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Fastapi Auth Api Key
1717
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1818
:alt: License: AGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
20-
:target: https://github.com/OCA/rest-framework/tree/16.0/fastapi_auth_api_key
20+
:target: https://github.com/OCA/rest-framework/tree/17.0/fastapi_auth_api_key
2121
:alt: OCA/rest-framework
2222
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/rest-framework-16-0/rest-framework-16-0-fastapi_auth_api_key
23+
:target: https://translation.odoo-community.org/projects/rest-framework-17-0/rest-framework-17-0-fastapi_auth_api_key
2424
:alt: Translate me on Weblate
2525
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=16.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=17.0
2727
:alt: Try me on Runboat
2828

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

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

@@ -94,6 +94,12 @@ Contributors
9494
~~~~~~~~~~~~
9595

9696
* Matthieu Méquignon <[email protected]>
97+
98+
99+
Other credits
100+
~~~~~~~~~~~~~
101+
102+
The migration of this module from 16.0 to 17.0 was financially supported by Camptocamp
97103

98104
Maintainers
99105
~~~~~~~~~~~
@@ -116,6 +122,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
116122

117123
|maintainer-mmequignon|
118124

119-
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/16.0/fastapi_auth_api_key>`_ project on GitHub.
125+
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/17.0/fastapi_auth_api_key>`_ project on GitHub.
120126

121127
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": "16.0.1.0.0",
6+
"version": "17.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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2024 Camptocamp SA
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
33

4-
from typing_extensions import Annotated
4+
from typing import Annotated
55

66
from odoo import SUPERUSER_ID
77
from odoo.api import Environment
@@ -34,7 +34,7 @@ def authenticated_auth_api_key(
3434
except ValidationError as error:
3535
raise HTTPException(
3636
status_code=status.HTTP_401_UNAUTHORIZED,
37-
detail=error.name,
37+
detail=error.args,
3838
headers={"WWW-Authenticate": "HTTP-API-KEY"},
3939
) from error
4040
# Ensure the api key is authorized for the current endpoint.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
* Matthieu Méquignon <[email protected]>
2+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The migration of this module from 16.0 to 17.0 was financially supported by Camptocamp

fastapi_auth_api_key/tests/test_fastapi_api_key_dependencies.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@ def setUpClass(cls):
1717
super().setUpClass()
1818
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
1919
# Is it valid? We need an env without superpowers
20-
demo_user = cls.env.ref("base.partner_demo")
20+
demo_user = cls.env.ref("base.user_demo")
2121
cls.demo_env = demo_user.with_user(demo_user).env
22+
cls.demo_endpoint = cls.env["fastapi.endpoint"].create(
23+
{
24+
"name": "Test Enpoint",
25+
"app": "demo",
26+
"root_path": "/path_demo",
27+
"demo_auth_method": "api_key",
28+
"user_id": demo_user.id,
29+
}
30+
)
2231
cls.setUpClassApiKey()
2332

2433
@classmethod
@@ -63,19 +72,22 @@ def setUpClassApiKey(cls):
6372
def test_authenticated_auth_api_key(self):
6473
# An exception is raised when no api key is used
6574
with self.assertRaises(HTTPException) as error:
66-
authenticated_auth_api_key(False, self.demo_env)
75+
authenticated_auth_api_key(False, self.demo_env, self.demo_endpoint)
6776
self.assertEqual(error.exception.detail, "No HTTP-API-KEY provided")
6877
# An exception is raised when no api key record is found
6978
with self.assertRaises(HTTPException) as error:
70-
authenticated_auth_api_key("404", self.demo_env)
71-
self.assertEqual(error.exception.detail, "The key 404 is not allowed")
79+
authenticated_auth_api_key("404", self.demo_env, self.demo_endpoint)
80+
self.assertEqual(error.exception.detail, ("The key 404 is not allowed",))
7281
# TODO enable this when we know how to filter keys based
7382
# on endpoint's api key group.
7483
# An exception is raised when unauthorized api key record is found
7584
# with self.assertRaises(HTTPException) as error:
7685
# authenticated_auth_api_key("not_authorized", self.demo_env)
86+
self.demo_endpoint.auth_api_key_group_id = (
87+
self.authorized_api_key.auth_api_key_group_ids[0]
88+
)
7789
result_key = authenticated_auth_api_key(
78-
self.authorized_api_key.key, self.demo_env
90+
self.authorized_api_key.key, self.demo_env, self.demo_endpoint
7991
)
8092
self.assertEqual(result_key, self.authorized_api_key)
8193

fastapi_auth_api_key/views/fastapi_endpoint.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<field name="model">fastapi.endpoint</field>
99
<field name="inherit_id" ref="fastapi.fastapi_endpoint_form_view" />
1010
<field name="arch" type="xml">
11-
<group name="resources" position="inside">
11+
<group name="resoures" position="inside">
1212
<field name="auth_api_key_group_id" />
1313
</group>
1414
</field>

0 commit comments

Comments
 (0)