Skip to content

Commit

Permalink
[MIG] users_ldap_groups: Migration to 12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-pelykh authored and hbrunn committed Dec 6, 2018
1 parent 1decb0e commit 143a449
Show file tree
Hide file tree
Showing 21 changed files with 734 additions and 149 deletions.
68 changes: 51 additions & 17 deletions users_ldap_groups/README.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3

======================
LDAP groups assignment
======================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github
:target: https://github.com/OCA/server-auth/tree/12.0/users_ldap_groups
:alt: OCA/server-auth
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-auth-12-0/server-auth-12-0-users_ldap_groups
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/251/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

Adds user accounts to groups based on rules defined by the administrator.

**Table of contents**

.. contents::
:local:

Usage
=====

Define mappings in Settings / General Settings / LDAP Parameters

Decide whether you want only groups mapped from ldap (`Only ldap groups` checked) or a mix of manually set groups and ldap groups (`Only ldap groups` unchecked). Setting this to 'no' will result in users never losing privileges when you remove them from a ldap group, so that's a potential security issue. It is still the default to prevent losing group information by accident.
Decide whether you want only groups mapped from LDAP (`Only LDAP groups` checked) or a mix of manually set groups and LDAP groups (`Only LDAP groups` unchecked). Setting this to 'no' will result in users never losing privileges when you remove them from a LDAP group, so that's a potential security issue. It is still the default to prevent losing group information by accident.

For active directory, use LDAP attribute 'memberOf' and operator 'contains'. Fill in the DN of the windows group as value and choose an Odoo group users with this windows group are to be assigned to.

Expand All @@ -21,42 +51,46 @@ For posix accounts, use operator 'query' and a value like::

The operator query matches if the filter in value returns something, and value
can contain ``$attribute`` which will be replaced by the first value of the
user's ldap record's attribute named `attribute`.
user's LDAP record's attribute named `attribute`.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-auth/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/server-tools/issues/new?body=module:%20{module_name}%0Aversion:%20{version}%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20users_ldap_groups%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Images
------
Authors
~~~~~~~

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
* Therp BV

Contributors
------------
~~~~~~~~~~~~

* Holger Brunn <[email protected]>
* Giacomo Spettoli <[email protected]>
* Alexey Pelykh <[email protected]>

Maintainers
~~~~~~~~~~~

Maintainer
----------
This module is maintained by the OCA.

