Browse Source

[ADD] New module partner_firstname_auth_ldap

pull/282/head
Laurent Mignon (ACSONE) 9 years ago
parent
commit
f43e58440e
  1. 54
      partner_firstname_auth_ldap/README.rst
  2. 1
      partner_firstname_auth_ldap/__init__.py
  3. 17
      partner_firstname_auth_ldap/__openerp__.py
  4. 1
      partner_firstname_auth_ldap/models/__init__.py
  5. 30
      partner_firstname_auth_ldap/models/res_company_ldap.py
  6. 79
      partner_firstname_auth_ldap/static/description/icon.svg
  7. 1
      partner_firstname_auth_ldap/tests/__init__.py
  8. 63
      partner_firstname_auth_ldap/tests/test_res_company_ldap.py
  9. 1
      setup/partner_firstname_auth_ldap/odoo_addons/__init__.py
  10. 1
      setup/partner_firstname_auth_ldap/odoo_addons/partner_firstname_auth_ldap
  11. 6
      setup/partner_firstname_auth_ldap/setup.py

54
partner_firstname_auth_ldap/README.rst

@ -0,0 +1,54 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
===========================
Partner Firstname Auth Ldap
===========================
Fill firstname and lastname for partners imported from ldap.
Usage
=====
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/134/9.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/{project_repo}/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.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Laurent Mignon <laurent.mignon@acsone.eu>
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.

1
partner_firstname_auth_ldap/__init__.py

@ -0,0 +1 @@
from . import models

17
partner_firstname_auth_ldap/__openerp__.py

@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Partner Firstname Auth Ldap',
'summary': """
Fill firstname and lastname for partners imported from ldap""",
'version': '9.0.1.0.0',
'license': 'AGPL-3',
'author': 'ACSONE SA/NV,Odoo Community Association (OCA)',
'website': 'https://acsone.eu/',
'depends': [
'auth_ldap',
'partner_firstname',
],
}

1
partner_firstname_auth_ldap/models/__init__.py

@ -0,0 +1 @@
from . import res_company_ldap

30
partner_firstname_auth_ldap/models/res_company_ldap.py

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import api, models
class ResCompanyLdap(models.Model):
_inherit = 'res.company.ldap'
@api.model
def map_ldap_attributes(self, conf, login, ldap_entry):
"""
Compose values for a new resource of model res_users,
based upon the retrieved ldap entry and the LDAP settings.
:param dict conf: LDAP configuration
:param login: the new user's login
:param tuple ldap_entry: single LDAP result (dn, attrs)
:return: parameters for a new resource of model res_users
:rtype: dict
"""
values = super(ResCompanyLdap, self).map_ldap_attributes(
conf, login, ldap_entry)
values.update({
'lastname': ldap_entry[1]['cn'][0],
'firstname': ldap_entry[1]['givenName'][0],
'email': ldap_entry[1]['mail'][0],
})
return values

79
partner_firstname_auth_ldap/static/description/icon.svg
File diff suppressed because it is too large
View File

1
partner_firstname_auth_ldap/tests/__init__.py

@ -0,0 +1 @@
from . import test_res_company_ldap

63
partner_firstname_auth_ldap/tests/test_res_company_ldap.py

@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import mock
from openerp.tests.common import TransactionCase
class TestResCompanyLdap(TransactionCase):
def setUp(self):
super(TestResCompanyLdap, self).setUp()
res_company_ldap_model = self.env['res.company.ldap']
self.res_company_ldap = res_company_ldap_model.create({
'company': self.ref('base.main_company'),
'ldap_server': 'ldap.server.test',
'ldap_filter': 'uid=%s',
'ldap_base': 'ou=users,dc=acsone,dc=test',
'create_user': True,
})
def test_user_create_from_ldap_bind(self):
res_users = self.env['res.users']
domain = [("firstname", "=", "Laurent"),
("lastname", "=", "Mignon"),
("email", "=", "laurent.mignon@acsone.eu")]
users = res_users.search(domain)
self.assertEquals(0, len(users))
with mock.patch("openerp.addons.auth_ldap.users_ldap.CompanyLDAP."
"authenticate") as authenticate:
authenticate.return_value = (
'uid=acsone,ou=users,dc=acsone,dc=test',
{'mailQuotaSize': ['0'],
'displayName': ['Acsone Ldap'],
'uid': ['acsone'],
'objectClass': ['top',
'person',
'organizationalPerson',
'inetOrgPerson',
'posixAccount',
'qmailUser'],
'loginShell': ['/sbin/nologin'],
'userPassword': ['{SSHA}wyz=='],
'uidNumber': ['5153'],
'accountStatus': ['active'],
'gidNumber': ['5000'],
'gecos': ['Acsone Ldap'],
'sn': ['Mignon'],
'homeDirectory': ['/home/acsonelmi'],
'mail': ['laurent.mignon@acsone.eu'],
'givenName': ['Laurent'],
'cn': ['Mignon']}
)
conf = self.res_company_ldap.get_ldap_dicts()[0]
entry = self.res_company_ldap.authenticate(
conf, "acsone", "pwd")
self.assertTrue(entry)
user_id = self.res_company_ldap.get_or_create_user(
conf, "acsone", entry)
self.assertTrue(user_id)
users = res_users.search(domain)
self.assertEquals(1, len(users))
self.assertEquals(user_id, users[0].id)

1
setup/partner_firstname_auth_ldap/odoo_addons/__init__.py

@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)

1
setup/partner_firstname_auth_ldap/odoo_addons/partner_firstname_auth_ldap

@ -0,0 +1 @@
../../../partner_firstname_auth_ldap

6
setup/partner_firstname_auth_ldap/setup.py

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Loading…
Cancel
Save