Skip to content

Commit c3aade5

Browse files
paradoxxxzerosebastienbeau
authored andcommitted
[IMP] fastapi_auth_partner: pre-commit auto fixes
1 parent df6dff0 commit c3aade5

18 files changed

Lines changed: 169 additions & 169 deletions

fastapi_auth_partner/README.rst

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.. image:: https://odoo-community.org/readme-banner-image
2-
:target: https://odoo-community.org/get-involved?utm_source=readme
3-
:alt: Odoo Community Association
4-
51
====================
62
Fastapi Auth Partner
73
====================
@@ -17,23 +13,24 @@ Fastapi Auth Partner
1713
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1814
:target: https://odoo-community.org/page/development-status
1915
:alt: Beta
20-
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
2117
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2218
:alt: License: AGPL-3
2319
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
24-
:target: https://github.com/OCA/rest-framework/tree/16.0/fastapi_auth_partner
20+
:target: https://github.com/OCA/rest-framework/tree/18.0/fastapi_auth_partner
2521
:alt: OCA/rest-framework
2622
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/rest-framework-16-0/rest-framework-16-0-fastapi_auth_partner
23+
:target: https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-fastapi_auth_partner
2824
:alt: Translate me on Weblate
2925
.. |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=16.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=18.0
3127
:alt: Try me on Runboat
3228

3329
|badge1| |badge2| |badge3| |badge4| |badge5|
3430

35-
This module is the FastAPI implementation of `auth_partner <../auth_partner>`_
36-
it provides all the routes to manage the authentication of partners.
31+
This module is the FastAPI implementation of
32+
`auth_partner <../auth_partner>`__ it provides all the routes to manage
33+
the authentication of partners.
3734

3835
**Table of contents**
3936

@@ -43,45 +40,48 @@ it provides all the routes to manage the authentication of partners.
4340
Usage
4441
=====
4542

46-
First you have to add the auth router to your FastAPI endpoint and the authentication dependency to your app dependencies:
43+
First you have to add the auth router to your FastAPI endpoint and the
44+
authentication dependency to your app dependencies:
4745

48-
.. code-block:: python
46+
.. code:: python
4947
50-
from odoo.addons.fastapi import dependencies
51-
from odoo.addons.fastapi_auth_partner.dependencies import (
52-
auth_partner_authenticated_partner,
53-
)
54-
from odoo.addons.fastapi_auth_partner.routers.auth import auth_router
48+
from odoo.addons.fastapi import dependencies
49+
from odoo.addons.fastapi_auth_partner.dependencies import (
50+
auth_partner_authenticated_partner,
51+
)
52+
from odoo.addons.fastapi_auth_partner.routers.auth import auth_router
5553
56-
class FastapiEndpoint(models.Model):
57-
_inherit = "fastapi.endpoint"
54+
class FastapiEndpoint(models.Model):
55+
_inherit = "fastapi.endpoint"
5856
59-
def _get_fastapi_routers(self):
60-
if self.app == "myapp":
61-
return [
62-
auth_router,
63-
]
64-
return super()._get_fastapi_routers()
57+
def _get_fastapi_routers(self):
58+
if self.app == "myapp":
59+
return [
60+
auth_router,
61+
]
62+
return super()._get_fastapi_routers()
6563
66-
def _get_app_dependencies_overrides(self):
67-
res = super()._get_app_dependencies_overrides()
68-
if self.app == "myapp":
69-
res.update(
70-
{
71-
dependencies.authenticated_partner_impl: auth_partner_authenticated_partner,
72-
}
73-
)
74-
return res
64+
def _get_app_dependencies_overrides(self):
65+
res = super()._get_app_dependencies_overrides()
66+
if self.app == "myapp":
67+
res.update(
68+
{
69+
dependencies.authenticated_partner_impl: auth_partner_authenticated_partner,
70+
}
71+
)
72+
return res
7573
76-
Next you can manage your authenticable partners and directories in the Odoo interface:
74+
Next you can manage your authenticable partners and directories in the
75+
Odoo interface:
7776