.. 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.
This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/12.0/users_ldap_groups>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 0 additions & 1 deletion users_ldap_groups/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2012-2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import models
33 changes: 20 additions & 13 deletions users_ldap_groups/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
# -*- coding: utf-8 -*-
# Copyright 2012-2018 Therp BV <https://therp.nl>
# Copyright 2018 Brainbean Apps <https://brainbeanapps.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "LDAP groups assignment",
"version": "10.0.0.0.0",
"depends": ["auth_ldap"],
"author": "Therp BV, Odoo Community Association (OCA)",
"license": "AGPL-3",
"summary": "Adds user accounts to groups based on rules defined "
"by the administrator.",
"category": "Authentication",
"data": [
'views/base_config_settings.xml',
'name': 'LDAP groups assignment',
'version': '12.0.1.0.0',
'depends': [
'auth_ldap',
],
'author':
'Therp BV, '
'Odoo Community Association (OCA)',
'license': 'AGPL-3',
'summary':
'Adds user accounts to groups based on rules defined '
'by the administrator.',
'category': 'Authentication',
'data': [
'views/res_company_ldap_views.xml',
'security/ir.model.access.csv',
],
"external_dependencies": {
'python': ['ldap'],
'external_dependencies': {
'python': [
'ldap'
],
},
}
6 changes: 3 additions & 3 deletions users_ldap_groups/i18n/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ msgstr "Erstellt am:"

#. module: users_ldap_groups
#: model:ir.model.fields,help:users_ldap_groups.field_res_company_ldap_group_mapping_ids
msgid "Define how Odoo groups are assigned to ldap users"
msgid "Define how Odoo groups are assigned to LDAP users"
msgstr ""

#. module: users_ldap_groups
Expand Down Expand Up @@ -91,7 +91,7 @@ msgid "Last Updated on"
msgstr "Zuletzt aktualisiert am"

#. module: users_ldap_groups
#: model:ir.ui.view,arch_db:users_ldap_groups.company_form_view
#: model:ir.ui.view,arch_db:users_ldap_groups.view_ldap_installer_form
msgid "Map User Groups"
msgstr ""

Expand All @@ -102,7 +102,7 @@ msgstr ""

#. module: users_ldap_groups
#: model:ir.model.fields,field_description:users_ldap_groups.field_res_company_ldap_only_ldap_groups
msgid "Only ldap groups"
msgid "Only LDAP groups"
msgstr ""

#. module: users_ldap_groups
Expand Down
6 changes: 3 additions & 3 deletions users_ldap_groups/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ msgstr "Creado en"

#. module: users_ldap_groups
#: model:ir.model.fields,help:users_ldap_groups.field_res_company_ldap_group_mapping_ids
msgid "Define how Odoo groups are assigned to ldap users"
msgid "Define how Odoo groups are assigned to LDAP users"
msgstr ""

#. module: users_ldap_groups
Expand Down Expand Up @@ -91,7 +91,7 @@ msgid "Last Updated on"
msgstr "Última actualización en"

#. module: users_ldap_groups
#: model:ir.ui.view,arch_db:users_ldap_groups.company_form_view
#: model:ir.ui.view,arch_db:users_ldap_groups.view_ldap_installer_form
msgid "Map User Groups"
msgstr ""

Expand All @@ -102,7 +102,7 @@ msgstr ""

#. module: users_ldap_groups
#: model:ir.model.fields,field_description:users_ldap_groups.field_res_company_ldap_only_ldap_groups
msgid "Only ldap groups"
msgid "Only LDAP groups"
msgstr ""

#. module: users_ldap_groups
Expand Down
6 changes: 3 additions & 3 deletions users_ldap_groups/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ msgstr "Créé le"

#. module: users_ldap_groups
#: model:ir.model.fields,help:users_ldap_groups.field_res_company_ldap_group_mapping_ids
msgid "Define how Odoo groups are assigned to ldap users"
msgid "Define how Odoo groups are assigned to LDAP users"
msgstr ""

#. module: users_ldap_groups
Expand Down Expand Up @@ -91,7 +91,7 @@ msgid "Last Updated on"
msgstr "Dernière mise à jour le"

#. module: users_ldap_groups
#: model:ir.ui.view,arch_db:users_ldap_groups.company_form_view
#: model:ir.ui.view,arch_db:users_ldap_groups.view_ldap_installer_form
msgid "Map User Groups"
msgstr ""

Expand All @@ -102,7 +102,7 @@ msgstr ""

#. module: users_ldap_groups
#: model:ir.model.fields,field_description:users_ldap_groups.field_res_company_ldap_only_ldap_groups
msgid "Only ldap groups"
msgid "Only LDAP groups"
msgstr ""

#. module: users_ldap_groups
Expand Down
6 changes: 3 additions & 3 deletions users_ldap_groups/i18n/pt_BR.po
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ msgstr "Criado em"
#. module: users_ldap_groups
#: model:ir.model.fields,help:users_ldap_groups.field_res_company_ldap_group_mapping_ids
#, fuzzy
msgid "Define how Odoo groups are assigned to ldap users"
msgid "Define how Odoo groups are assigned to LDAP users"
msgstr "Define como grupos OpenERP são aribuídos aos usuários ldap"

#. module: users_ldap_groups
Expand Down Expand Up @@ -97,7 +97,7 @@ msgid "Last Updated on"
msgstr "Última atualização em"

#. module: users_ldap_groups
#: model:ir.ui.view,arch_db:users_ldap_groups.company_form_view
#: model:ir.ui.view,arch_db:users_ldap_groups.view_ldap_installer_form
msgid "Map User Groups"
msgstr "Mapear Grupos de Usuários"

Expand All @@ -109,7 +109,7 @@ msgstr "Apenas grupos ldap"

#. module: users_ldap_groups
#: model:ir.model.fields,field_description:users_ldap_groups.field_res_company_ldap_only_ldap_groups
msgid "Only ldap groups"
msgid "Only LDAP groups"
msgstr "Apenas grupos ldap"

#. module: users_ldap_groups
Expand Down
6 changes: 3 additions & 3 deletions users_ldap_groups/i18n/sl.po
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ msgstr "Ustvarjeno"
#. module: users_ldap_groups
#: model:ir.model.fields,help:users_ldap_groups.field_res_company_ldap_group_mapping_ids
#, fuzzy
msgid "Define how Odoo groups are assigned to ldap users"
msgid "Define how Odoo groups are assigned to LDAP users"
msgstr "Določi način dodeljevanja OpenERP skupin LDAP uporabnikom"

#. module: users_ldap_groups
Expand Down Expand Up @@ -98,7 +98,7 @@ msgid "Last Updated on"
msgstr "Zadnjič posodobljeno"

#. module: users_ldap_groups
#: model:ir.ui.view,arch_db:users_ldap_groups.company_form_view
#: model:ir.ui.view,arch_db:users_ldap_groups.view_ldap_installer_form
msgid "Map User Groups"
msgstr "Mapiraj uporabniške skupine"

Expand All @@ -110,7 +110,7 @@ msgstr "Samo LDAP skupine"

#. module: users_ldap_groups
#: model:ir.model.fields,field_description:users_ldap_groups.field_res_company_ldap_only_ldap_groups
msgid "Only ldap groups"
msgid "Only LDAP groups"
msgstr "Samo LDAP skupine"

#. module: users_ldap_groups
Expand Down
6 changes: 3 additions & 3 deletions users_ldap_groups/i18n/users_ldap_groups.pot
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ msgstr ""

#. module: users_ldap_groups
#: model:ir.model.fields,help:users_ldap_groups.field_res_company_ldap_group_mapping_ids
msgid "Define how Odoo groups are assigned to ldap users"
msgid "Define how Odoo groups are assigned to LDAP users"
msgstr ""

#. module: users_ldap_groups
Expand Down Expand Up @@ -82,7 +82,7 @@ msgid "Last Updated on"
msgstr ""

#. module: users_ldap_groups
#: model:ir.ui.view,arch_db:users_ldap_groups.company_form_view
#: model:ir.ui.view,arch_db:users_ldap_groups.view_ldap_installer_form
msgid "Map User Groups"
msgstr ""

Expand All @@ -93,7 +93,7 @@ msgstr ""

#. module: users_ldap_groups
#: model:ir.model.fields,field_description:users_ldap_groups.field_res_company_ldap_only_ldap_groups
msgid "Only ldap groups"
msgid "Only LDAP groups"
msgstr ""

#. module: users_ldap_groups
Expand Down
2 changes: 0 additions & 2 deletions users_ldap_groups/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2012-2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import res_company_ldap
from . import res_company_ldap_operator
Expand Down
34 changes: 23 additions & 11 deletions users_ldap_groups/models/res_company_ldap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2012-2018 Therp BV <https://therp.nl>
# Copyright 2018 Brainbean Apps <https://brainbeanapps.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from logging import getLogger
from odoo import api, fields, models
Expand All @@ -11,29 +11,36 @@ class ResCompanyLdap(models.Model):

group_mapping_ids = fields.One2many(
'res.company.ldap.group_mapping',
'ldap_id', 'Group mappings',
help='Define how Odoo groups are assigned to ldap users',
'ldap_id',
'Group mappings',
help='Define how Odoo groups are assigned to LDAP users',
)
only_ldap_groups = fields.Boolean(
'Only ldap groups', default=False,
help='If this is checked, manual changes to group membership are '
'undone on every login (so Odoo groups are always synchronous '
'with LDAP groups). If not, manually added groups are preserved.',
'Only LDAP groups',
default=False,
help=(
'If this is checked, manual changes to group membership are '
'undone on every login (so Odoo groups are always synchronous '
'with LDAP groups). If not, manually added groups are preserved.'
),
)

@api.model
def get_or_create_user(self, conf, login, ldap_entry):
def _get_or_create_user(self, conf, login, ldap_entry):
op_obj = self.env['res.company.ldap.operator']
user_id = super(ResCompanyLdap, self).get_or_create_user(
user_id = super()._get_or_create_user(
conf, login, ldap_entry
)
if not user_id:
return user_id
this = self.browse(conf['id'])
user = self.env['res.users'].browse(user_id)

groups = []

if this.only_ldap_groups:
_logger.debug('deleting all groups from user %d', user_id)
user.write({'groups_id': [(5, False, False)]})
groups.append((5, False, False))

for mapping in this.group_mapping_ids:
operator = getattr(op_obj, mapping.operator)
Expand All @@ -43,5 +50,10 @@ def get_or_create_user(self, conf, login, ldap_entry):
_logger.debug(
'adding user %d to group %s', user, mapping.group_id.name,
)
user.write({'groups_id': [(4, mapping.group_id.id)]})
groups.append((4, mapping.group_id.id, False))

user.write({
'groups_id': groups
})

return user_id
Loading

0 comments on commit 143a449

Please sign in to comment.