From f43e58440e1bc21e99e5a037b5ea0f1c348acdff Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Mon, 20 Jun 2016 12:38:17 +0200 Subject: [PATCH] [ADD] New module partner_firstname_auth_ldap --- partner_firstname_auth_ldap/README.rst | 54 +++++++++++++ partner_firstname_auth_ldap/__init__.py | 1 + partner_firstname_auth_ldap/__openerp__.py | 17 ++++ .../models/__init__.py | 1 + .../models/res_company_ldap.py | 30 +++++++ .../static/description/icon.svg | 79 +++++++++++++++++++ partner_firstname_auth_ldap/tests/__init__.py | 1 + .../tests/test_res_company_ldap.py | 63 +++++++++++++++ .../odoo_addons/__init__.py | 1 + .../odoo_addons/partner_firstname_auth_ldap | 1 + setup/partner_firstname_auth_ldap/setup.py | 6 ++ 11 files changed, 254 insertions(+) create mode 100644 partner_firstname_auth_ldap/README.rst create mode 100644 partner_firstname_auth_ldap/__init__.py create mode 100644 partner_firstname_auth_ldap/__openerp__.py create mode 100644 partner_firstname_auth_ldap/models/__init__.py create mode 100644 partner_firstname_auth_ldap/models/res_company_ldap.py create mode 100644 partner_firstname_auth_ldap/static/description/icon.svg create mode 100644 partner_firstname_auth_ldap/tests/__init__.py create mode 100644 partner_firstname_auth_ldap/tests/test_res_company_ldap.py create mode 100644 setup/partner_firstname_auth_ldap/odoo_addons/__init__.py create mode 120000 setup/partner_firstname_auth_ldap/odoo_addons/partner_firstname_auth_ldap create mode 100644 setup/partner_firstname_auth_ldap/setup.py diff --git a/partner_firstname_auth_ldap/README.rst b/partner_firstname_auth_ldap/README.rst new file mode 100644 index 000000000..a62e581d3 --- /dev/null +++ b/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 +`_. 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 `_. + +Contributors +------------ + +* Laurent Mignon + +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. diff --git a/partner_firstname_auth_ldap/__init__.py b/partner_firstname_auth_ldap/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/partner_firstname_auth_ldap/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/partner_firstname_auth_ldap/__openerp__.py b/partner_firstname_auth_ldap/__openerp__.py new file mode 100644 index 000000000..e4bfef1e7 --- /dev/null +++ b/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', + ], +} diff --git a/partner_firstname_auth_ldap/models/__init__.py b/partner_firstname_auth_ldap/models/__init__.py new file mode 100644 index 000000000..1eca6cbff --- /dev/null +++ b/partner_firstname_auth_ldap/models/__init__.py @@ -0,0 +1 @@ +from . import res_company_ldap diff --git a/partner_firstname_auth_ldap/models/res_company_ldap.py b/partner_firstname_auth_ldap/models/res_company_ldap.py new file mode 100644 index 000000000..1610a9602 --- /dev/null +++ b/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 diff --git a/partner_firstname_auth_ldap/static/description/icon.svg b/partner_firstname_auth_ldap/static/description/icon.svg new file mode 100644 index 000000000..a7a26d093 --- /dev/null +++ b/partner_firstname_auth_ldap/static/description/icon.svg @@ -0,0 +1,79 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/partner_firstname_auth_ldap/tests/__init__.py b/partner_firstname_auth_ldap/tests/__init__.py new file mode 100644 index 000000000..bf38ba451 --- /dev/null +++ b/partner_firstname_auth_ldap/tests/__init__.py @@ -0,0 +1 @@ +from . import test_res_company_ldap diff --git a/partner_firstname_auth_ldap/tests/test_res_company_ldap.py b/partner_firstname_auth_ldap/tests/test_res_company_ldap.py new file mode 100644 index 000000000..6b743dda7 --- /dev/null +++ b/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) diff --git a/setup/partner_firstname_auth_ldap/odoo_addons/__init__.py b/setup/partner_firstname_auth_ldap/odoo_addons/__init__.py new file mode 100644 index 000000000..de40ea7ca --- /dev/null +++ b/setup/partner_firstname_auth_ldap/odoo_addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/partner_firstname_auth_ldap/odoo_addons/partner_firstname_auth_ldap b/setup/partner_firstname_auth_ldap/odoo_addons/partner_firstname_auth_ldap new file mode 120000 index 000000000..0bac5312c --- /dev/null +++ b/setup/partner_firstname_auth_ldap/odoo_addons/partner_firstname_auth_ldap @@ -0,0 +1 @@ +../../../partner_firstname_auth_ldap \ No newline at end of file diff --git a/setup/partner_firstname_auth_ldap/setup.py b/setup/partner_firstname_auth_ldap/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/partner_firstname_auth_ldap/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)