Add separate var for search attributes and config attribute for search fields

Add an optional search_attributes variable in case the attributes you
want to display by default aren't what you want to search on.

Also link in any cn=ipaconfig attributes that contain a comma-separated
list of attributes to search on.
This commit is contained in:
Rob Crittenden 2010-07-12 14:17:33 -04:00
parent ccaf537aa6
commit 371a4b2c72
3 changed files with 17 additions and 1 deletions

View File

@ -67,6 +67,8 @@ class LDAPObject(Object):
object_name_plural = 'entries'
object_class = []
object_class_config = None
search_attributes = []
search_attributes_config = None
default_attributes = []
hidden_attributes = ['objectclass', 'aci']
uuid_attribute = ''
@ -819,11 +821,23 @@ class LDAPSearch(CallbackInterface, crud.Search):
set(self.obj.default_attributes + search_kw.keys())
)
if self.obj.search_attributes:
search_attrs = self.obj.search_attributes
else:
search_attrs = self.obj.default_attributes
if self.obj.search_attributes_config:
config = ldap.get_ipa_config()[1]
config_attrs = config.get(
self.obj.search_attributes_config, [])
if len(config_attrs) == 1 and (
isinstance(config_attrs[0], basestring)):
search_attrs = config_attrs[0].split(',')
search_kw['objectclass'] = self.obj.object_class
attr_filter = ldap.make_filter(search_kw, rules=ldap.MATCH_ALL)
search_kw = {}
for a in self.obj.default_attributes:
for a in search_attrs:
search_kw[a] = term
term_filter = ldap.make_filter(search_kw, exact=False)

View File

@ -75,6 +75,7 @@ class group(LDAPObject):
object_name_plural = 'groups'
object_class = ['ipausergroup']
object_class_config = 'ipagroupobjectclasses'
search_attributes_config = 'ipagroupsearchfields'
default_attributes = [
'cn', 'description', 'gidnumber', 'member', 'memberof'
]

View File

@ -58,6 +58,7 @@ class user(LDAPObject):
object_name_plural = 'users'
object_class = ['posixaccount']
object_class_config = 'ipauserobjectclasses'
search_attributes_config = 'ipausersearchfields'
default_attributes = [
'uid', 'givenname', 'sn', 'homedirectory', 'loginshell', 'ou',
'telephonenumber', 'title', 'memberof',