summaryrefslogtreecommitdiffstats
path: root/ipalib/plugins/baseldap.py
diff options
context:
space:
mode:
authorOndrej Hamada <ohamada@redhat.com>2011-12-02 13:51:35 +0100
committerRob Crittenden <rcritten@redhat.com>2011-12-01 18:04:30 -0500
commit8956fdbf40fab0259f65144678d1ffcc759771d9 (patch)
tree881a9d3c7ca9e64da3fcda85db2db6cacacb5dcf /ipalib/plugins/baseldap.py
parentc3dc08b93ffc3c98cef16200752ca2d3badeccd1 (diff)
downloadfreeipa.git-8956fdbf40fab0259f65144678d1ffcc759771d9.tar.gz
freeipa.git-8956fdbf40fab0259f65144678d1ffcc759771d9.tar.xz
freeipa.git-8956fdbf40fab0259f65144678d1ffcc759771d9.zip
Sort password policy by priority
'ipa pwpolicy-find' output is now sorted by priority of the policies. Lower position means lower priority. Global policy is then at the bottom. The changes has also affected LDAPSearch class in baseldap.py: LDAPSearch class sorts the search results by primary key be default (which is usually 'cn'). Therefor a function pointer entries_sortfn was added. If no sorting function exists, default sorting by primary key is used. Sorting function had to be introduced due to the fact that pwpolicy's primary key is also it's 'cn' and global policy is not allowed to have any priority. https://fedorahosted.org/freeipa/ticket/2045
Diffstat (limited to 'ipalib/plugins/baseldap.py')
-rw-r--r--ipalib/plugins/baseldap.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index cda0c497..2fdcd2b7 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -1548,6 +1548,10 @@ class LDAPSearch(BaseLDAPCommand, crud.Search):
member_param_incl_doc = _('Search for %s with these %s %s.')
member_param_excl_doc = _('Search for %s without these %s %s.')
+ # pointer to function for entries sorting
+ # if no function is assigned the entries are sorted by their primary key value
+ entries_sortfn = None
+
takes_options = (
Int('timelimit?',
label=_('Time Limit'),
@@ -1726,9 +1730,12 @@ class LDAPSearch(BaseLDAPCommand, crud.Search):
else:
callback(self, ldap, entries, truncated, *args, **options)
- 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)
+ if not self.entries_sortfn:
+ 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: