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

Collapse All | Expand All

(-)file_not_specified_in_diff (-9 / +31 lines)
Line  Link Here
0
-- schoolldap.py.ORIG
0
++ schoolldap.py
Lines 34-39 import univention.config_registry Link Here
34
import univention.uldap
34
import univention.uldap
35
import univention.admin.config
35
import univention.admin.config
36
import univention.admin.modules
36
import univention.admin.modules
37
from univention.admin.uexceptions import noObject
37
38
38
import univention.admin.modules as udm_modules
39
import univention.admin.modules as udm_modules
39
from univention.management.console.protocol.message import Message
40
from univention.management.console.protocol.message import Message
Lines 436-463 class SchoolBaseModule(Base): Link Here
436
			groupObj = groupModule.object(None, ldap_connection, None, group)
437
			groupObj = groupModule.object(None, ldap_connection, None, group)
437
			groupObj.open()
438
			groupObj.open()
438
439
439
		users = cls.get_all(ldap_connection, school, LDAP_Filter.forUsers(pattern))
440
			# The following code block prevents a massive performance loss if the group
440
		users = [user.get_udm_object(ldap_connection) for user in users]
441
			# contains far less users than all available users. The else-block opens
441
		if groupObj:
442
			# all available users ==> high LDAP load! (Bug #42167)
442
			# filter users to be members of the specified group
443
			users = []
443
			users = [i for i in users if i.dn in set(groupObj['users'])]
444
			for userdn in set(groupObj['users']):
445
				try:
446
					user = cls.from_dn(userdn, school, ldap_connection)
447
				except noObject:
448
					continue
449
				if school not in user.schools:
450
					continue
451
				udm_obj = user.get_udm_object(ldap_connection)
452
				if pattern:
453
					# check if pattern is part of any of user's common properties (case insensitive)
454
					if not any([pattern.lower() in udm_obj.info.get(propertyname, '').lower() for propertyname in LDAP_Filter.forUsersSubMatch]):
455
						continue
456
				users.append(udm_obj)
457
		else:
458
			# be aware that this search opens all user objects of specified type and may take some time!
459
			users = cls.get_all(ldap_connection, school, LDAP_Filter.forUsers(pattern))
460
			users = [user.get_udm_object(ldap_connection) for user in users]
461
444
		return users
462
		return users
445
463
446
464
447
class LDAP_Filter:
465
class LDAP_Filter:
466
	forUsersSubMatch = ['lastname', 'username', 'firstname']
467
	forGroupsSubMatch = ['name', 'description']
468
	forComputersSubMatch = ['name', 'description']
469
	forComputersFullMatch = ['mac', 'ip']
448
470
449
	@staticmethod
471
	@staticmethod
450
	def forUsers( pattern ):
472
	def forUsers( pattern ):
451
		return LDAP_Filter.forAll( pattern, ['lastname', 'username', 'firstname'] )
473
		return LDAP_Filter.forAll(pattern, LDAP_Filter.forUsersSubMatch)
452
474
453
	@staticmethod
475
	@staticmethod
454
	def forGroups( pattern, school = None ):
476
	def forGroups( pattern, school = None ):
455
		# school parameter is deprecated
477
		# school parameter is deprecated
456
		return LDAP_Filter.forAll( pattern, ['name', 'description'] )
478
		return LDAP_Filter.forAll(pattern, LDAP_Filter.forGroupsSubMatch)
457
479
458
	@staticmethod
480
	@staticmethod
459
	def forComputers( pattern ):
481
	def forComputers( pattern ):
460
		return LDAP_Filter.forAll( pattern, ['name', 'description'], ['mac', 'ip'] )
482
		return LDAP_Filter.forAll(pattern, LDAP_Filter.forComputersSubMatch, LDAP_Filter.forComputersFullMatch)
461
483
462
	regWhiteSpaces = re.compile(r'\s+')
484
	regWhiteSpaces = re.compile(r'\s+')
463
	@staticmethod
485
	@staticmethod

Return to bug 42167