Skip to content

Commit 07cccea

Browse files
committed
[MIG] auth_saml_create_user: Migration to 18.0
1 parent bd92107 commit 07cccea

15 files changed

Lines changed: 128 additions & 313 deletions

auth_saml_create_user/README.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Auth SAML Create User
1010
!! source digest: sha256:99e8fd5583907518e2d4a0ef800c952bf67fe884007baa8365c037da4ffa55b0
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
13-
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1414
:target: https://odoo-community.org/page/development-status
15-
:alt: Production/Stable
15+
:alt: Beta
1616
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
1717
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1818
:alt: License: AGPL-3
@@ -61,17 +61,28 @@ Authors
6161
-------
6262

6363
* Savoir-faire Linux
64+
* Smile
6465

6566
Contributors
6667
------------
6768

6869
- Luis Garcia(luis.garcia@savoirfairelinux.com)
70+
6971
- Jerome Oufella(jerome.oufella@savoirfairelinux.com)
72+
7073
- Rim Ben Dhaou <rim.bendhaou@savoirfairelinux.com>
74+
7175
- Larbi Gharib <larbi.gharib@savoirfairelinux.com>
76+
7277
- Pierre Gault <pierre.gault@savoirfairelinux.com>
78+
7379
- William Beverly <william.beverly@savoirfairelinux.com>
7480

81+
- [SMILE] (https://smile.eu/en):
82+
83+
- Martin Deconinck <martin.deconinck@smile.fr>
84+
- Théo Martin <theo.martin@smile.fr>
85+
7586
Other credits
7687
-------------
7788

auth_saml_create_user/__manifest__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@
66
"summary": """
77
This module extends the functionality of Auth SAML to support
88
the automatic creation of SAML users when they don't exist in odoo.""",
9-
"author": "Savoir-faire Linux, Odoo Community Association (OCA)",
9+
"version": "18.0.1.0.0",
10+
"category": "Tools",
11+
"sequence": 20,
12+
"author": "Savoir-faire Linux, Odoo Community Association (OCA), Smile",
1013
"maintainers": ["eilst"],
1114
"website": "https://github.com/OCA/server-auth",
1215
"license": "AGPL-3",
13-
"category": "Tools",
14-
"version": "11.0.1.0.1",
15-
"depends": ["auth_saml"],
16+
"depends": [
17+
"auth_saml",
18+
],
1619
"data": [
17-
"data/auth_saml_create_user.xml",
1820
"views/auth_saml.xml",
1921
],
20-
"development_status": "Production/Stable",
22+
"demo": [],
23+
"test": [],
24+
"auto_install": False,
25+
"installable": True,
26+
"application": False,
2127
}

auth_saml_create_user/data/auth_saml_create_user.xml

Lines changed: 0 additions & 90 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# © 2018 Savoir-faire Linux
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4-
from . import auth_saml
4+
from . import auth_saml_provider
55
from . import res_users

auth_saml_create_user/models/auth_saml.py renamed to auth_saml_create_user/models/auth_saml_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ class AuthSamlProvider(models.Model):
88
_inherit = "auth.saml.provider"
99

1010
create_user = fields.Boolean(
11-
string="Create User",
11+
default=True,
1212
)

auth_saml_create_user/models/res_users.py

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
import logging
55
import random
66

7-
from odoo import api, models
7+
from odoo import models
8+
from odoo.tools import safe_eval
9+
10+
from odoo.addons.auth_saml.models.ir_config_parameter import ALLOW_SAML_UID_AND_PASSWORD
811

912
_logger = logging.getLogger(__name__)
1013
s = "abcdefghijklmnopqrstuvwxyz034567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?"
@@ -14,29 +17,38 @@
1417
class ResUsers(models.Model):
1518
_inherit = "res.users"
1619

17-
@api.multi
18-
def _auth_saml_signin(self, provider, validation, saml_response):
19-
saml_uid = validation["user_id"]
20-
user_ids = self.search(
21-
[("saml_uid", "=", saml_uid), ("saml_provider_id", "=", provider)]
22-
)
23-
if self.check_if_create_user(provider) and not user_ids:
24-
self.create_user(saml_uid, provider)
25-
return super()._auth_saml_signin(provider, validation, saml_response)
26-
2720
def check_if_create_user(self, provider):
2821
return self.env["auth.saml.provider"].browse(provider).create_user
2922