7877
FastAPI > Authentication > Partner
7978

8079
and
8180

8281
FastAPI > Authentication > Directory
8382

84-
Next you must set the directory used for the authentication in the FastAPI endpoint:
83+
Next you must set the directory used for the authentication in the
84+
FastAPI endpoint:
8585

8686
FastAPI > FastAPI Endpoint > myapp > Directory
8787

@@ -102,28 +102,28 @@ Bug Tracker
102102
Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/issues>`_.
103103
In case of trouble, please check there if your issue has already been reported.
104104
If you spotted it first, help us to smash it by providing a detailed and welcomed
105-
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20fastapi_auth_partner%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
105+
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20fastapi_auth_partner%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
106106

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

109109
Credits
110110
=======
111111

112112
Authors
113-
~~~~~~~
113+
-------
114114

115115
* Akretion
116116

117117
Contributors
118-
~~~~~~~~~~~~
118+
------------
119119

120-
* `Akretion <https://www.akretion.com>`_:
120+
- `Akretion <https://www.akretion.com>`__:
121121

122-
* Sébastien Beau
123-
* Florian Mounier
122+
- Sébastien Beau
123+
- Florian Mounier
124124

125125
Maintainers
126-
~~~~~~~~~~~
126+
-----------
127127

128128
This module is maintained by the OCA.
129129

@@ -135,6 +135,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
135135
mission is to support the collaborative development of Odoo features and
136136
promote its widespread use.
137137

138-
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/16.0/fastapi_auth_partner>`_ project on GitHub.
138+
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/18.0/fastapi_auth_partner>`_ project on GitHub.
139139

140140
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<odoo>
3-
<record model="fastapi.endpoint" id="fastapi_endpoint_demo">
4-
<field name="name">Fastapi Auth Partner Demo Endpoint</field>
5-
<field
3+
<record model="fastapi.endpoint" id="fastapi_endpoint_demo">
4+
<field name="name">Fastapi Auth Partner Demo Endpoint</field>
5+
<field
66
name="description"
77
><![CDATA[
88
# A Dummy FastApi Partner Auth Demo
@@ -11,16 +11,19 @@ This demo endpoint has been created by inhering from "fastapi.endpoint", registe
1111
a new app into the app selection field and implementing the `_get_fastapi_routers`
1212
methods. See documentation to learn more about how to create a new app.
1313
]]></field>
14-
<field name="app">demo</field>
15-
<field name="root_path">/fastapi_auth_partner_demo</field>
16-
<field name="demo_auth_method">auth_partner</field>
17-
<field name="user_id" ref="fastapi.my_demo_app_user" />
18-
<field name="directory_id" ref="auth_partner.demo_directory" />
19-
<field name="public_api_url">https://api.example.com/</field>
20-
<field name="public_url">https://www.example.com/</field>
21-
</record>
14+
<field name="app">demo</field>
15+
<field name="root_path">/fastapi_auth_partner_demo</field>
16+
<field name="demo_auth_method">auth_partner</field>
17+
<field name="user_id" ref="fastapi.my_demo_app_user" />
18+
<field name="directory_id" ref="auth_partner.demo_directory" />
19+
<field name="public_api_url">https://api.example.com/</field>
20+
<field name="public_url">https://www.example.com/</field>
21+
</record>
2222

23-
<record id="fastapi.my_demo_app_user" model="res.users">
24-
<field name="groups_id" eval="[(4, ref('auth_partner.group_auth_partner_api'))]" />
25-
</record>
23+
<record id="fastapi.my_demo_app_user" model="res.users">
24+
<field
25+
name="groups_id"
26+
eval="[(4, ref('auth_partner.group_auth_partner_api'))]"
27+
/>
28+
</record>
2629
</odoo>

fastapi_auth_partner/dependencies.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import logging
66
import sys
7-
from typing import Any, Dict, Union
7+
from typing import Any
88

