View | Details | Raw Unified | Return to bug 32765
Collapse All | Expand All

(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admin/modules.py (-97 / +112 lines)
 Lines 393-403   def update_extended_attributes(lo, module, position): Link Here 
393
	module.extended_udm_attributes = []
393
	module.extended_udm_attributes = []
394
	for dn, attrs in lo.search( base = position.getDomainConfigBase(),
394
	for dn, attrs in lo.search( base = position.getDomainConfigBase(),
395
								filter='(&(objectClass=univentionUDMProperty)(univentionUDMPropertyModule=%s)(univentionUDMPropertyVersion=2))' % name(module) ):
395
								filter='(&(objectClass=univentionUDMProperty)(univentionUDMPropertyModule=%s)(univentionUDMPropertyVersion=2))' % name(module) ):
396
		def ldap_true(attribute_name):
397
			return attrs.get(attribute_name, ['0'])[0].upper() in ('1', 'TRUE')
398
		def ldap_int(attribute_name, default=0):
399
			try:
400
				return int(attrs.get(attribute_name, [default])[0])
401
			except (TypeError, ValueError):
402
				return default
403
396
		# get CLI name
404
		# get CLI name
397
		pname=attrs['univentionUDMPropertyCLIName'][0]
405
		pname = attrs['univentionUDMPropertyCLIName'][0]
398
406
399
		# get syntax
407
		# get syntax
400
		propertySyntaxString=attrs.get('univentionUDMPropertySyntax', [''])[0]
408
		propertySyntaxString = attrs.get('univentionUDMPropertySyntax', [''])[0]
401
		if propertySyntaxString and hasattr(univention.admin.syntax, propertySyntaxString):
409
		if propertySyntaxString and hasattr(univention.admin.syntax, propertySyntaxString):
402
			propertySyntax = getattr(univention.admin.syntax, propertySyntaxString)
410
			propertySyntax = getattr(univention.admin.syntax, propertySyntaxString)
403
		else:
411
		else:
 Lines 407-413   def update_extended_attributes(lo, module, position): Link Here 
407
				propertySyntax = univention.admin.syntax.string()
415
				propertySyntax = univention.admin.syntax.string()
408
416
409
		# get hooks
417
		# get hooks
410
		propertyHookString=attrs.get('univentionUDMPropertyHook', [''])[0]
418
		propertyHookString = attrs.get('univentionUDMPropertyHook', [''])[0]
411
		propertyHook = None
419
		propertyHook = None
412
		if propertyHookString and hasattr(univention.admin.hook, propertyHookString):
420
		if propertyHookString and hasattr(univention.admin.hook, propertyHookString):
413
			propertyHook = getattr(univention.admin.hook, propertyHookString)()
421
			propertyHook = getattr(univention.admin.hook, propertyHookString)()
 Lines 416-455   def update_extended_attributes(lo, module, position): Link Here 
416
		propertyDefault = attrs.get('univentionUDMPropertyDefault', [''])
424
		propertyDefault = attrs.get('univentionUDMPropertyDefault', [''])
417
425
418
		# value may change
426
		# value may change
419
		try:
427
		mayChange = ldap_int('univentionUDMPropertyValueMayChange')
420
			mayChange = int( attrs.get('univentionUDMPropertyValueMayChange', ['0'])[0] )
421
		except:
422
			ud.debug(ud.ADMIN, ud.ERROR, 'modules update_extended_attributes: ERROR: processing univentionUDMPropertyValueMayChange throwed exception - assuming mayChange=0')
423
			mayChange = 0
424
428
425
		# value is editable (only via hooks or direkt module.info[] access)
429
		# value is editable (only via hooks or direkt module.info[] access)
426
		editable = attrs.get('univentionUDMPropertyValueNotEditable', ['0'])[0] not in ['1', 'TRUE']
430
		editable = not ldap_true('univentionUDMPropertyValueNotEditable')
427
431
428
		# value is required
432
		# value is required
429
		valueRequired = ( attrs.get('univentionUDMPropertyValueRequired',[ '0' ])[0].upper() in [ '1', 'TRUE' ] )
433
		valueRequired = ldap_true('univentionUDMPropertyValueRequired')
430
434
431
		# value not available for searching
435
		# value not available for searching
432
		try:
436
		doNotSearch = ldap_int('univentionUDMPropertyDoNotSearch')
433
			doNotSearch = int( attrs.get('univentionUDMPropertyDoNotSearch',[ '0' ])[0] )
434
		except:
435
			ud.debug(ud.ADMIN, ud.ERROR, 'modules update_extended_attributes: ERROR: processing univentionUDMPropertyDoNotSearch throwed exception - assuming doNotSearch=0')
436
			doNotSearch = 0
437
437
438
		# check if CA is multivalue property
438
		# check if EA is multivalue property
439
		if attrs.get('univentionUDMPropertyMultivalue', [''])[0] == '1':
439
		multivalue = ldap_true('univentionUDMPropertyMultivalue')
440
			multivalue = 1
440
		map_method = None if multivalue else univention.admin.mapping.ListToString
441
			map_method = None
441
		if not multivalue:
442
		else:
443
			multivalue = 0
444
			map_method = univention.admin.mapping.ListToString
445
			# single value ==> use only first value
442
			# single value ==> use only first value
446
			propertyDefault = propertyDefault[0]
443
			propertyDefault = propertyDefault[0]
447
444
448
		# Show this attribute in UDM/UMC?
445
		# Show this attribute in UDM/UMC?
449
		if attrs.get('univentionUDMPropertyLayoutDisable', [''])[0] == '1':
446
		layoutDisabled = ldap_true('univentionUDMPropertyLayoutDisable')
450
			layoutDisabled = True
451
		else:
452
			layoutDisabled = False
453
447
454
		# get current language
448
		# get current language
455
		lang = locale.getlocale( locale.LC_MESSAGES )[0]
449
		lang = locale.getlocale( locale.LC_MESSAGES )[0]
 Lines 460-482   def update_extended_attributes(lo, module, position): Link Here 
460
			lang = 'xxxxx'
454
			lang = 'xxxxx'
461
455
462
		# get descriptions
456
		# get descriptions
463
		shortdesc = attrs.get('univentionUDMPropertyTranslationShortDescription;entry-%s' % lang, attrs['univentionUDMPropertyShortDescription'] )[0]
457
		shortdesc = attrs.get(
464
		longdesc = attrs.get('univentionUDMPropertyTranslationLongDescription;entry-%s' % lang, attrs.get('univentionUDMPropertyLongDescription', ['']))[0]
458
				'univentionUDMPropertyTranslationShortDescription;entry-%s' % lang,
459
				attrs['univentionUDMPropertyShortDescription']
460
		)[0]
461
		longdesc = attrs.get(
462
				'univentionUDMPropertyTranslationLongDescription;entry-%s' % lang,
463
				attrs.get('univentionUDMPropertyLongDescription', [''])
464
		)[0]
465
465
466
		# create property
466
		# create property
467
		# FIXME: must add attribute to honor fullWidth (should be defined by the syntax)
467
		# FIXME: must add attribute to honor fullWidth (should be defined by the syntax)
468
		module.property_descriptions[pname] = univention.admin.property(
468
		module.property_descriptions[pname] = univention.admin.property(
469
			short_description = shortdesc,
469
			short_description=shortdesc,
470
			long_description = longdesc,
470
			long_description=longdesc,
471
			syntax = propertySyntax,
471
			syntax=propertySyntax,
472
			multivalue = multivalue,
472
			multivalue=multivalue,
473
			options = attrs.get('univentionUDMPropertyOptions',[]),
473
			options=attrs.get('univentionUDMPropertyOptions', []),
474
			required = valueRequired,
474
			required=valueRequired,
475
			may_change = mayChange,
475
			may_change=mayChange,
476
			dontsearch = doNotSearch,
476
			dontsearch=doNotSearch,
477
			identifies = 0,
477
			identifies=0,
478
			default = propertyDefault,
478
			default=propertyDefault,
479
			editable = editable
479
			editable=editable
480
		)
480
		)
481
481
482
		# add LDAP mapping
482
		# add LDAP mapping
 Lines 485-551   def update_extended_attributes(lo, module, position): Link Here 
485
		else:
485
		else:
486
			module.mapping.register(pname, attrs['univentionUDMPropertyLdapMapping'][0], univention.admin.mapping.nothing, univention.admin.mapping.nothing)
486
			module.mapping.register(pname, attrs['univentionUDMPropertyLdapMapping'][0], univention.admin.mapping.nothing, univention.admin.mapping.nothing)
487
487
488
		module.extended_udm_attributes.extend([
489
			univention.admin.extended_attribute(
490
				pname,
491
				attrs.get('univentionUDMPropertyObjectClass', [])[0],
492
				attrs['univentionUDMPropertyLdapMapping'][0],
493
				deleteObjectClass,
494
				propertySyntaxString,
495
				propertyHook
496
			)
497
		])
498
499
		if layoutDisabled or not hasattr(module, 'layout'):
500
			continue
488
501
489
		if hasattr( module, 'layout' ):
502
		tabname = attrs.get(
490
			tabname = attrs.get('univentionUDMPropertyTranslationTabName;entry-%s' % lang, attrs.get('univentionUDMPropertyLayoutTabName',[ _('Custom') ]) )[0]
503
				'univentionUDMPropertyTranslationTabName;entry-%s' % lang,
491
			overwriteTab = ( attrs.get('univentionUDMPropertyLayoutOverwriteTab',[ '0' ])[0].upper() in [ '1', 'TRUE' ] )
504
				attrs.get('univentionUDMPropertyLayoutTabName', [_('Custom')])
492
			# in the first generation of extended attributes of version 2
505
		)[0]
493
			# this field was a position defining the attribute to
506
		overwriteTab = ldap_true('univentionUDMPropertyLayoutOverwriteTab')
494
			# overwrite. now it is the name of the attribute to overwrite
507
		# in the first generation of extended attributes of version 2
495
			overwriteProp = attrs.get( 'univentionUDMPropertyLayoutOverwritePosition', [ '' ] )[ 0 ]
508
		# this field was a position defining the attribute to
496
			if overwriteProp == '0':
509
		# overwrite. now it is the name of the attribute to overwrite
497
				overwriteProp = None
510
		overwriteProp = attrs.get('univentionUDMPropertyLayoutOverwritePosition', [''])[0]
498
			fullWidth = ( attrs.get('univentionUDMPropertyLayoutFullWidth',[ '0' ])[0].upper() in [ '1', 'TRUE' ] )
511
		if overwriteProp == '0':
499
			deleteObjectClass = ( attrs.get('univentionUDMPropertyDeleteObjectClass', ['0'])[0].upper() in [ '1', 'TRUE' ] )
512
			overwriteProp = None
500
			tabAdvanced = ( attrs.get('univentionUDMPropertyLayoutTabAdvanced',[ '0' ])[0].upper() in [ '1', 'TRUE' ] )
513
		fullWidth = ldap_true('univentionUDMPropertyLayoutFullWidth')
501
514
		deleteObjectClass = ldap_true('univentionUDMPropertyDeleteObjectClass')
502
			groupname = attrs.get( 'univentionUDMPropertyTranslationGroupName;entry-%s' % lang, attrs.get( 'univentionUDMPropertyLayoutGroupName', [ '' ] ) )[ 0 ]
515
		tabAdvanced = ldap_true('univentionUDMPropertyLayoutTabAdvanced')
503
			try:
516
504
				groupPosition = int( attrs.get( 'univentionUDMPropertyLayoutGroupPosition', [ '-1' ] )[ 0 ] )
517
		groupname = attrs.get(
505
			except TypeError:
518
				'univentionUDMPropertyTranslationGroupName;entry-%s' % lang,
506
				groupPosition = 0
519
				attrs.get('univentionUDMPropertyLayoutGroupName', [''])
507
520
		)[0]
508
			ud.debug( ud.ADMIN, ud.INFO, 'update_extended_attributes: extended attribute (LDAP): %s' % str( attrs ) )
521
		groupPosition = ldap_int('univentionUDMPropertyLayoutGroupPosition', -1)
509
522
510
			# only one is possible ==> overwriteTab wins
523
		ud.debug(ud.ADMIN, ud.INFO, 'update_extended_attributes: extended attribute (LDAP): %s' % (attrs,))
511
			if overwriteTab and overwriteProp:
524
512
				overwriteProp = None
525
		# only one is possible ==> overwriteTab wins
513
526
		if overwriteTab and overwriteProp:
514
			# add tab name to list if missing
527
			overwriteProp = None
515
			if not tabname in properties4tabs and not layoutDisabled:
528
516
				properties4tabs[ tabname ] = []
529
		# add tab name to list if missing
517
				ud.debug(ud.ADMIN, ud.INFO, 'modules update_extended_attributes: custom fields init for tab %s' % tabname)
530
		if tabname not in properties4tabs:
518
531
			properties4tabs[ tabname ] = []
519
			# remember tab for purging if required
532
			ud.debug(ud.ADMIN, ud.INFO, 'modules update_extended_attributes: custom fields init for tab %s' % tabname)
520
			if overwriteTab and not tabname in overwriteTabList and not layoutDisabled:
533
521
				overwriteTabList.append(tabname)
534
		# remember tab for purging if required
522
535
		if overwriteTab and tabname not in overwriteTabList:
523
			if not layoutDisabled:
536
			overwriteTabList.append(tabname)
524
				# get position on tab
537
525
				# -1 == append on top
538
		# get position on tab
526
				tabPosition = attrs.get( 'univentionUDMPropertyLayoutPosition', [ '-1' ] )[ 0 ]
539
		# -1 == append on top
540
		tabPosition = ldap_int('univentionUDMPropertyLayoutPosition', -1]
541
542
		if tabPosition == -1:
543
			for ea_layout in properties4tabs[tabname]:
527
				try:
544
				try:
528
					tabPosition = int( tabPosition )
545
					if ea_layout.position <= tabPosition:
546
						# CLEANUP, FIXME: pos is undefined!
547
						# does not break because of except:
548
						tabPosition = pos - 1
529
				except:
549
				except:
530
					ud.debug(ud.ADMIN, ud.WARN, 'modules update_extended_attributes: custom field for tab %s: failed to convert tabNumber to int' % tabname)
550
					ud.debug(ud.ADMIN, ud.WARN, 'modules update_extended_attributes: custom field for tab %s: failed to set tabPosition' % tabname)
531
					tabPosition = -1
551
532
552
		properties4tabs[tabname].append(
533
				if tabPosition == -1:
553
				EA_Layout(
534
					for ea_layout in properties4tabs[ tabname ]:
554
					name=pname,
535
						try:
555
					tabName=tabname,
536
							if ea_layout.position <= tabPosition:
556
					position=tabPosition,
537
								# CLEANUP, FIXME: pos is undefined!
557
					advanced=tabAdvanced,
538
								# does not break because of except:
558
					overwrite=overwriteProp,
539
								tabPosition = pos-1
559
					fullWidth=fullWidth,
540
						except:
560
					groupName=groupname,
541
							ud.debug(ud.ADMIN, ud.WARN, 'modules update_extended_attributes: custom field for tab %s: failed to set tabPosition' % tabname)
561
					groupPosition=groupPosition
542
562
				)
543
				properties4tabs[ tabname ].append( EA_Layout( name = pname, tabName = tabname, position = tabPosition, advanced = tabAdvanced, overwrite = overwriteProp, fullWidth = fullWidth, groupName = groupname, groupPosition = groupPosition ) )
563
		)
544
545
			module.extended_udm_attributes.extend( [ univention.admin.extended_attribute( pname, attrs.get('univentionUDMPropertyObjectClass', [])[0],
546
																				  attrs['univentionUDMPropertyLdapMapping'][0], deleteObjectClass,
547
																				  propertySyntaxString,
548
																				  propertyHook ) ] )
549
564
550
	# overwrite tabs that have been added by UDM extended attributes
565
	# overwrite tabs that have been added by UDM extended attributes
551
	for tab in module.extended_attribute_tabnames:
566
	for tab in module.extended_attribute_tabnames:

Return to bug 32765