View | Details | Raw Unified | Return to bug 43286 | Differences between
and this patch

Collapse All | Expand All

(-)a/management/univention-directory-manager-modules/modules/univention/admin/handlers/__init__.py (+40 lines)
 Lines 527-532   def _ldap_pre_remove(self): Link Here 
527
	def _ldap_post_remove(self):
527
	def _ldap_post_remove(self):
528
		pass
528
		pass
529
529
530
	def remove_value(self, key, value=None):
531
		"""Removes a specific value from the specified property.
532
			If this value is currently not set univention.admin.uexceptions.valueNotSet is raised.
533
			if value is None the whole values of this property gets removed.
534
		"""
535
		if not self.has_key(key):
536
			raise univention.admin.uexceptions.noProperty(key)
537
538
		if value is None:
539
			# remove all currently set values
540
			self[key] = [] if self.descriptions[key].multivalue else None
541
			return
542
543
		if not self.contains_value(key, value):
544
			raise univention.admin.uexceptions.valueNotSet(key, value)
545
546
		if not self.descriptions[key].multivalue:
547
			self[key] = value
548
			return
549
550
		current_values = list(self[key])
551
		for val in current_values[:]:
552
			if self.compare_value(key, value, val):
553
				current_values.remove(val)
554
		self[key] = current_values
555
556
	def contains_value(self, key, value):
557
		if self.descriptions[key].multivalue and any(self.compare_value(key, value, val) for val in self[key]):
558
			return True
559
		if not self.descriptions[key].multivalue and self.compare_value(key, value, self[key]):
560
			return True
561
		return False
562
563
	def compare_value(self, key, a, b):
564
		return self.descriptions[key].syntax.compare(a, b)
565
566
	def append_value(self, key, value):
567
		if not self.has_key(key):
568
			raise univention.admin.uexceptions.noProperty(key)
569
530
570
531
def _not_implemented_method(attr):
571
def _not_implemented_method(attr):
532
	def _not_implemented_error(self, *args, **kwargs):
572
	def _not_implemented_error(self, *args, **kwargs):
(-)a/management/univention-directory-manager-modules/modules/univention/admin/syntax.py (-3 / +13 lines)
 Lines 138-143   def type(cls): Link Here 
138
	def tostring(self, text):
138
	def tostring(self, text):
139
		return text
139
		return text
140
140
141
	@classmethod
142
	def compare(cls, a, b):
143
		return a == b
144
141
145
142
class simple(ISyntax):
146
class simple(ISyntax):
143
	regex = None
147
	regex = None
 Lines 2055-2071   class soundModule(select): Link Here 
2055
	]
2059
	]
2056
2060
2057
2061
2058
class GroupDN(UDM_Objects):
2062
class _DNCompare(UDM_Objects):
2063
	@classmethod
2064
	def compare(cls, a, b):
2065
		return univention.admin.uldap.DN(a) == univention.admin.uldap.DN(b)
2066
2067
2068
class GroupDN(_DNCompare):
2059
	udm_modules = ('groups/group', )
2069
	udm_modules = ('groups/group', )
2060
	use_objects = False
2070
	use_objects = False
2061
2071
2062
2072
2063
class UserDN(UDM_Objects):
2073
class UserDN(_DNCompare):
2064
	udm_modules = ('users/user', )
2074
	udm_modules = ('users/user', )
2065
	use_objects = False
2075
	use_objects = False
2066
2076
2067
2077
2068
class HostDN(UDM_Objects):
2078
class HostDN(_DNCompare):
2069
	udm_modules = ('computers/computer', )
2079
	udm_modules = ('computers/computer', )
2070
	udm_filter = '!(univentionObjectFlag=docker)'
2080
	udm_filter = '!(univentionObjectFlag=docker)'
2071
2081
(-)a/management/univention-directory-manager-modules/modules/univention/admin/uexceptions.py (+4 lines)
 Lines 97-102   class valueMismatch(valueError): Link Here 
97
	message = _('Values do not match.')
97
	message = _('Values do not match.')
98
98
99
99
100
class valueNotSet(valueError):
101
	message = _('The value is not set.')
102
103
100
class noLock(base):
104
class noLock(base):
101
	message = _('Could not acquire lock.')
105
	message = _('Could not acquire lock.')
102
106
(-)a/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-60 / +38 lines)
 Lines 299-346   def object_input(module, object, input, append=None, remove=None): Link Here 
299
						except univention.admin.uexceptions.valueInvalidSyntax, errmsg:
299
						except univention.admin.uexceptions.valueInvalidSyntax, errmsg:
