Skip to content

Commit f6b721a

Browse files
committed
[FIX] auto-fix pre-commit
1 parent 4cc52b4 commit f6b721a

9 files changed

Lines changed: 66 additions & 43 deletions

File tree

auth_saml_create_user/README.rst

Lines changed: 13 additions & 4 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,18 +61,27 @@ 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>
74-
- Martin Deconinck <martin.deconinck@smile.fr>
75-
- Théo Martin <theo.martin@smile.fr>
80+
81+
- [SMILE] (https://smile.eu/en):
82+
83+
- Martin Deconinck <martin.deconinck@smile.fr>
84+
- Théo Martin <theo.martin@smile.fr>
7685

7786
Other credits
7887
-------------

auth_saml_create_user/__manifest__.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,16 @@
1111
"sequence": 20,
1212
"author": "Savoir-faire Linux, Odoo Community Association (OCA), Smile",
1313
"maintainers": ["eilst"],
14-
"description": """Auth SAML Auto create users
15-
16-
Allow to automatically create users when they authenticate with SAML.
17-
""",
1814
"website": "https://github.com/OCA/server-auth",
1915
"license": "AGPL-3",
2016
"depends": [
2117
"auth_saml",
2218
],
2319
"data": [
24-
'views/auth_saml.xml',
20+
"views/auth_saml.xml",
2521
],
26-
'demo': [],
27-
'test': [],
22+
"demo": [],
23+
"test": [],
2824
"auto_install": False,
2925
"installable": True,
3026
"application": False,
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# Copyright (C) 2010-2016 XCG Consulting <http://odoo.consulting>
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4-
from odoo import models, fields
4+
from odoo import fields, models
55

66

77
class AuthSamlProvider(models.Model):
8-
_inherit = 'auth.saml.provider'
8+
_inherit = "auth.saml.provider"
99

1010
create_user = fields.Boolean(
11-
string='Create User',
1211
default=True,
1312
)
Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,54 @@
11
# © 2019 Savoir-faire Linux
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4+
import logging
5+
import random
6+
47
from odoo import models
58
from odoo.tools import safe_eval
6-
from odoo.addons.auth_saml.models.ir_config_parameter import ALLOW_SAML_UID_AND_PASSWORD
7-
8-
import random
9-
import logging
109

10+
from odoo.addons.auth_saml.models.ir_config_parameter import ALLOW_SAML_UID_AND_PASSWORD
1111

1212
_logger = logging.getLogger(__name__)
1313
s = "abcdefghijklmnopqrstuvwxyz034567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?"
1414
passlen = 16
1515

1616

1717
class ResUsers(models.Model):
18-
_inherit = 'res.users'
18+
_inherit = "res.users"
1919

2020
def check_if_create_user(self, provider):
21-
return self.env['auth.saml.provider'].browse(provider).create_user
21+
return self.env["auth.saml.provider"].browse(provider).create_user
2222

2323
def create_user(self, saml_uid, provider):
24-
_logger.debug("Creating new Odoo user \"%s\" from SAML" % saml_uid)
25-
SudoUser = self.env['res.users'].sudo()
24+
_logger.debug(f"Creating new Odoo user {saml_uid} from SAML")
25+
SudoUser = self.env["res.users"].sudo()
2626
values = {
27-
'name': saml_uid,
28-
'login': saml_uid,
29-
'saml_ids': [(0, 0, {'saml_provider_id': provider, 'saml_uid': saml_uid}),],
30-
'company_id': self.env['res.company'].sudo().browse(1).id,
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,
3133
}
32-
allow_saml_password = self.env['ir.config_parameter'].sudo().get_param(ALLOW_SAML_UID_AND_PASSWORD, 'False')
34+
allow_saml_password = (
35+
self.env["ir.config_parameter"]
36+
.sudo()
37+
.get_param(ALLOW_SAML_UID_AND_PASSWORD, "False")
38+
)
3339
if safe_eval.safe_eval(allow_saml_password):
34-
values['password'] = "".join(random.sample(s, passlen))
40+
values["password"] = "".join(random.sample(s, passlen))
3541
res = SudoUser.create(values)
3642
return res
3743

3844
def _auth_saml_signin(self, provider: int, validation: dict, saml_response) -> str:
3945
"""
40-
Overload to auto create a new user if configured to allow it.
46+
Overload to auto create a new user if configured to allow it.
4147
"""
42-
saml_uid = validation['user_id']
48+
saml_uid = validation["user_id"]
4349
user_ids = self.env["res.users.saml"].search(
44-
[('saml_uid', '=', saml_uid), ('saml_provider_id', '=', provider)])
50+
[("saml_uid", "=", saml_uid), ("saml_provider_id", "=", provider)]
51+
)
4552
if self.check_if_create_user(provider) and not user_ids:
4653
self.create_user(saml_uid, provider)
4754
return super()._auth_saml_signin(provider, validation, saml_response)
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"

