[Freeipa-devel] [PATCH] handle group add/del errors

Kevin McCarthy kmccarth at redhat.com
Wed Sep 19 20:47:02 UTC 2007


This isn't the best solution, but it's a first step.  With this commit,
I'm considering groups "good enough" and will start mocking out some
other parts of the app for discussion.

-Kevin

-------------- next part --------------
# HG changeset patch
# User Kevin McCarthy <kmccarth at redhat.com>
# Date 1190234632 25200
# Node ID b52e28ce1b72dd28344038cfa0ca8a3576ddf7bf
# Parent  cd0f7c22cb7ab4811d128d5682795683d86c4abd
Handle add/remove failures a little bit better.
Still some refinements that can be done, but at least it shows the failures
now.

diff -r cd0f7c22cb7a -r b52e28ce1b72 ipa-server/ipa-gui/ipagui/controllers.py
--- a/ipa-server/ipa-gui/ipagui/controllers.py	Tue Sep 11 02:48:53 2007 -0400
+++ b/ipa-server/ipa-gui/ipagui/controllers.py	Wed Sep 19 13:43:52 2007 -0700
@@ -446,7 +446,6 @@ class Root(controllers.RootController):
 
             return dict(form=group_edit_form, group=group_dict, members=member_dicts)
         except ipaerror.IPAError, e:
-            turbogears.flash("User show failed: " + str(e))
             turbogears.flash("Group edit failed: " + str(e))
             raise turbogears.redirect('/groupshow', uid=kw.get('cn'))
 
@@ -489,12 +488,12 @@ class Root(controllers.RootController):
 
             if group_modified:
                 rv = client.update_group(new_group)
-            #
-            # TODO - if the group update succeeds, but below operations fail,
-            # we needs to make sure a subsequent submit doesn't try to update
-            # the group again.  Probably by overwriting the group_orig hidden
-            # field blob.
-            #
+                #
+                # If the group update succeeds, but below operations fail, we
+                # need to make sure a subsequent submit doesn't try to update
+                # the group again.
+                #
+                kw['group_orig'] = b64encode(dumps(new_group.toDict()))
         except ipaerror.IPAError, e:
             turbogears.flash("User update failed: " + str(e))
             return dict(form=group_edit_form, group=kw, members=member_dicts,
@@ -503,15 +502,14 @@ class Root(controllers.RootController):
         #
         # Add members
         #
+        failed_adds = []
         try:
             uidadds = kw.get('uidadd')
             if uidadds != None:
                 if not(isinstance(uidadds,list) or isinstance(uidadds,tuple)):
                     uidadds = [uidadds]
-                failed = client.add_users_to_group(uidadds, kw.get('cn'))
-                #
-                # TODO - deal with failed adds
-                #
+                failed_adds = client.add_users_to_group(uidadds, kw.get('cn'))
+                kw['uidadd'] = failed_adds
         except ipaerror.IPAError, e:
             turbogears.flash("User update failed: " + str(e))
             return dict(form=group_edit_form, group=kw, members=member_dicts,
@@ -520,21 +518,36 @@ class Root(controllers.RootController):
         #
         # Remove members
         #
+        failed_dels = []
         try:
             uiddels = kw.get('uiddel')
             if uiddels != None:
                 if not(isinstance(uiddels,list) or isinstance(uiddels,tuple)):
                     uiddels = [uiddels]
-                failed = client.remove_users_from_group(uiddels, kw.get('cn'))
-                #
-                # TODO - deal with failed removals
-                #
+                failed_dels = client.remove_users_from_group(uiddels, kw.get('cn'))
+                kw['uiddel'] = failed_dels
         except ipaerror.IPAError, e:
             turbogears.flash("User update failed: " + str(e))
             return dict(form=group_edit_form, group=kw, members=member_dicts,
                         tg_template='ipagui.templates.groupedit')
 
-        # TODO if not group_modified
+        #
+        # TODO - check failed ops to see if it's because of another update.
+        #        handle "someone else already did it" errors better - perhaps
+        #        not even as an error
+        # TODO - update the Group Members list.
+        #        (note that we have to handle the above todo first, or else
+        #         there will be an error message, but the add/del lists will
+        #         be empty)
+        #
+        if (len(failed_adds) > 0) or (len(failed_dels) > 0):
+            message = "There was an error updating group members.<br />"
+            message += "Failures have been preserved in the add/remove lists."
+            if group_modified:
+                message = "Group Details successfully updated.<br />" + message
+            turbogears.flash(message)
+            return dict(form=group_edit_form, group=kw, members=member_dicts,
+                        tg_template='ipagui.templates.groupedit')
 
         turbogears.flash("%s updated!" % kw['cn'])
         raise turbogears.redirect('/groupshow', cn=kw['cn'])
diff -r cd0f7c22cb7a -r b52e28ce1b72 ipa-server/xmlrpc-server/funcs.py
--- a/ipa-server/xmlrpc-server/funcs.py	Tue Sep 11 02:48:53 2007 -0400
+++ b/ipa-server/xmlrpc-server/funcs.py	Wed Sep 19 13:43:52 2007 -0700
@@ -715,7 +715,7 @@ class IPAServer:
             except ipaerror.exception_for(ipaerror.LDAP_EMPTY_MODLIST):
                 # User is already in the group
                 failed.append(user)
-            except ipaerror.gen_exception(ipaerror.LDAP_NOT_FOUND):
+            except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND):
                 # User or the group does not exist
                 failed.append(user)
 
@@ -773,7 +773,7 @@ class IPAServer:
             except ipaerror.exception_for(ipaerror.LDAP_EMPTY_MODLIST):
                 # User is not in the group
                 failed.append(user)
-            except ipaerror.gen_exception(ipaerror.LDAP_NOT_FOUND):
+            except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND):
                 # User or the group does not exist
                 failed.append(user)
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2228 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/freeipa-devel/attachments/20070919/d088559d/attachment.bin>


More information about the Freeipa-devel mailing list