Browse Source
[ADD] users_ldap_populate: migrate functionality added to 6.1 after 7.0 port (#408)
[ADD] users_ldap_populate: migrate functionality added to 6.1 after 7.0 port (#408)
* [ADD] possibility to deactivate users not found in ldap while populating * [IMP] search in ldap for every possibly unknown user to be really sure it actually is not present there * [FIX] refactoring mistake * [IMP] don't use self.query() to be sure to be stopped if any error occurs * [IMP] remove superfluous check as exceptions are not supressed any more * [FIX] typo in variable name [FIX] handle unicode characters in search filter [FIX] search for user's login, not her name * [FIX] don't pass user_name as assertion_value * [FIX] don't deactivate users if we got a non-existent ldap configuration * [FIX] flake8 * [FIX] more flake8 * [FIX] make form usable * [FIX] name clash between function and field * [ADD] testpull/1049/head
Holger Brunn
7 years ago
committed by
Alexandre Fayolle
8 changed files with 254 additions and 26 deletions
-
72users_ldap_populate/README.rst
-
17users_ldap_populate/__openerp__.py
-
10users_ldap_populate/model/populate_wizard.py
-
100users_ldap_populate/model/users_ldap.py
-
4users_ldap_populate/tests/__init__.py
-
70users_ldap_populate/tests/test_users_ldap_populate.py
-
2users_ldap_populate/view/populate_wizard.xml
-
5users_ldap_populate/view/users_ldap.xml
@ -0,0 +1,72 @@ |
|||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg |
|||
:alt: License: AGPL-3 |
|||
|
|||
============= |
|||
LDAP Populate |
|||
============= |
|||
|
|||
This module allows to prepopulate the user database with all entries in the |
|||
LDAP database. |
|||
|
|||
Installation |
|||
============ |
|||
|
|||
In order to schedule the population of the user database on a regular basis, |
|||
create a new scheduled action with the following properties: |
|||
|
|||
- Object: res.company.ldap |
|||
- Function: action_populate |
|||
- Arguments: ``[res.company.ldap.id]`` |
|||
|
|||
Substitute ``res.company.ldap.id`` with the actual id of the res.company.ldap |
|||
object you want to query. |
|||
|
|||
Usage |
|||
===== |
|||
|
|||
To use this module, you need to: |
|||
|
|||
* go to your company settings |
|||
* open your LDAP configuration |
|||
* click the button ``Populate`` |
|||
|
|||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas |
|||
:alt: Try me on Runbot |
|||
:target: https://runbot.odoo-community.org/runbot/149/8.0 |
|||
|
|||
For further information, please visit: |
|||
|
|||
* https://www.odoo.com/forum/help-1 |
|||
|
|||
Bug Tracker |
|||
=========== |
|||
|
|||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/users_ldap_populate/issues>`_. |
|||
In case of trouble, please check there if your issue has already been reported. |
|||
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback |
|||
`here <https://github.com/OCA/users_ldap_populate/issues/new?body=module:%20users_ldap_populate%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
|||
|
|||
Credits |
|||
======= |
|||
|
|||
Contributors |
|||
------------ |
|||
|
|||
* Holger Brunn <hbrunn@therp.nl> |
|||
* Daniel Reis <dgreis@sapo.pt> |
|||
* Stefan Rijnhart <stefan@opener.am> |
|||
|
|||
Maintainer |
|||
---------- |
|||
|
|||
.. image:: https://odoo-community.org/logo.png |
|||
:alt: Odoo Community Association |
|||
:target: https://odoo-community.org |
|||
|
|||
This module is maintained by the OCA. |
|||
|
|||
OCA, or the Odoo Community Association, is a nonprofit organization whose |
|||
mission is to support the collaborative development of Odoo features and |
|||
promote its widespread use. |
|||
|
|||
To contribute to this module, please visit https://odoo-community.org. |
@ -0,0 +1,4 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2016 Therp BV <http://therp.nl> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
from . import test_users_ldap_populate |
@ -0,0 +1,70 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2016 Therp BV <http://therp.nl> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
from openerp.tests.common import TransactionCase |
|||
from contextlib import contextmanager |
|||
|
|||
|
|||
class patch_ldap_connection(object): |
|||
def __init__(self, results): |
|||
self.results = results |
|||
|
|||
def simple_bind_s(self, user, password): |
|||
return True |
|||
|
|||
def search_st(self, base, scope, ldap_filter, attributes, timeout=None): |
|||
if ldap_filter == '(uid=*)': |
|||
return self.results |
|||
else: |
|||
return [] |
|||
|
|||
def unbind(self): |
|||
return True |
|||
|
|||
|
|||
@contextmanager |
|||
def patch_ldap(self, results): |
|||
""" defuse ldap functions to return fake entries instead of talking to a |
|||
server. Use this in your own ldap related tests """ |
|||
import ldap |
|||
original_initialize = ldap.initialize |
|||
|
|||
def initialize(uri): |
|||
return patch_ldap_connection(results) |
|||
ldap.initialize = initialize |
|||
yield |
|||
ldap.initialize = original_initialize |
|||
|
|||
|
|||
def get_fake_ldap(self): |
|||
company = self.env.ref('base.main_company') |
|||
company.write({ |
|||
'ldaps': [(0, 0, { |
|||
'ldap_server': 'fake', |
|||
'ldap_port': 'fake', |
|||
'ldap_filter': '(uid=%s)', |
|||
'ldap_base': 'fake', |
|||
'deactivate_unknown_users': True, |
|||
'no_deactivate_user_ids': [(6, 0, [ |
|||
self.env.ref('base.user_root').id, |
|||
])], |
|||
})], |
|||
}) |
|||
return company.ldaps.filtered( |
|||
lambda x: x.ldap_server == 'fake' |
|||
) |
|||
|
|||
|
|||
class TestUsersLdapPopulate(TransactionCase): |
|||
def test_users_ldap_populate(self): |
|||
with patch_ldap(self, [('DN=fake', { |
|||
'cn': ['fake'], |
|||
'uid': ['fake'], |
|||
'mail': ['fake@fakery.com'], |
|||
})]): |
|||
get_fake_ldap(self).populate_wizard() |
|||
self.assertFalse(self.env.ref('base.user_demo').active) |
|||
self.assertTrue(self.env.ref('base.user_root').active) |
|||
self.assertTrue(self.env['res.users'].search([ |
|||
('login', '=', 'fake') |
|||
])) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue