diff options
author | Kevin McCarthy <kmccarth@redhat.com> | 2007-09-28 16:01:42 -0700 |
---|---|---|
committer | Kevin McCarthy <kmccarth@redhat.com> | 2007-09-28 16:01:42 -0700 |
commit | dbf8c1aeb98c730b7f4a83bfc15062040e331083 (patch) | |
tree | 4b1b422e9993d103bffb8764a5b6bc04388f7296 /ipa-server/xmlrpc-server/funcs.py | |
parent | 0cfccd0f8cf77fd2a4197cb47becea85173ca48a (diff) | |
download | freeipa-dbf8c1aeb98c730b7f4a83bfc15062040e331083.tar.gz freeipa-dbf8c1aeb98c730b7f4a83bfc15062040e331083.tar.xz freeipa-dbf8c1aeb98c730b7f4a83bfc15062040e331083.zip |
Add group management to the user edit page.
Added a couple more API calls to make the inverse operations easier.
Diffstat (limited to 'ipa-server/xmlrpc-server/funcs.py')
-rw-r--r-- | ipa-server/xmlrpc-server/funcs.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/ipa-server/xmlrpc-server/funcs.py b/ipa-server/xmlrpc-server/funcs.py index 838f05f12..e4e2f40e2 100644 --- a/ipa-server/xmlrpc-server/funcs.py +++ b/ipa-server/xmlrpc-server/funcs.py @@ -899,6 +899,56 @@ class IPAServer: return failed + def add_groups_to_user(self, group_dns, user_dn, opts=None): + """Given a list of group dn's add them to the user. + + Returns a list of the group dns that were not added. + """ + + failed = [] + + if (isinstance(group_dns, str)): + group_dns = [group_dns] + + for group_dn in group_dns: + # TODO - change add_member_to_group to take a group_dn + try: + group = self.get_group_by_dn(group_dn, ['cn'], opts) + self.add_member_to_group(user_dn, group.get('cn'), opts) + except ipaerror.exception_for(ipaerror.LDAP_EMPTY_MODLIST): + # User is already in the group + failed.append(group_dn) + except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND): + # User or the group does not exist + failed.append(group_dn) + + return failed + + def remove_groups_from_user(self, group_dns, user_dn, opts=None): + """Given a list of group dn's remove them from the user. + + Returns a list of the group dns that were not removed. + """ + + failed = [] + + if (isinstance(group_dns, str)): + group_dns = [group_dns] + + for group_dn in group_dns: + # TODO - change remove_member_from_group to take a group_dn + try: + group = self.get_group_by_dn(group_dn, ['cn'], opts) + self.remove_member_from_group(user_dn, group.get('cn'), opts) + except ipaerror.exception_for(ipaerror.LDAP_EMPTY_MODLIST): + # User is not in the group + failed.append(group_dn) + except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND): + # User or the group does not exist + failed.append(group_dn) + + return failed + def update_group (self, oldgroup, newgroup, opts=None): """Update a group in LDAP""" return self.__update_entry(oldgroup, newgroup, opts) |