summaryrefslogtreecommitdiffstats
path: root/ipalib/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'ipalib/plugins')
-rw-r--r--ipalib/plugins/baseldap.py13
-rw-r--r--ipalib/plugins/pwpolicy.py12
2 files changed, 22 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:
diff --git a/ipalib/plugins/pwpolicy.py b/ipalib/plugins/pwpolicy.py
index db42bca0..2b586ec5 100644
--- a/ipalib/plugins/pwpolicy.py
+++ b/ipalib/plugins/pwpolicy.py
@@ -455,6 +455,18 @@ api.register(pwpolicy_show)
class pwpolicy_find(LDAPSearch):
__doc__ = _('Search for group password policies.')
+ def sort_priority(self,x,y):
+ # global policy will be always last in the output
+ if x[1]['cn'][0] == global_policy_name:
+ return 1
+ elif y[1]['cn'][0] == global_policy_name:
+ return -1
+ else:
+ # policies with higher priority will be at the beginning of the list
+ return cmp(int(x[1]['cospriority'][0]), int(y[1]['cospriority'][0]))
+
+ entries_sortfn = sort_priority
+
def post_callback(self, ldap, entries, truncated, *args, **options):
if options.get('pkey_only', False):
return False