auth_saml_create_user/readme/CONTRIBUTORS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
- William Beverly \<william.beverly@savoirfairelinux.com\>
77

88
- [SMILE] (https://smile.eu/en):
9-
- Martin DECONINCK \<martin.deconinck@smile.fr\>
9+
- Martin Deconinck \<martin.deconinck@smile.fr\>
1010
- Théo Martin \<theo.martin@smile.fr\>

auth_saml_create_user/static/description/index.html

Lines changed: 5 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,9 +420,12 @@ <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>
422424
<li>Martin Deconinck &lt;<a class="reference external" href="mailto:martin.deconinck&#64;smile.fr">martin.deconinck&#64;smile.fr</a>&gt;</li>
423425
<li>Théo Martin &lt;<a class="reference external" href="mailto:theo.martin&#64;smile.fr">theo.martin&#64;smile.fr</a>&gt;</li>
424426
</ul>
427+
</li>
428+
</ul>
425429
</div>
426430
<div class="section" id="other-credits">
427431
<h2><a class="toc-backref" href="#toc-entry-6">Other credits</a></h2>

auth_saml_create_user/tests/test_auth_saml_provider.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# © 2019 Savoir-faire Linux
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4-
from odoo.addons.auth_saml.tests.test_pysaml import TestPySaml
54
from odoo.exceptions import AccessDenied
65

6+
from odoo.addons.auth_saml.tests.test_pysaml import TestPySaml
77

8-
class TestSamlCreateUser(TestPySaml):
98

9+
class TestSamlCreateUser(TestPySaml):
1010
def setUp(self):
1111
super().setUp()
1212

1313
def test_login_with_existing_user(self):
14-
15-
# update the existing user login, to avoid already existing user when creating a new one by SAML
14+
# Update the existing user login, to avoid already existing user
15+
# when creating a new one by SAML
1616
self.user.unlink()
1717

1818
redirect_url = self.saml_provider._get_auth_request()
@@ -22,7 +22,9 @@ def test_login_with_existing_user(self):
2222
self.assertEqual(200, response.status_code)
2323
unpacked_response = response._unpack()
2424

25-
self.assertFalse(self.env['res.users'].search([("login", "=", "test@example.com")]))
25+
self.assertFalse(
26+
self.env["res.users"].search([("login", "=", "test@example.com")])
27+
)
2628

2729
(database, login, token) = (
2830
self.env["res.users"]
@@ -33,7 +35,7 @@ def test_login_with_existing_user(self):
3335
)
3436

3537
# User is now created
36-
new_user = self.env['res.users'].search([("login", "=", "test@example.com")])
38+
new_user = self.env["res.users"].search([("login", "=", "test@example.com")])
3739
self.assertTrue(new_user)
3840

3941
# We should not be able to log in with the wrong token

auth_saml_create_user/views/auth_saml.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="UTF-8" ?>
22
<odoo>
33
<record id="view_saml_provider_form" model="ir.ui.view">
44
<field name="name">auth.saml.provider.form</field>
55
<field name="model">auth.saml.provider</field>
6-
<field name="inherit_id" ref="auth_saml.view_saml_provider_form"/>
6+
<field name="inherit_id" ref="auth_saml.view_saml_provider_form" />
77
<field name="arch" type="xml">
8-
<xpath expr="//field[@name='want_assertions_or_response_signed']" position="after">
9-
<field name="create_user"/>
8+
<xpath
9+
expr="//field[@name='want_assertions_or_response_signed']"
10+
position="after"
11+
>
12+
<field name="create_user" />
1013
</xpath>
1114
</field>
1215
</record>

0 commit comments

Comments
 (0)