3023
def create_user(self, saml_uid, provider):
31-
_logger.debug('Creating new Odoo user "%s" from SAML' % saml_uid)
24+
_logger.debug(f"Creating new Odoo user {saml_uid} from SAML")
3225
SudoUser = self.env["res.users"].sudo()
33-
new_user = SudoUser.create(
34-
{
35-
"name": saml_uid,
36-
"login": saml_uid,
37-
"saml_provider_id": provider,
38-
"password": "".join(random.sample(s, passlen)),
39-
"company_id": self.env["res.company"].sudo().browse(1).id,
40-
}
26+
values = {
27+
"name": saml_uid,
28+
"login": saml_uid,
29+
"saml_ids": [
30+
(0, 0, {"saml_provider_id": provider, "saml_uid": saml_uid}),
31+
],
32+
"company_id": self.env["res.company"].sudo().browse(1).id,
33+
}
34+
allow_saml_password = (
35+
self.env["ir.config_parameter"]
36+
.sudo()
37+
.get_param(ALLOW_SAML_UID_AND_PASSWORD, "False")
38+
)
39+
if safe_eval.safe_eval(allow_saml_password):
40+
values["password"] = "".join(random.sample(s, passlen))
41+
res = SudoUser.create(values)
42+
return res
43+
44+
def _auth_saml_signin(self, provider: int, validation: dict, saml_response) -> str:
45+
"""
46+
Overload to auto create a new user if configured to allow it.
47+
"""
48+
saml_uid = validation["user_id"]
49+
user_ids = self.env["res.users.saml"].search(
50+
[("saml_uid", "=", saml_uid), ("saml_provider_id", "=", provider)]
4151
)
42-
new_user.write({"saml_uid": saml_uid})
52+
if self.check_if_create_user(provider) and not user_ids:
53+
self.create_user(saml_uid, provider)
54+
return super()._auth_saml_signin(provider, validation, saml_response)

auth_saml_create_user/readme/CONTRIBUTORS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
- Larbi Gharib \<larbi.gharib@savoirfairelinux.com\>
55
- Pierre Gault \<pierre.gault@savoirfairelinux.com\>
66
- William Beverly \<william.beverly@savoirfairelinux.com\>
7+
8+
- [SMILE] (https://smile.eu/en):
9+
- Martin Deconinck \<martin.deconinck@smile.fr\>
10+
- Théo Martin \<theo.martin@smile.fr\>

auth_saml_create_user/security/ir.model.access.csv

Lines changed: 0 additions & 2 deletions
This file was deleted.

auth_saml_create_user/static/description/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ <h1 class="title">Auth SAML Create User</h1>
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370370
!! source digest: sha256:99e8fd5583907518e2d4a0ef800c952bf67fe884007baa8365c037da4ffa55b0
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-auth/tree/18.0/auth_saml_create_user"><img alt="OCA/server-auth" src="https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-auth-18-0/server-auth-18-0-auth_saml_create_user"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-auth&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-auth/tree/18.0/auth_saml_create_user"><img alt="OCA/server-auth" src="https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-auth-18-0/server-auth-18-0-auth_saml_create_user"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-auth&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373373
<p>This module extends the functionality of Auth SAML to support the
374374
automatic creation of SAML users when they don’t exist in odoo.</p>
375375
<p><strong>Table of contents</strong></p>
@@ -408,6 +408,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
408408
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
409409
<ul class="simple">
410410
<li>Savoir-faire Linux</li>
411+
<li>Smile</li>
411412
</ul>
412413
</div>
413414
<div class="section" id="contributors">
@@ -419,6 +420,11 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
419420
<li>Larbi Gharib &lt;<a class="reference external" href="mailto:larbi.gharib&#64;savoirfairelinux.com">larbi.gharib&#64;savoirfairelinux.com</a>&gt;</li>
420421
<li>Pierre Gault &lt;<a class="reference external" href="mailto:pierre.gault&#64;savoirfairelinux.com">pierre.gault&#64;savoirfairelinux.com</a>&gt;</li>
421422
<li>William Beverly &lt;<a class="reference external" href="mailto:william.beverly&#64;savoirfairelinux.com">william.beverly&#64;savoirfairelinux.com</a>&gt;</li>
423+
<li>[SMILE] (<a class="reference external" href="https://smile.eu/en">https://smile.eu/en</a>):<ul>
424+
<li>Martin Deconinck &lt;<a class="reference external" href="mailto:martin.deconinck&#64;smile.fr">martin.deconinck&#64;smile.fr</a>&gt;</li>
425+
<li>Théo Martin &lt;<a class="reference external" href="mailto:theo.martin&#64;smile.fr">theo.martin&#64;smile.fr</a>&gt;</li>
426+
</ul>
427+
</li>
422428
</ul>
423429
</div>
424430
<div class="section" id="other-credits">
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# © 2019 Savoir-faire Linux
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4-
from . import common
5-
from . import test_auth_saml_create_users
4+
from . import test_auth_saml_provider

0 commit comments

Comments
 (0)