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

(-)a/management/univention-management-console-module-udm/umc/python/udm/__init__.py (-3 / +16 lines)
 Lines 69-75    Link Here 
69
69
70
from .udm_ldap import (
70
from .udm_ldap import (
71
	UDM_Error, UDM_Module, UDM_Settings,
71
	UDM_Error, UDM_Module, UDM_Settings,
72
	ldap_dn2path, get_module, read_syntax_choices, list_objects,
72
	ldap_dn2path, get_module, read_syntax_choices, list_objects, _get_syntax,
73
	LDAP_Connection, set_bind_function, container_modules,
73
	LDAP_Connection, set_bind_function, container_modules,
74
	info_syntax_choices, search_syntax_choices_by_key,
74
	info_syntax_choices, search_syntax_choices_by_key,
75
	UserWithoutDN, ObjectDoesNotExist, SuperordinateDoesNotExist, NoIpLeft,
75
	UserWithoutDN, ObjectDoesNotExist, SuperordinateDoesNotExist, NoIpLeft,
 Lines 894-906   def _thread(request): Link Here 
894
		thread = notifier.threads.Simple('Validate', notifier.Callback(_thread, request), notifier.Callback(self.thread_finished_callback, request))
894
		thread = notifier.threads.Simple('Validate', notifier.Callback(_thread, request), notifier.Callback(self.thread_finished_callback, request))
895
		thread.run()
895
		thread.run()
896
896
897
	@sanitize(key=LDAPSearchSanitizer(use_asterisks=False))
897
	@sanitize(
898
		syntax=StringSanitizer(required=True),
899
		key=LDAPSearchSanitizer(use_asterisks=False),
900
	)
898
	@simple_response
901
	@simple_response
899
	def syntax_choices_key(self, syntax, key):
902
	def syntax_choices_key(self, syntax, key):
903
		syntax = _get_syntax(syntax)
904
		if syntax is None:
905
			return
900
		return search_syntax_choices_by_key(syntax, key)
906
		return search_syntax_choices_by_key(syntax, key)
901
907
908
	@sanitize(syntax=StringSanitizer(required=True))
902
	@simple_response
909
	@simple_response
903
	def syntax_choices_info(self, syntax):
910
	def syntax_choices_info(self, syntax):
911
		syntax = _get_syntax(syntax)
912
		if syntax is None:
913
			return
904
		return info_syntax_choices(syntax)
914
		return info_syntax_choices(syntax)
905
915
906
	@sanitize(
916
	@sanitize(
 Lines 918-924   def syntax_choices(self, request): Link Here 
918
		"""
928
		"""
919
929
920
		def _thread(request):
930
		def _thread(request):
921
			return read_syntax_choices(request.options['syntax'], request.options)
931
			syntax = _get_syntax(request.options['syntax'])
932
			if syntax is None:
933
				return
934
			return read_syntax_choices(syntax, request.options)
922
935
923
		thread = notifier.threads.Simple('SyntaxChoice', notifier.Callback(_thread, request), notifier.Callback(self.thread_finished_callback, request))
936
		thread = notifier.threads.Simple('SyntaxChoice', notifier.Callback(_thread, request), notifier.Callback(self.thread_finished_callback, request))
924
		thread.run()
937
		thread.run()
(-)a/management/univention-management-console-module-udm/umc/python/udm/udm_ldap.py (-21 / +14 lines)
 Lines 275-281   def get_default_values(self, property_name): Link Here 
275
			if key == property_name:
275
			if key == property_name:
276
				value = default_value(prop.syntax)
276
				value = default_value(prop.syntax)
277
				if isinstance(value, (list, tuple)):
277
				if isinstance(value, (list, tuple)):
278
					value = read_syntax_choices(prop.syntax.name)
278
					value = read_syntax_choices(prop.syntax)
279
				return value
279
				return value
280
280
281
	def _map_properties(self, obj, properties):
281
	def _map_properties(self, obj, properties):
 Lines 1126-1141   def _get_syntax(syntax_name): Link Here 
1126
	return udm_syntax.__dict__[syntax_name]()
1126
	return udm_syntax.__dict__[syntax_name]()
1127
1127
1128
1128
1129
def search_syntax_choices_by_key(syntax_name, key):
1129
def search_syntax_choices_by_key(syn, key):
1130
	syn = _get_syntax(syntax_name)
1131
	if syn is None:
1132
		return None
1133
1134
	if issubclass(syn.__class__, udm_syntax.UDM_Objects):
1130
	if issubclass(syn.__class__, udm_syntax.UDM_Objects):
1135
		if syn.key == 'dn':
1131
		if syn.key == 'dn':
1136
			module_search_options = {'scope': 'base', 'container': key}
1132
			module_search_options = {'scope': 'base', 'container': key}
1137
			try:
1133
			try:
1138
				return read_syntax_choices(syntax_name, {}, module_search_options)
1134
				return read_syntax_choices(syn, {}, module_search_options)
1139
			except udm_errors.base:  # TODO: which exception is raised here exactly?
1135
			except udm_errors.base:  # TODO: which exception is raised here exactly?
1140
				# invalid DN
1136
				# invalid DN
1141
				return []
1137
				return []
 Lines 1144-1162   def search_syntax_choices_by_key(syntax_name, key): Link Here 
1144
			if match:
1140
			if match:
1145
				attr = match.groups()[0]
1141
				attr = match.groups()[0]
1146
				options = {'objectProperty': attr, 'objectPropertyValue': key}
1142
				options = {'objectProperty': attr, 'objectPropertyValue': key}
1147
				return read_syntax_choices(syntax_name, options)
1143
				return read_syntax_choices(syn, options)
1148
1144
1149
	MODULE.warn('Syntax "%s": No fast search function' % syntax_name)
1145
	MODULE.warn('Syntax %r: No fast search function' % syn.name)
1150
	# return them all, as there is no reason to filter after everything has loaded
1146
	# return them all, as there is no reason to filter after everything has loaded
1151
	# frontend will cache it.
1147
	# frontend will cache it.
1152
	return read_syntax_choices(syntax_name)
1148
	return read_syntax_choices(syn)
1153
1154
1149
1155
def info_syntax_choices(syntax_name, options={}):
1156
	syn = _get_syntax(syntax_name)
1157
	if syn is None:
1158
		return None
1159
1150
1151
def info_syntax_choices(syn, options={}):
1160
	if issubclass(syn.__class__, udm_syntax.UDM_Objects):
1152
	if issubclass(syn.__class__, udm_syntax.UDM_Objects):
1161
		size = 0
1153
		size = 0
1162
		if syn.static_values is not None:
1154
		if syn.static_values is not None:
 Lines 1176-1185   def info_syntax_choices(syntax_name, options={}): Link Here 
1176
1168
1177
1169
1178
@LDAP_Connection
1170
@LDAP_Connection
1179
def read_syntax_choices(syntax_name, options={}, module_search_options={}, ldap_connection=None, ldap_position=None):
1171
def read_syntax_choices(syn, options={}, module_search_options={}, ldap_connection=None, ldap_position=None):
1180
	syn = _get_syntax(syntax_name)
1172
	syntax_name = syn.name
1181
	if syn is None:
1182
		return None
1183
1173
1184
	if issubclass(syn.__class__, udm_syntax.UDM_Objects):
1174
	if issubclass(syn.__class__, udm_syntax.UDM_Objects):
1185
		syn.choices = []
1175
		syn.choices = []
 Lines 1350-1356   def map_choice(obj): Link Here 
1350
			syn.choices.append((dn, dn_list[0].split('=', 1)[1]))
1340
			syn.choices.append((dn, dn_list[0].split('=', 1)[1]))
1351
	elif issubclass(syn.__class__, udm_syntax.LDAP_Search):
1341
	elif issubclass(syn.__class__, udm_syntax.LDAP_Search):
1352
		options = options.get('options', {})
1342
		options = options.get('options', {})
1353
		syntax = udm_syntax.LDAP_Search(options['syntax'], options['filter'], options['attributes'], options['base'], options['value'], options['viewonly'], options['empty'], options['empty_end'])
1343
		try:
1344
			syntax = udm_syntax.LDAP_Search(options['syntax'], options['filter'], options['attributes'], options['base'], options['value'], options['viewonly'], options['empty'], options['empty_end'])
1345
		except KeyError:
1346
			syntax = syn
1354
1347
1355
		if '$dn$' in options:
1348
		if '$dn$' in options:
1356
			filter_mod = get_module(None, options['$dn$'])
1349
			filter_mod = get_module(None, options['$dn$'])
 Lines 1391-1397   def map_choice(obj): Link Here 
1391
					id = obj.oldattr[store][0]
1384
					id = obj.oldattr[store][0]
1392
				else:
1385
				else:
1393
					# no valid store object, ignore
1386
					# no valid store object, ignore
1394
					MODULE.warn('LDAP_Search syntax "%s": "%s" is no valid property for object "%s" - ignoring entry.' % (options['syntax'], store, dn))
1387
					MODULE.warn('LDAP_Search syntax %r: %r is no valid property for object %r - ignoring entry.' % (syntax.name, store, dn))
1395
					continue
1388
					continue
1396
1389
1397
			# find the value to display
1390
			# find the value to display

Return to bug 38635