diff --git a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admin/modules.py b/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admin/modules.py index a011ab4..3975279 100644 --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admin/modules.py +++ b/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admin/modules.py @@ -393,11 +393,19 @@ def update_extended_attributes(lo, module, position): module.extended_udm_attributes = [] for dn, attrs in lo.search( base = position.getDomainConfigBase(), filter='(&(objectClass=univentionUDMProperty)(univentionUDMPropertyModule=%s)(univentionUDMPropertyVersion=2))' % name(module) ): + def ldap_true(attribute_name): + return attrs.get(attribute_name, ['0'])[0].upper() in ('1', 'TRUE') + def ldap_int(attribute_name, default=0): + try: + return int(attrs.get(attribute_name, [default])[0]) + except (TypeError, ValueError): + return default + # get CLI name - pname=attrs['univentionUDMPropertyCLIName'][0] + pname = attrs['univentionUDMPropertyCLIName'][0] # get syntax - propertySyntaxString=attrs.get('univentionUDMPropertySyntax', [''])[0] + propertySyntaxString = attrs.get('univentionUDMPropertySyntax', [''])[0] if propertySyntaxString and hasattr(univention.admin.syntax, propertySyntaxString): propertySyntax = getattr(univention.admin.syntax, propertySyntaxString) else: @@ -407,7 +415,7 @@ def update_extended_attributes(lo, module, position): propertySyntax = univention.admin.syntax.string() # get hooks - propertyHookString=attrs.get('univentionUDMPropertyHook', [''])[0] + propertyHookString = attrs.get('univentionUDMPropertyHook', [''])[0] propertyHook = None if propertyHookString and hasattr(univention.admin.hook, propertyHookString): propertyHook = getattr(univention.admin.hook, propertyHookString)() @@ -416,40 +424,26 @@ def update_extended_attributes(lo, module, position): propertyDefault = attrs.get('univentionUDMPropertyDefault', ['']) # value may change - try: - mayChange = int( attrs.get('univentionUDMPropertyValueMayChange', ['0'])[0] ) - except: - ud.debug(ud.ADMIN, ud.ERROR, 'modules update_extended_attributes: ERROR: processing univentionUDMPropertyValueMayChange throwed exception - assuming mayChange=0') - mayChange = 0 + mayChange = ldap_int('univentionUDMPropertyValueMayChange') # value is editable (only via hooks or direkt module.info[] access) - editable = attrs.get('univentionUDMPropertyValueNotEditable', ['0'])[0] not in ['1', 'TRUE'] + editable = not ldap_true('univentionUDMPropertyValueNotEditable') # value is required - valueRequired = ( attrs.get('univentionUDMPropertyValueRequired',[ '0' ])[0].upper() in [ '1', 'TRUE' ] ) + valueRequired = ldap_true('univentionUDMPropertyValueRequired') # value not available for searching - try: - doNotSearch = int( attrs.get('univentionUDMPropertyDoNotSearch',[ '0' ])[0] ) - except: - ud.debug(ud.ADMIN, ud.ERROR, 'modules update_extended_attributes: ERROR: processing univentionUDMPropertyDoNotSearch throwed exception - assuming doNotSearch=0') - doNotSearch = 0 + doNotSearch = ldap_int('univentionUDMPropertyDoNotSearch') - # check if CA is multivalue property - if attrs.get('univentionUDMPropertyMultivalue', [''])[0] == '1': - multivalue = 1 - map_method = None - else: - multivalue = 0 - map_method = univention.admin.mapping.ListToString + # check if EA is multivalue property + multivalue = ldap_true('univentionUDMPropertyMultivalue') + map_method = None if multivalue else univention.admin.mapping.ListToString + if not multivalue: # single value ==> use only first value propertyDefault = propertyDefault[0] # Show this attribute in UDM/UMC? - if attrs.get('univentionUDMPropertyLayoutDisable', [''])[0] == '1': - layoutDisabled = True - else: - layoutDisabled = False + layoutDisabled = ldap_true('univentionUDMPropertyLayoutDisable') # get current language lang = locale.getlocale( locale.LC_MESSAGES )[0] @@ -460,23 +454,29 @@ def update_extended_attributes(lo, module, position): lang = 'xxxxx' # get descriptions - shortdesc = attrs.get('univentionUDMPropertyTranslationShortDescription;entry-%s' % lang, attrs['univentionUDMPropertyShortDescription'] )[0] - longdesc = attrs.get('univentionUDMPropertyTranslationLongDescription;entry-%s' % lang, attrs.get('univentionUDMPropertyLongDescription', ['']))[0] + shortdesc = attrs.get( + 'univentionUDMPropertyTranslationShortDescription;entry-%s' % lang, + attrs['univentionUDMPropertyShortDescription'] + )[0] + longdesc = attrs.get( + 'univentionUDMPropertyTranslationLongDescription;entry-%s' % lang, + attrs.get('univentionUDMPropertyLongDescription', ['']) + )[0] # create property # FIXME: must add attribute to honor fullWidth (should be defined by the syntax) module.property_descriptions[pname] = univention.admin.property( - short_description = shortdesc, - long_description = longdesc, - syntax = propertySyntax, - multivalue = multivalue, - options = attrs.get('univentionUDMPropertyOptions',[]), - required = valueRequired, - may_change = mayChange, - dontsearch = doNotSearch, - identifies = 0, - default = propertyDefault, - editable = editable + short_description=shortdesc, + long_description=longdesc, + syntax=propertySyntax, + multivalue=multivalue, + options=attrs.get('univentionUDMPropertyOptions', []), + required=valueRequired, + may_change=mayChange, + dontsearch=doNotSearch, + identifies=0, + default=propertyDefault, + editable=editable ) # add LDAP mapping @@ -485,67 +485,82 @@ def update_extended_attributes(lo, module, position): else: module.mapping.register(pname, attrs['univentionUDMPropertyLdapMapping'][0], univention.admin.mapping.nothing, univention.admin.mapping.nothing) + module.extended_udm_attributes.extend([ + univention.admin.extended_attribute( + pname, + attrs.get('univentionUDMPropertyObjectClass', [])[0], + attrs['univentionUDMPropertyLdapMapping'][0], + deleteObjectClass, + propertySyntaxString, + propertyHook + ) + ]) + + if layoutDisabled or not hasattr(module, 'layout'): + continue - if hasattr( module, 'layout' ): - tabname = attrs.get('univentionUDMPropertyTranslationTabName;entry-%s' % lang, attrs.get('univentionUDMPropertyLayoutTabName',[ _('Custom') ]) )[0] - overwriteTab = ( attrs.get('univentionUDMPropertyLayoutOverwriteTab',[ '0' ])[0].upper() in [ '1', 'TRUE' ] ) - # in the first generation of extended attributes of version 2 - # this field was a position defining the attribute to - # overwrite. now it is the name of the attribute to overwrite - overwriteProp = attrs.get( 'univentionUDMPropertyLayoutOverwritePosition', [ '' ] )[ 0 ] - if overwriteProp == '0': - overwriteProp = None - fullWidth = ( attrs.get('univentionUDMPropertyLayoutFullWidth',[ '0' ])[0].upper() in [ '1', 'TRUE' ] ) - deleteObjectClass = ( attrs.get('univentionUDMPropertyDeleteObjectClass', ['0'])[0].upper() in [ '1', 'TRUE' ] ) - tabAdvanced = ( attrs.get('univentionUDMPropertyLayoutTabAdvanced',[ '0' ])[0].upper() in [ '1', 'TRUE' ] ) - - groupname = attrs.get( 'univentionUDMPropertyTranslationGroupName;entry-%s' % lang, attrs.get( 'univentionUDMPropertyLayoutGroupName', [ '' ] ) )[ 0 ] - try: - groupPosition = int( attrs.get( 'univentionUDMPropertyLayoutGroupPosition', [ '-1' ] )[ 0 ] ) - except TypeError: - groupPosition = 0 - - ud.debug( ud.ADMIN, ud.INFO, 'update_extended_attributes: extended attribute (LDAP): %s' % str( attrs ) ) - - # only one is possible ==> overwriteTab wins - if overwriteTab and overwriteProp: - overwriteProp = None - - # add tab name to list if missing - if not tabname in properties4tabs and not layoutDisabled: - properties4tabs[ tabname ] = [] - ud.debug(ud.ADMIN, ud.INFO, 'modules update_extended_attributes: custom fields init for tab %s' % tabname) - - # remember tab for purging if required - if overwriteTab and not tabname in overwriteTabList and not layoutDisabled: - overwriteTabList.append(tabname) - - if not layoutDisabled: - # get position on tab - # -1 == append on top - tabPosition = attrs.get( 'univentionUDMPropertyLayoutPosition', [ '-1' ] )[ 0 ] + tabname = attrs.get( + 'univentionUDMPropertyTranslationTabName;entry-%s' % lang, + attrs.get('univentionUDMPropertyLayoutTabName', [_('Custom')]) + )[0] + overwriteTab = ldap_true('univentionUDMPropertyLayoutOverwriteTab') + # in the first generation of extended attributes of version 2 + # this field was a position defining the attribute to + # overwrite. now it is the name of the attribute to overwrite + overwriteProp = attrs.get('univentionUDMPropertyLayoutOverwritePosition', [''])[0] + if overwriteProp == '0': + overwriteProp = None + fullWidth = ldap_true('univentionUDMPropertyLayoutFullWidth') + deleteObjectClass = ldap_true('univentionUDMPropertyDeleteObjectClass') + tabAdvanced = ldap_true('univentionUDMPropertyLayoutTabAdvanced') + + groupname = attrs.get( + 'univentionUDMPropertyTranslationGroupName;entry-%s' % lang, + attrs.get('univentionUDMPropertyLayoutGroupName', ['']) + )[0] + groupPosition = ldap_int('univentionUDMPropertyLayoutGroupPosition', -1) + + ud.debug(ud.ADMIN, ud.INFO, 'update_extended_attributes: extended attribute (LDAP): %s' % (attrs,)) + + # only one is possible ==> overwriteTab wins + if overwriteTab and overwriteProp: + overwriteProp = None + + # add tab name to list if missing + if tabname not in properties4tabs: + properties4tabs[ tabname ] = [] + ud.debug(ud.ADMIN, ud.INFO, 'modules update_extended_attributes: custom fields init for tab %s' % tabname) + + # remember tab for purging if required + if overwriteTab and tabname not in overwriteTabList: + overwriteTabList.append(tabname) + + # get position on tab + # -1 == append on top + tabPosition = ldap_int('univentionUDMPropertyLayoutPosition', -1] + + if tabPosition == -1: + for ea_layout in properties4tabs[tabname]: try: - tabPosition = int( tabPosition ) + if ea_layout.position <= tabPosition: + # CLEANUP, FIXME: pos is undefined! + # does not break because of except: + tabPosition = pos - 1 except: - ud.debug(ud.ADMIN, ud.WARN, 'modules update_extended_attributes: custom field for tab %s: failed to convert tabNumber to int' % tabname) - tabPosition = -1 - - if tabPosition == -1: - for ea_layout in properties4tabs[ tabname ]: - try: - if ea_layout.position <= tabPosition: - # CLEANUP, FIXME: pos is undefined! - # does not break because of except: - tabPosition = pos-1 - except: - ud.debug(ud.ADMIN, ud.WARN, 'modules update_extended_attributes: custom field for tab %s: failed to set tabPosition' % tabname) - - properties4tabs[ tabname ].append( EA_Layout( name = pname, tabName = tabname, position = tabPosition, advanced = tabAdvanced, overwrite = overwriteProp, fullWidth = fullWidth, groupName = groupname, groupPosition = groupPosition ) ) - - module.extended_udm_attributes.extend( [ univention.admin.extended_attribute( pname, attrs.get('univentionUDMPropertyObjectClass', [])[0], - attrs['univentionUDMPropertyLdapMapping'][0], deleteObjectClass, - propertySyntaxString, - propertyHook ) ] ) + ud.debug(ud.ADMIN, ud.WARN, 'modules update_extended_attributes: custom field for tab %s: failed to set tabPosition' % tabname) + + properties4tabs[tabname].append( + EA_Layout( + name=pname, + tabName=tabname, + position=tabPosition, + advanced=tabAdvanced, + overwrite=overwriteProp, + fullWidth=fullWidth, + groupName=groupname, + groupPosition=groupPosition + ) + ) # overwrite tabs that have been added by UDM extended attributes for tab in module.extended_attribute_tabnames: