On 11/29/2011 03:46 PM, Ondrej Hamada wrote:
https://fedorahosted.org/freeipa/ticket/2045
'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.
forget to attach the patch, sorry :-[
--
Regards,
Ondrej Hamada
FreeIPA team
jabber: [email protected]
IRC: ohamada
From 8078a025aaa68fb55482bfe7b3c410773d0583d4 Mon Sep 17 00:00:00 2001
From: Ondrej Hamada <[email protected]>
Date: Tue, 29 Nov 2011 15:18:48 +0100
Subject: [PATCH] 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
---
ipalib/plugins/baseldap.py | 12 +++++++++---
ipalib/plugins/pwpolicy.py | 13 +++++++++++++
2 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index 4fd5fe4a1e7ff2d8fac7d3a65379b4ae0c5eb554..f35412f0abef6c1a6ca6881e0b475ee2e54e8d28 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -1434,6 +1434,9 @@ class LDAPSearch(CallbackInterface, crud.Search):
member_param_incl_doc = _('Search for %s with these %s %s.')
member_param_excl_doc = _('Search for %s without these %s %s.')
+ # if True, self.execute function won't sort the entries by 'cn' value
+ entries_sortfn = None
+
takes_options = (
Int('timelimit?',
label=_('Time Limit'),
@@ -1612,9 +1615,12 @@ class LDAPSearch(CallbackInterface, 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:
+ self.entries_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(self.entries_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 db42bca0424da34bc17b7df376d529bd60f55751..0f9175eb9691470ba94f4fcbbc2e4b76e5c0a199 100644
--- a/ipalib/plugins/pwpolicy.py
+++ b/ipalib/plugins/pwpolicy.py
@@ -455,7 +455,20 @@ 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
for e in entries:
--
1.7.6.4
_______________________________________________
Freeipa-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/freeipa-devel