300
							out.append('E: Invalid Syntax: %s' % str(errmsg))
300
							out.append('E: Invalid Syntax: %s' % str(errmsg))
301
	if remove:
301
	if remove:
302
		for key, value in remove.items():
302
		for key, values in remove.items():
303
			if univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex):
303
			if not values:
304
				if value:
304
				values = [None]  # remove the whole property
305
					for i in range(0, len(value)):
306
						test_val = value[i].split('"')
307
						if test_val[0] and test_val[0] == value[i]:
308
							val = value[i].split(' ')
309
						else:
310
							val = []
311
							out.append('test_val=%s' % test_val)
312
							for j in test_val:
313
								if j and j.rstrip().lstrip():
314
									val.append(j.rstrip().lstrip())
315
316
							for j in range(0, len(val)):
317
								val[j] = '"%s"' % val[j]
318
319
						if val and val in object[key]:
320
							object[key].remove(val)
321
						else:
322
							out.append("WARNING: cannot remove %s from %s, value does not exist" % (val, key))
323
				else:
324
					object[key] = []
325
305
326
			else:
306
			if univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex):
327
				current_values = [object[key]] if isinstance(object[key], basestring) else list(object[key])
307
				parsed_values = []
328
				if value is None:
308
				for value in values:
329
					current_values = []
309
					if '"' not in value:
330
				else:
310
						value = value.split(' ')
331
					vallist = [value] if isinstance(value, basestring) else value
311
					else:
312
						value = ['"%s"' % (x.strip(),) for x in value.split('"') if x.strip()]
313
					parsed_values.append(value)
314
				values = parsed_values
332
315
333
					for val in vallist:
316
			for value in values:
334
						if val in current_values:
317
				try:
335
							current_values.remove(val)
318
					object.remove_value(key, value)
336
						else:
319
				except univention.admin.uexceptions.valueNotSet as exc:
337
							out.append("WARNING: cannot remove %s from %s, value does not exist" % (val, key))
320
					out.append("WARNING: cannot remove %s from %s: %s" % (value, key, exc))
338
				if not module.property_descriptions[key].multivalue:
339
					try:
340
						current_values = current_values[0]
341
					except IndexError:
342
						current_values = None
343
				object[key] = current_values
344
	if input:
321
	if input:
345
		for key, value in input.items():
322
		for key, value in input.items():
346
			if module.property_descriptions[key].syntax.name == 'binaryfile':
323
			if module.property_descriptions[key].syntax.name == 'binaryfile':
 Lines 669-696   def _doit(arglist): Link Here 
669
				out.append("WARNING: No attribute with name %s in this module, value not appended." % name)
646
				out.append("WARNING: No attribute with name %s in this module, value not appended." % name)
670
647
671
		elif opt == '--remove':
648
		elif opt == '--remove':
672
			pos = val.find('=')
649
			try:
673
			if pos == -1:
650
				name, value = val.split('=', 1)
651
			except ValueError:
674
				name = val
652
				name = val
675
				value = None
653
				remove[name] = None
676
			else:
654
			else:
677
				name = val[:pos]
655
				value = _2utf8(value)
678
				value = _2utf8(val[pos + 1:])
656
				remove.setdefault(name, []).append(value)
679
			was_set = False
657
#			was_set = False
680
			for mod, (properties, options) in information.items():
658
#			for mod, (properties, options) in information.items():
681
				if properties.has_key(name):
659
#				if properties.has_key(name):
682
					was_set = True
660
#					was_set = True
683
					if properties[name].multivalue:
661
#					if properties[name].multivalue:
684
						if value is None:
662
#						if value is None:
685
							remove[name] = value
663
#							remove[name] = value
686
						elif value:
664
#						elif value:
687
							remove.setdefault(name, [])
665
#							remove.setdefault(name, [])
688
							if remove[name] is not None:
666
#							if remove[name] is not None:
689
								remove[name].append(value)
667
#								remove[name].append(value)
690
					else:
668
#					else:
691
						remove[name] = value
669
#						remove[name] = value
692
			if not was_set:
670
#			if not was_set:
693
				out.append("WARNING: No attribute with name %s in this module, value not removed." % name)
671
#				out.append("WARNING: No attribute with name %s in this module, value not removed." % name)
694
		elif opt == '--remove_referring':
672
		elif opt == '--remove_referring':
695
			remove_referring = 1
673
			remove_referring = 1
696
		elif opt == '--recursive':
674
		elif opt == '--recursive':

Return to bug 43286