summaryrefslogtreecommitdiffstats
path: root/ipalib/plugins/baseldap.py
diff options
context:
space:
mode:
authorMartin Kosek <mkosek@redhat.com>2012-04-25 16:24:20 +0200
committerMartin Kosek <mkosek@redhat.com>2012-04-26 14:31:53 +0200
commitb137b7137176fbcc02db0b9b9fdf53a896fdd11a (patch)
tree4af77975938f963c02007ac54fa4bdebb8b48f99 /ipalib/plugins/baseldap.py
parent81c65ee0b2961a96a7a3b2d072f6cb0ec6933a27 (diff)
downloadfreeipa-b137b7137176fbcc02db0b9b9fdf53a896fdd11a.tar.gz
freeipa-b137b7137176fbcc02db0b9b9fdf53a896fdd11a.tar.xz
freeipa-b137b7137176fbcc02db0b9b9fdf53a896fdd11a.zip
Sort password policies properly with --pkey-only
Password policy plugin sorts password policies by its COS priority. However, when the pwpolicy-find command is run with --pkey-only, the resulting entries do not contain COS priority and the sort function crashes. This patch makes sure that cospriority is present in the time of the result sorting process and removes the cospriority again when the sorting is done. This way, the entries are sorted properly both with and without --pkey-only flag. Previous entries_sortfn member attribute of LDAPSearch class containing custom user sorting function was replaced just with a flag indicating if a sorting in LDAPSearch shall be done at all. This change makes it possible to sort entries in a custom post_callback which is much more powerful (and essential for sorting like in pwpolicy plugin) approach than a plain sorting function. https://fedorahosted.org/freeipa/ticket/2676
Diffstat (limited to 'ipalib/plugins/baseldap.py')
-rw-r--r--ipalib/plugins/baseldap.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index 7ee5fa1e1..d37a20d1f 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -1675,9 +1675,10 @@ class LDAPSearch(BaseLDAPCommand, crud.Search):
member_param_incl_doc = _('Search for %(searched_object)s with these %(relationship)s %(ldap_object)s.')
member_param_excl_doc = _('Search for %(searched_object)s without these %(relationship)s %(ldap_object)s.')
- # pointer to function for entries sorting
- # if no function is assigned the entries are sorted by their primary key value
- entries_sortfn = None
+ # LDAPSearch sorts all matched records in the end using their primary key
+ # as a key attribute
+ # Set the following attribute to False to turn sorting off
+ sort_result_entries = True
takes_options = (
Int('timelimit?',
@@ -1846,12 +1847,10 @@ class LDAPSearch(BaseLDAPCommand, crud.Search):
else:
callback(self, ldap, entries, truncated, *args, **options)
- if not self.entries_sortfn:
+ if self.sort_result_entries:
if self.obj.primary_key:
sortfn=lambda x,y: cmp(x[1][self.obj.primary_key.name][0].lower(), y[1][self.obj.primary_key.name][0].lower())
entries.sort(sortfn)
- else:
- entries.sort(self.entries_sortfn)
if not options.get('raw', False):
for e in entries: