Skip to content

Commit 2e57e7f

Browse files
committed
[MIG] users_ldap_groups: Migration to 18.0
1 parent 431b96e commit 2e57e7f

7 files changed

Lines changed: 75 additions & 49 deletions

File tree

users_ldap_groups/README.rst

Lines changed: 9 additions & 10 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
LDAP groups assignment
73
======================
@@ -17,17 +13,17 @@ LDAP groups assignment
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%2Fserver--auth-lightgray.png?logo=github
24-
:target: https://github.com/OCA/server-auth/tree/17.0/users_ldap_groups
20+
:target: https://github.com/OCA/server-auth/tree/18.0/users_ldap_groups
2521
:alt: OCA/server-auth
2622
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/server-auth-17-0/server-auth-17-0-users_ldap_groups
23+
:target: https://translation.odoo-community.org/projects/server-auth-18-0/server-auth-18-0-users_ldap_groups
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/server-auth&target_branch=17.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=18.0
3127
:alt: Try me on Runboat
3228

3329
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -79,7 +75,7 @@ Bug Tracker
7975
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-auth/issues>`_.
8076
In case of trouble, please check there if your issue has already been reported.
8177
If you spotted it first, help us to smash it by providing a detailed and welcomed
82-
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20users_ldap_groups%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
78+
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20users_ldap_groups%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
8379

8480
Do not contact contributors directly about support or help with technical issues.
8581

@@ -106,6 +102,9 @@ Contributors
106102
- Carolina Fernandez
107103

108104
- Dhara Solanki <dhara.solanki@initos.com>
105+
- Invitu <https://www.invitu.com>
106+
107+
- Cyril Vinh-Tung <cyril@invitu.com>
109108

110109
Maintainers
111110
-----------
@@ -120,6 +119,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
120119
mission is to support the collaborative development of Odoo features and
121120
promote its widespread use.
122121

123-
This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/17.0/users_ldap_groups>`_ project on GitHub.
122+
This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/18.0/users_ldap_groups>`_ project on GitHub.
124123

125124
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

users_ldap_groups/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
{
88
"name": "LDAP groups assignment",
9-
"version": "17.0.1.0.0",
9+
"version": "18.0.1.0.0",
1010
"depends": ["auth_ldap"],
1111
"author": "Therp BV, " "Odoo Community Association (OCA)",
1212
"website": "https://github.com/OCA/server-auth",
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
# Copyright 2018 Therp BV <https://therp.nl>
22
# Copyright 2018 Brainbean Apps <https://brainbeanapps.com>
3+
# Copyright 2026 Invitu <https://www.invitu.com>
34
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
4-
from odoo import SUPERUSER_ID, api, models, registry
5+
from odoo import SUPERUSER_ID, api, models
56

67

78
class ResUsers(models.Model):
89
_inherit = "res.users"
910

1011
@classmethod
11-
def _login(cls, db, login, password, user_agent_env):
12-
user_id = super()._login(db, login, password, user_agent_env)
13-
if not user_id:
14-
return user_id
15-
with registry(db).cursor() as cr:
12+
def _login(cls, db, credential, user_agent_env):
13+
auth_info = super()._login(db, credential, user_agent_env)
14+
if not auth_info:
15+
return auth_info
16+
with cls.pool.cursor() as cr:
17+
login = credential["login"]
1618
env = api.Environment(cr, SUPERUSER_ID, {})
17-
user = env["res.users"].browse(user_id)
19+
user = env["res.users"].browse(auth_info["uid"])
1820
# check if this user came from ldap, rerun get_or_create_user in
1921
# this case to apply ldap groups if necessary
2022
ldaps = user.company_id.ldaps
2123
if user.active and any(ldaps.mapped("only_ldap_groups")):
2224
for conf in ldaps._get_ldap_dicts():
23-
entry = ldaps._authenticate(conf, login, password)
25+
entry = ldaps._authenticate(conf, login, credential["password"])
2426
if entry:
2527
ldaps._get_or_create_user(conf, login, entry)
2628
break
27-
return user_id
29+
return auth_info

users_ldap_groups/readme/CONTRIBUTORS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
- João Marques
77
- Carolina Fernandez
88
- Dhara Solanki \<<dhara.solanki@initos.com>\>
9+
- Invitu \<<https://www.invitu.com>\>
10+
- Cyril Vinh-Tung \<<cyril@invitu.com>\>

users_ldap_groups/static/description/index.html

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6-
<title>README.rst</title>
6+
<title>LDAP groups assignment</title>
77
<style type="text/css">
88

99
/*
@@ -360,21 +360,16 @@
360360
</style>
361361
</head>
362362
<body>
363-
<div class="document">
363+
<div class="document" id="ldap-groups-assignment">
364+
<h1 class="title">LDAP groups assignment</h1>
364365

365-
366-
<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
367-
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
368-
</a>
369-
<div class="section" id="ldap-groups-assignment">
370-
<h1>LDAP groups assignment</h1>
371366
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
372367
!! This file is generated by oca-gen-addon-readme !!
373368
!! changes will be overwritten. !!
374369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375370
!! source digest: sha256:5538d0664000dd276401538dfe2ecc07df73df425f496375b7ff738bba905479
376371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<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/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-auth/tree/17.0/users_ldap_groups"><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-17-0/server-auth-17-0-users_ldap_groups"><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=17.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/users_ldap_groups"><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-users_ldap_groups"><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>
378373
<p><a class="reference external image-reference" href="https://www.gnu.org/licenses/agpl"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a></p>
379374
<p>Adds user accounts to groups based on rules defined by the
380375
administrator.</p>
@@ -392,7 +387,7 @@ <h1>LDAP groups assignment</h1>
392387
</ul>
393388
</div>
394389
<div class="section" id="usage">
395-
<h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
390+
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
396391
<p>Define mappings in Settings / General Settings / Integrations / LDAP
397392
Authentication / LDAP Server</p>
398393
<p>Decide whether you want only groups mapped from LDAP (Only LDAP groups
@@ -414,23 +409,23 @@ <h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
414409
value of the user’s LDAP record’s attribute named attribute.</p>
415410
</div>
416411
<div class="section" id="bug-tracker">
417-
<h2><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h2>
412+
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
418413
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-auth/issues">GitHub Issues</a>.
419414
In case of trouble, please check there if your issue has already been reported.
420415
If you spotted it first, help us to smash it by providing a detailed and welcomed
421-
<a class="reference external" href="https://github.com/OCA/server-auth/issues/new?body=module:%20users_ldap_groups%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
416+
<a class="reference external" href="https://github.com/OCA/server-auth/issues/new?body=module:%20users_ldap_groups%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
422417
<p>Do not contact contributors directly about support or help with technical issues.</p>
423418
</div>
424419
<div class="section" id="credits">
425-
<h2><a class="toc-backref" href="#toc-entry-3">Credits</a></h2>
420+
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
426421
<div class="section" id="authors">
427-
<h3><a class="toc-backref" href="#toc-entry-4">Authors</a></h3>
422+
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
428423
<ul class="simple">
429424
<li>Therp BV</li>
430425
</ul>
431426
</div>
432427
<div class="section" id="contributors">
433-
<h3><a class="toc-backref" href="#toc-entry-5">Contributors</a></h3>
428+
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
434429
<ul class="simple">
435430
<li>Holger Brunn &lt;<a class="reference external" href="mailto:hbrunn&#64;therp.nl">hbrunn&#64;therp.nl</a>&gt;</li>
436431
<li>Giacomo Spettoli &lt;<a class="reference external" href="mailto:giacomo.spettoli&#64;gmail.com">giacomo.spettoli&#64;gmail.com</a>&gt;</li>
@@ -444,22 +439,25 @@ <h3><a class="toc-backref" href="#toc-entry-5">Contributors</a></h3>
444439
</ul>
445440
</li>
446441
<li>Dhara Solanki &lt;<a class="reference external" href="mailto:dhara.solanki&#64;initos.com">dhara.solanki&#64;initos.com</a>&gt;</li>
442+
<li>Invitu &lt;<a class="reference external" href="https://www.invitu.com">https://www.invitu.com</a>&gt;<ul>
443+
<li>Cyril Vinh-Tung &lt;<a class="reference external" href="mailto:cyril&#64;invitu.com">cyril&#64;invitu.com</a>&gt;</li>
444+
</ul>
445+
</li>
447446
</ul>
448447
</div>
449448
<div class="section" id="maintainers">
450-
<h3><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h3>
449+
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
451450
<p>This module is maintained by the OCA.</p>
452451
<a class="reference external image-reference" href="https://odoo-community.org">
453452
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
454453
</a>
455454
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
456455
mission is to support the collaborative development of Odoo features and
457456
promote its widespread use.</p>
458-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-auth/tree/17.0/users_ldap_groups">OCA/server-auth</a> project on GitHub.</p>
457+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-auth/tree/18.0/users_ldap_groups">OCA/server-auth</a> project on GitHub.</p>
459458
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
460459
</div>
461460
</div>
462461
</div>
463-
</div>
464462
</body>
465463
</html>

users_ldap_groups/tests/test_users_ldap_groups.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from contextlib import contextmanager
55
from unittest import mock
66

7+
from odoo import _
78
from odoo.exceptions import UserError
89
from odoo.tests.common import TransactionCase
910

@@ -47,7 +48,7 @@ def unbind_s(self):
4748

4849
def __getattr__(self, name):
4950
def wrapper():
50-
raise Exception("'%s' is not mocked" % name)
51+
raise Exception(_("%s is not mocked") % name)
5152

5253
return wrapper
5354

@@ -128,11 +129,17 @@ def test_users_ldap_groups_only_true(self):
128129
self.env["res.users"]
129130
.sudo()
130131
.authenticate(
131-
self.env.cr.dbname, "users_ldap_groups-username", "password", {}
132+
self.env.cr.dbname,
133+
{
134+
"login": "users_ldap_groups-username",
135+
"password": "password",
136+
"type": "password",
137+
},
138+
{},
132139
)
133140
)
134141
# this asserts group mappings from demo data
135-
user = self.env["res.users"].sudo().browse(user_id)
142+
user = self.env["res.users"].sudo().browse(user_id["uid"])
136143
groups = user.groups_id
137144
self.assertIn(self.group_contains, groups)
138145
self.assertIn(self.group_user, groups)
@@ -176,17 +183,23 @@ def test_users_ldap_groups_only_false(self):
176183
self.env["res.users"]
177184
.sudo()
178185
.authenticate(
179-
self.env.cr.dbname, "users_ldap_groups-username", "password", {}
186+
self.env.cr.dbname,
187+
{
188+
"login": "users_ldap_groups-username",
189+
"password": "password",
190+
"type": "password",
191+
},
192+
{},
180193
)
181194
)
182195
# this asserts group mappings from demo data
183-
user = self.env["res.users"].sudo().browse(user_id)
196+
user = self.env["res.users"].sudo().browse(user_id["uid"])
184197
groups = user.groups_id
185198
self.assertIn(self.group_contains, groups)
186199
self.assertIn(self.group_equals, groups)
187200
self.assertGreater(len(groups), 2) # user should keep default groups
188201

189-
def _test_users_ldap_groups_not_user_type(self):
202+
def test_users_ldap_groups_not_user_type(self):
190203
self._create_ldap_config(
191204
groups=[
192205
{
@@ -232,7 +245,13 @@ def _test_users_ldap_groups_not_user_type(self):
232245
):
233246
with self.assertRaises(UserError):
234247
self.env["res.users"].sudo().authenticate(
235-
self.env.cr.dbname, "users_ldap_groups-username", "password", {}
248+
self.env.cr.dbname,
249+
{
250+
"login": "users_ldap_groups-username",
251+
"password": "password",
252+
"type": "password",
253+
},
254+
{},
236255
)
237256

238257
def test_users_ldap_groups_ldap_returns_binary_data(self):
@@ -293,11 +312,17 @@ def test_users_ldap_groups_ldap_returns_binary_data(self):
293312
self.env["res.users"]
294313
.sudo()
295314
.authenticate(
296-
self.env.cr.dbname, "users_ldap_groups-username", "password", {}
315+
self.env.cr.dbname,
316+
{
317+
"login": "users_ldap_groups-username",
318+
"password": "password",
319+
"type": "password",
320+
},
321+
{},
297322
)
298323
)
299324
# this asserts group mappings from demo data
300-
user = self.env["res.users"].sudo().browse(user_id)
325+
user = self.env["res.users"].sudo().browse(user_id["uid"])
301326
groups = user.groups_id
302327
self.assertIn(self.group_contains, groups)
303328
self.assertIn(self.group_user, groups)

users_ldap_groups/views/res_company_ldap_views.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<field name="only_ldap_groups" />
1616
<label for="group_mapping_ids" />
1717
<field name="group_mapping_ids" nolabel="1">
18-
<tree editable="bottom">
18+
<list editable="bottom">
1919
<field
2020
name="ldap_attribute"
2121
required="operator != 'query'"
@@ -24,7 +24,7 @@
2424
<field name="operator" />
2525
<field name="value" />
2626
<field name="group_id" />
27-
</tree>
27+
</list>
2828
</field>
2929
</group>
3030
</xpath>

0 commit comments

Comments
 (0)