commit 024a409f0e82f95769ef704963c8837bfbd58a78 Author: Florian Best Date: Wed Oct 11 16:27:19 2017 +0200 Bug #43129: make mapping/unmapping for extended attributes configurable diff --git a/management/univention-directory-manager-modules/modules/univention/admin/handlers/settings/extended_attribute.py b/management/univention-directory-manager-modules/modules/univention/admin/handlers/settings/extended_attribute.py index 9d404fa..a3656e3 100644 --- a/management/univention-directory-manager-modules/modules/univention/admin/handlers/settings/extended_attribute.py +++ b/management/univention-directory-manager-modules/modules/univention/admin/handlers/settings/extended_attribute.py @@ -378,6 +378,28 @@ identifies=False, copyable=True, ), + 'mapMethod': univention.admin.property( + short_description=_('Map method'), + long_description=_('Defines a custom UDM property to LDAP attribute mapping method.'), + syntax=univention.admin.syntax.string, + multivalue=False, + options=[], + required=False, + may_change=True, + identifies=False, + copyable=True, + ), + 'unmapMethod': univention.admin.property( + short_description=_('Unmap method'), + long_description=_('Defines a custom LDAP attribute to UDM property mapping method.'), + syntax=univention.admin.syntax.string, + multivalue=False, + options=[], + required=False, + may_change=True, + identifies=False, + copyable=True, + ), } layout = [ @@ -425,6 +447,7 @@ ]), Tab(_('Data type'), _('Data type definition'), layout=[ ["syntax", "default"], + ["mapMethod", "unmapMethod"], ["multivalue"], ["valueRequired"], ["mayChange"], @@ -459,6 +482,8 @@ mapping.register('notEditable', 'univentionUDMPropertyValueNotEditable', None, univention.admin.mapping.ListToString) mapping.register('doNotSearch', 'univentionUDMPropertyDoNotSearch', None, univention.admin.mapping.ListToString) mapping.register('copyable', 'univentionUDMPropertyCopyable', None, univention.admin.mapping.ListToString) +mapping.register('mapMethod', 'univentionUDMPropertyMapMethod', None, univention.admin.mapping.ListToString) +mapping.register('unmapMethod', 'univentionUDMPropertyUnMapMethod', None, univention.admin.mapping.ListToString) mapping.register('version', 'univentionUDMPropertyVersion', None, univention.admin.mapping.ListToString) mapping.register('CLIName', 'univentionUDMPropertyCLIName', None, univention.admin.mapping.ListToString) mapping.register('options', 'univentionUDMPropertyOptions') diff --git a/management/univention-directory-manager-modules/modules/univention/admin/modules.py b/management/univention-directory-manager-modules/modules/univention/admin/modules.py index 7c1b42b..cc735d7 100644 --- a/management/univention-directory-manager-modules/modules/univention/admin/modules.py +++ b/management/univention-directory-manager-modules/modules/univention/admin/modules.py @@ -311,21 +311,27 @@ def update_extended_attributes(lo, module, position): ud.debug(ud.ADMIN, ud.ERROR, 'modules update_extended_attributes: ERROR: processing univentionUDMPropertyDoNotSearch throwed exception - assuming doNotSearch=0') doNotSearch = 0 + map_method = '' + unmap_method = '' + # check if CA is multivalue property - if attrs.get('univentionUDMPropertyMultivalue', [''])[0] == '1': - multivalue = 1 - map_method = None - unmap_method = None - else: - multivalue = 0 - map_method = univention.admin.mapping.ListToString - unmap_method = None + multivalue = attrs.get('univentionUDMPropertyMultivalue', [''])[0] == '1' + if not multivalue: + map_method = 'ListToString' if propertySyntaxString == 'boolean': - map_method = univention.admin.mapping.BooleanListToString - unmap_method = univention.admin.mapping.BooleanUnMap + map_method = 'BooleanListToString' + unmap_method = 'BooleanUnMap' # single value ==> use only first value propertyDefault = propertyDefault[0] + # extended attribute for objectClass should not be mapped to any attribute/property + if attrs['univentionUDMPropertyLdapMapping'][0].lower() == 'objectClass'.lower(): + map_method = 'nothing' + unmap_method = 'nothing' + + map_method = getattr(univention.admin.mapping, attrs.get('univentionUDMPropertyMapMethod', [map_method])[0], None) + unmap_method = getattr(univention.admin.mapping, attrs.get('univentionUDMPropertyUnMapMethod', [unmap_method])[0], None) + # Show this attribute in UDM/UMC? if attrs.get('univentionUDMPropertyLayoutDisable', [''])[0] == '1': layoutDisabled = True @@ -363,10 +369,7 @@ def update_extended_attributes(lo, module, position): ) # add LDAP mapping - if attrs['univentionUDMPropertyLdapMapping'][0].lower() != 'objectClass'.lower(): - module.mapping.register(pname, attrs['univentionUDMPropertyLdapMapping'][0], unmap_method, map_method) - else: - module.mapping.register(pname, attrs['univentionUDMPropertyLdapMapping'][0], univention.admin.mapping.nothing, univention.admin.mapping.nothing) + module.mapping.register(pname, attrs['univentionUDMPropertyLdapMapping'][0], unmap_method, map_method) if hasattr(module, 'layout'): tabname = attrs.get('univentionUDMPropertyTranslationTabName;entry-%s' % lang, attrs.get('univentionUDMPropertyLayoutTabName', [_('Custom')]))[0] diff --git a/management/univention-ldap/schema/custom-attribute.schema b/management/univention-ldap/schema/custom-attribute.schema index 6149e4f..5f61e78 100644 --- a/management/univention-ldap/schema/custom-attribute.schema +++ b/management/univention-ldap/schema/custom-attribute.schema @@ -291,6 +291,18 @@ attributetype ( 1.3.6.1.4.1.10176.200.131 NAME 'univentionUDMPropertyCopyable' SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE) +attributetype ( 1.3.6.1.4.1.10176.200.132 NAME 'univentionUDMPropertyMapMethod' + DESC 'defines the UDM property to LDAP attribute mapping method' + EQUALITY caseIgnoreMatch + SUBSTR caseIgnoreSubstringsMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE) + +attributetype ( 1.3.6.1.4.1.10176.200.133 NAME 'univentionUDMPropertyUnMapMethod' + DESC 'defines the LDAP attribute to UDM property mapping method' + EQUALITY caseIgnoreMatch + SUBSTR caseIgnoreSubstringsMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE) + objectclass ( 1.3.6.1.4.1.10176.200.199 NAME 'univentionUDMProperty' commit 915efc6bddf7bcb136ad6cffd00746bd1929772e Author: Florian Best Date: Wed Oct 11 16:35:47 2017 +0200 Bug #43129: add loading of mapping.d diff --git a/management/univention-directory-manager-modules/debian/python-univention-directory-manager.install b/management/univention-directory-manager-modules/debian/python-univention-directory-manager.install index 44529cc..6306bf5 100644 --- a/management/univention-directory-manager-modules/debian/python-univention-directory-manager.install +++ b/management/univention-directory-manager-modules/debian/python-univention-directory-manager.install @@ -15,6 +15,7 @@ modules/univention/admin/handlers/computers/*.py usr/share/pyshared/univention/a modules/univention/admin/handlers/kerberos/*.py usr/share/pyshared/univention/admin/handlers/kerberos/ modules/univention/admin/syntax.d/*.py usr/share/pyshared/univention/admin/syntax.d/ modules/univention/admin/hooks.d/*.py usr/share/pyshared/univention/admin/hooks.d/ +modules/univention/admin/mapping.d/*.py usr/share/pyshared/univention/admin/mapping.d/ python-lib/*.py usr/share/pyshared/univention/lib listener/*.py usr/lib/univention-directory-listener/system/ 18python-univention-directory-manager.inst usr/lib/univention-install/ diff --git a/management/univention-directory-manager-modules/modules/univention/admin/__init__.py b/management/univention-directory-manager-modules/modules/univention/admin/__init__.py index e3c6164..823de38 100644 --- a/management/univention-directory-manager-modules/modules/univention/admin/__init__.py +++ b/management/univention-directory-manager-modules/modules/univention/admin/__init__.py @@ -513,6 +513,7 @@ def __init__(self, id, short_description=None, long_description='', members=[]): from univention.admin import modules, objects, syntax, hook, mapping syntax.import_syntax_files() hook.import_hook_files() +mapping.import_mapping_files() if __name__ == '__main__': prop = property('_replace') diff --git a/management/univention-directory-manager-modules/modules/univention/admin/mapping.d/__init__.py b/management/univention-directory-manager-modules/modules/univention/admin/mapping.d/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/management/univention-directory-manager-modules/modules/univention/admin/mapping.py b/management/univention-directory-manager-modules/modules/univention/admin/mapping.py index 2724829..d20ea1d 100644 --- a/management/univention-directory-manager-modules/modules/univention/admin/mapping.py +++ b/management/univention-directory-manager-modules/modules/univention/admin/mapping.py @@ -33,6 +33,27 @@ import univention.debug import types import base64 +import traceback +import sys +import os + + +def import_mapping_files(): + for dir_ in sys.path: + mapping_py = os.path.join(dir_, 'univention/admin/mapping.py') + mapping_d = os.path.join(dir_, 'univention/admin/mapping.d/') + + if os.path.exists(mapping_py) and os.path.isdir(mapping_d): + mapping_files = (os.path.join(mapping_d, f) for f in os.listdir(mapping_d) if f.endswith('.py')) + + for fn in mapping_files: + try: + with open(fn, 'r') as fd: + exec fd in sys.modules[__name__].__dict__ + univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, 'admin.mapping.import_mapping_files: importing "%s"' % fn) + except (EnvironmentError, ImportError): + univention.debug.debug(univention.debug.ADMIN, univention.debug.ERROR, 'admin.mapping.import_mapping_files: loading %s failed' % fn) + univention.debug.debug(univention.debug.ADMIN, univention.debug.ERROR, 'admin.mapping.import_mapping_files: TRACEBACK:\n%s' % traceback.format_exc()) def DaysToSeconds(days):