99
from itsdangerous import URLSafeTimedSerializer
1010
from starlette.status import HTTP_401_UNAUTHORIZED
@@ -20,12 +20,12 @@
2020
if sys.version_info >= (3, 9):
2121
from typing import Annotated
2222
else:
23-
from typing_extensions import Annotated
23+
from typing import Annotated
2424

2525
_logger = logging.getLogger(__name__)
2626

2727

28-
Payload = Dict[str, Any]
28+
Payload = dict[str, Any]
2929

3030

3131
class AuthPartner:
@@ -41,7 +41,7 @@ def __call__(
4141
Depends(odoo_env),
4242
],
4343
endpoint: Annotated[FastapiEndpoint, Depends(fastapi_endpoint)],
44-
fastapi_auth_partner: Annotated[Union[str, None], Cookie()] = None,
44+
fastapi_auth_partner: Annotated[str | None, Cookie()] = None,
4545
) -> Partner:
4646
if not fastapi_auth_partner and self.allow_unauthenticated:
4747
return env["res.partner"].with_user(env.ref("base.public_user")).browse()

fastapi_auth_partner/models/fastapi_endpoint.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# @author Florian Mounier <florian.mounier@akretion.com>
44
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
55

6-
from typing import List
76

87
from odoo import fields, models
98

@@ -44,7 +43,7 @@ class FastapiEndpoint(models.Model):
4443
"Default to the public_api_url if not set or the odoo url if not set either."
4544
)
4645

47-
def _get_fastapi_routers(self) -> List[APIRouter]:
46+
def _get_fastapi_routers(self) -> list[APIRouter]:
4847
routers = super()._get_fastapi_routers()
4948
if self.app == "demo" and self.demo_auth_method == "auth_partner":
5049
routers.append(auth_router)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- [Akretion](https://www.akretion.com):
2+
- Sébastien Beau
3+
- Florian Mounier

fastapi_auth_partner/readme/CONTRIBUTORS.rst

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This module is the FastAPI implementation of
2+
[auth_partner](../auth_partner) it provides all the routes to manage the
3+
authentication of partners.

fastapi_auth_partner/readme/DESCRIPTION.rst

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
First you have to add the auth router to your FastAPI endpoint and the
2+
authentication dependency to your app dependencies:
3+
4+
``` python
5+
from odoo.addons.fastapi import dependencies
6+
from odoo.addons.fastapi_auth_partner.dependencies import (
7+
auth_partner_authenticated_partner,
8+
)
9+
from odoo.addons.fastapi_auth_partner.routers.auth import auth_router
10+
11+
class FastapiEndpoint(models.Model):
12+
_inherit = "fastapi.endpoint"
13+
14+
def _get_fastapi_routers(self):
15+
if self.app == "myapp":
16+
return [
17+
auth_router,
18+
]
19+
return super()._get_fastapi_routers()
20+
21+
def _get_app_dependencies_overrides(self):
22+
res = super()._get_app_dependencies_overrides()
23+
if self.app == "myapp":
24+
res.update(
25+
{
26+
dependencies.authenticated_partner_impl: auth_partner_authenticated_partner,
27+
}
28+
)
29+
return res
30+
```
31+
32+
Next you can manage your authenticable partners and directories in the
33+
Odoo interface:
34+
35+
FastAPI \> Authentication \> Partner
36+
37+
and
38+
39+
FastAPI \> Authentication \> Directory
40+
41+
Next you must set the directory used for the authentication in the
42+
FastAPI endpoint:
43+
44+
FastAPI \> FastAPI Endpoint \> myapp \> Directory
45+
46+
Then you can use the auth router to authenticate your requests:
47+
48+
- POST /auth/register to register a partner
49+
- POST /auth/login to authenticate a partner
50+
- POST /auth/logout to unauthenticate a partner
51+
- POST /auth/validate_email to validate a partner email
52+
- POST /auth/request_reset_password to request a password reset
53+
- POST /auth/set_password to set a new password
54+
- GET /auth/profile to get the partner profile
55+
- GET /auth/impersonate to impersonate a partner

0 commit comments

Comments
 (0)