Skip to content

Commit 85be184

Browse files
committed
[ADD] shopinvader_fastapi_auth_partner_api_unit_member
1 parent db25c8c commit 85be184

File tree

18 files changed

+1004
-0
lines changed

18 files changed

+1004
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../shopinvader_fastapi_auth_partner_api_unit_member
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
================================================
2+
Shopinvader Fastapi Auth Partner Api Unit Member
3+
================================================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:46bd8663388a1f03209619852bf7bec6c34a32457d19e688254400b19449d058
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-shopinvader%2Fodoo--shopinvader-lightgray.png?logo=github
20+
:target: https://github.com/shopinvader/odoo-shopinvader/tree/16.0/shopinvader_fastapi_auth_partner_api_unit_member
21+
:alt: shopinvader/odoo-shopinvader
22+
23+
|badge1| |badge2| |badge3|
24+
25+
This module glues the `shopinvader_fastapi_auth_partner_api` and the `shopinvader_api_unit_member` modules.
26+
27+
It adds a auth_state field to the unit member and defines this member route:
28+
29+
- `POST /unit/members/:id/invite` to add an auth.partner to the unit member allowing it to sign in and send an invite email to it.
30+
31+
32+
**Table of contents**
33+
34+
.. contents::
35+
:local:
36+
37+
Bug Tracker
38+
===========
39+
40+
Bugs are tracked on `GitHub Issues <https://github.com/shopinvader/odoo-shopinvader/issues>`_.
41+
In case of trouble, please check there if your issue has already been reported.
42+
If you spotted it first, help us to smash it by providing a detailed and welcomed
43+
`feedback <https://github.com/shopinvader/odoo-shopinvader/issues/new?body=module:%20shopinvader_fastapi_auth_partner_api_unit_member%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
44+
45+
Do not contact contributors directly about support or help with technical issues.
46+
47+
Credits
48+
=======
49+
50+
Authors
51+
~~~~~~~
52+
53+
* Akretion
54+
55+
Contributors
56+
~~~~~~~~~~~~
57+
58+
* `Akretion <https://www.akretion.com>`_:
59+
60+
* Florian Mounier
61+
62+
Maintainers
63+
~~~~~~~~~~~
64+
65+
This module is part of the `shopinvader/odoo-shopinvader <https://github.com/shopinvader/odoo-shopinvader/tree/16.0/shopinvader_fastapi_auth_partner_api_unit_member>`_ project on GitHub.
66+
67+
You are welcome to contribute.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import models
2+
from . import routers
3+
from . import schemas
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2024 Akretion (http://www.akretion.com).
2+
# @author Florian Mounier <florian.mounier@akretion.com>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
5+
{
6+
"name": "Shopinvader Fastapi Auth Partner Api Unit Member",
7+
"summary": "This module glues the shopinvader unit member management with "
8+
"the fastapi auth partner api adding an auth state on members and an invite "
9+
"route.",
10+
"version": "16.0.1.0.0",
11+
"license": "AGPL-3",
12+
"author": "Akretion",
13+
"website": "https://github.com/shopinvader/odoo-shopinvader",
14+
"depends": [
15+
"shopinvader_api_unit_member",
16+
"shopinvader_fastapi_auth_partner",
17+
],
18+
"data": [
19+
"data/email_data.xml",
20+
"views/auth_directory_view.xml",
21+
],
22+
"auto_install": True,
23+
"installable": True,
24+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<odoo noupdate="1">
3+
<record id="email_already_existing" model="mail.template">
4+
<field name="name">Auth Directory: Email Already Existing</field>
5+
<field name="email_from">noreply@example.org</field>
6+
<field name="subject">Someone tried to invite you in an other team</field>
7+
<field name="partner_to">{{object.partner_id.id}}</field>
8+
<field name="model_id" ref="auth_partner.model_auth_partner" />
9+
<field name="auto_delete" eval="True" />
10+
<field name="lang">{{object.partner_id.lang}}</field>
11+
<field name="body_html" type="html">
12+
<div>
13+
Hi <t t-out="object.partner_id.name or ''" />
14+
<t t-set="member" t-value="object.env.context.get('member')" />
15+
<t t-set="manager" t-value="object.env.context.get('manager')" />
16+
17+
<p>
18+
<t t-esc="manager.name" /> tried to invite you in the team
19+
<t t-esc="manager.unit_id.name" /> but you already have an
20+
other account, please contact <t t-esc="manager.name" /> if
21+
you want to change your team.
22+
</p>
23+
</div>
24+
</field>
25+
</record>
26+
27+
</odoo>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import auth_directory
2+
from . import res_partner
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2024 Akretion (http://www.akretion.com).
2+
# @author Florian Mounier <florian.mounier@akretion.com>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
5+
from odoo import fields, models
6+
7+
8+
class AuthDirectory(models.Model):
9+
_inherit = "auth.directory"
10+
11+
member_existing_template_id = fields.Many2one(
12+
"mail.template",
13+
"Mail Template Unit Member Already Existing",
14+
required=False,
15+
default=lambda self: self.env.ref(
16+
"shopinvader_fastapi_auth_partner_api_unit_member.email_already_existing",
17+
raise_if_not_found=False,
18+
),
19+
)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Copyright 2024 Akretion (http://www.akretion.com).
2+
# @author Florian Mounier <florian.mounier@akretion.com>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
import logging
5+
6+
from odoo import _, api, fields, models
7+
from odoo.exceptions import UserError
8+
9+
from ..schemas import AuthState
10+
11+
_logger = logging.getLogger(__name__)
12+
13+
14+
class ResPartner(models.Model):
15+
_inherit = "res.partner"
16+
17+
member_auth_state = fields.Selection(
18+
selection=[
19+
(AuthState.none.value, "None"),
20+
(AuthState.invited.value, "Invited"),
21+
(AuthState.accepted.value, "Accepted"),
22+
],
23+
compute="_compute_member_auth_state",
24+
)
25+
26+
@api.depends("auth_partner_ids.password", "auth_partner_ids.encrypted_password")
27+
def _compute_member_auth_state(self):
28+
for record in self:
29+
auth = record.auth_partner_ids
30+
if not auth:
31+
record.member_auth_state = AuthState.none.value
32+
continue
33+
34+
if len(auth) > 1:
35+
_logger.warning(
36+
"Multiple auth_partner_ids for unit member partner %s, "
37+
"using the first one",
38+
record,
39+
)
40+
auth = auth[0]
41+
42+
if auth.password or auth.encrypted_password:
43+
record.member_auth_state = AuthState.accepted.value
44+
else:
45+
record.member_auth_state = AuthState.invited.value
46+
47+
@api.model
48+
def _invite_shopinvader_unit_member(self, member_id, directory):
49+
self._ensure_manager()
50+
member = self.browse(member_id)
51+
self._ensure_same_unit(member)
52+
if not member.email:
53+
raise UserError(_("Cannot invite a member without an email"))
54+
55+
auth_with_email = self.env["auth.partner"].search(
56+
[
57+
("login", "=", member.email),
58+
("directory_id", "=", directory.id),
59+
],
60+
)
61+
62+
if auth_with_email:
63+
# If another member with the same email is already in the directory,
64+
if auth_with_email not in member.auth_partner_ids:
65+
directory._send_mail_background(
66+
"member_existing",
67+
auth_with_email,
68+
member=member,
69+
manager=self,
70+
)
71+
raise UserError(
72+
# Do not leak the information that the email is already in use
73+
_("Something went wrong, please contact the administrator"),
74+
)
75+
76+
member_auth = auth_with_email
77+
else:
78+
member_auth = self.env["auth.partner"].create(
79+
{
80+
"partner_id": member.id,
81+
"login": member.email,
82+
"directory_id": directory.id,
83+
}
84+
)
85+
86+
member_auth._send_invite()
87+
return member
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+
3+
* Florian Mounier

0 commit comments

Comments
 (0)