diff options
author | Pavel Zuna <pzuna@redhat.com> | 2009-05-12 18:40:14 +0200 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2009-05-20 16:46:39 -0600 |
commit | 1e55b0a1ab7e0ca05dc2279fe1ecc21096384157 (patch) | |
tree | 6bbeb2b13501dfe7238389ff430b606f67287550 /ipalib/plugins | |
parent | a3ae5047f3a5492fcac48638e1150ee3348f34e8 (diff) | |
download | freeipa.git-1e55b0a1ab7e0ca05dc2279fe1ecc21096384157.tar.gz freeipa.git-1e55b0a1ab7e0ca05dc2279fe1ecc21096384157.tar.xz freeipa.git-1e55b0a1ab7e0ca05dc2279fe1ecc21096384157.zip |
Fix counting of successfully added members. Add checks for use_ldap2 in group2. Some cosmetic changes.
Diffstat (limited to 'ipalib/plugins')
-rw-r--r-- | ipalib/plugins/basegroup2.py | 32 | ||||
-rw-r--r-- | ipalib/plugins/group2.py | 23 |
2 files changed, 36 insertions, 19 deletions
diff --git a/ipalib/plugins/basegroup2.py b/ipalib/plugins/basegroup2.py index 189d9f0a..0235debe 100644 --- a/ipalib/plugins/basegroup2.py +++ b/ipalib/plugins/basegroup2.py @@ -27,7 +27,7 @@ from ipalib import Command, Object from ipalib import Flag, Int, List, Str _default_attributes = ['cn', 'description', 'member', 'memberOf'] -_default_class = 'groupofnames' +_default_class = 'groupOfNames' def get_dn_by_attr(ldap, attr, value, object_class, parent_dn=''): @@ -141,7 +141,7 @@ class basegroup2_create(crud.Create): """ Create new group. """ - base_classes = ("top", _default_class) + base_classes = ('top', _default_class) def execute(self, cn, **kw): """ @@ -405,7 +405,8 @@ class basegroup2_add_member(Command): """ Execute the group-add-member operation. - Returns the updated group entry + Returns a tuple containing the number of members added + and the updated entry. :param cn: The group name to add new members to. :param kw: groups is a comma-separated list of groups to add @@ -415,19 +416,18 @@ class basegroup2_add_member(Command): assert self.api.env.use_ldap2, 'use_ldap2 is False' ldap = self.api.Backend.ldap2 dn = get_dn_by_attr(ldap, 'cn', cn, self.filter_class, self.container) - add_failed = [] to_add = [] + add_failed = [] completed = 0 - total = 0 members = kw.get('groups', []) (to_add, add_failed) = find_members( - ldap, add_failed, members, 'cn', 'ipaUserGroup', self.container + ldap, add_failed, members, 'cn', 'ipaUserGroup', + self.api.env.container_group ) (completed, add_failed) = add_members( - ldap, completed, to_add, add_failed, dn, "member" + ldap, completed, to_add, add_failed, dn, 'member' ) - total += completed members = kw.get('users', []) (to_add, add_failed) = find_members( @@ -437,9 +437,8 @@ class basegroup2_add_member(Command): (completed, add_failed) = add_members( ldap, completed, to_add, add_failed, dn, 'member' ) - total += completed - return (total, ldap.get_entry(dn, self.default_attributes)) + return (completed, ldap.get_entry(dn, self.default_attributes)) def output_for_cli(self, textui, result, *args, **options): """ @@ -481,9 +480,10 @@ class basegroup2_del_member(Command): def execute(self, cn, **kw): """ - Execute the group-remove-member operation. + Execute the group-del-member operation. - Returns the members that could not be added + Returns a tuple containing the number of members removed + and the updated entry. :param cn: The group name to add new members to. :param kw: groups is a comma-separated list of groups to remove @@ -496,16 +496,15 @@ class basegroup2_del_member(Command): to_remove = [] remove_failed = [] completed = 0 - total = 0 members = kw.get('groups', []) (to_remove, remove_failed) = find_members( - ldap, remove_failed, members, 'cn', 'ipaUserGroup', self.container + ldap, remove_failed, members, 'cn', 'ipaUserGroup', + self.api.env.container_group ) (completed, remove_failed) = del_members( ldap, completed, to_remove, remove_failed, dn, 'member' ) - total += completed members = kw.get('users', []) (to_remove, remove_failed) = find_members( @@ -515,9 +514,8 @@ class basegroup2_del_member(Command): (completed, remove_failed) = del_members( ldap, completed, to_remove, remove_failed, dn, 'member' ) - total += completed - return (total, ldap.get_entry(dn, self.default_attributes)) + return (completed, ldap.get_entry(dn, self.default_attributes)) def output_for_cli(self, textui, result, *args, **options): """ diff --git a/ipalib/plugins/group2.py b/ipalib/plugins/group2.py index b3b0917f..1cadc3f5 100644 --- a/ipalib/plugins/group2.py +++ b/ipalib/plugins/group2.py @@ -29,6 +29,7 @@ _container_dn = api.env.container_group _default_attributes = ['cn', 'description', 'gidNumber', 'member', 'memberOf'] _default_class = 'ipaUserGroup' + class group2(basegroup2): """ Group object. @@ -177,6 +178,10 @@ class group2_find(basegroup2_find): container = _container_dn filter_class = _default_class + def execute(self, cn, **kw): + assert self.api.env.use_ldap2, 'use_ldap2 is False' + return super(group2_find, self).execute(cn, **kw) + api.register(group2_find) @@ -187,21 +192,35 @@ class group2_show(basegroup2_show): default_attributes = _default_attributes container = _container_dn + def execute(self, cn, **kw): + assert self.api.env.use_ldap2, 'use_ldap2 is False' + return super(group2_show, self).execute(cn, **kw) + api.register(group2_show) class group2_add_member(basegroup2_add_member): """ - Add member to group. + Add members to group. """ container = _container_dn + def execute(self, cn, **kw): + assert self.api.env.use_ldap2, 'use_ldap2 is False' + return super(group2_add_member, self).execute(cn, **kw) + api.register(group2_add_member) class group2_del_member(basegroup2_del_member): - 'Remove a member from a group.' + """ + Remove members from group. + """ container = _container_dn + def execute(self, cn, **kw): + assert self.api.env.use_ldap2, 'use_ldap2 is False' + return super(group2_del_member, self).execute(cn, **kw) + api.register(group2_del_member) |