[Freeipa-devel] [PATCH] add group management to 'add group' page

Kevin McCarthy kmccarth at redhat.com
Mon Oct 1 20:50:33 UTC 2007


These should be looking pretty familiar by now.  The patch adds the
group member section to the 'add group' page.  This should be the last
page for this type of patch.

-Kevin

-------------- next part --------------
# HG changeset patch
# User Kevin McCarthy <kmccarth at redhat.com>
# Date 1191270460 25200
# Node ID 32edac7bca41673fbf399f73ddae55c08afbbf22
# Parent  23d9775392a14cb7dc860675deaec6889431b28d
Add group management to the newgroup page.

diff -r 23d9775392a1 -r 32edac7bca41 ipa-server/ipa-gui/ipagui/controllers.py
--- a/ipa-server/ipa-gui/ipagui/controllers.py	Mon Oct 01 11:26:22 2007 -0700
+++ b/ipa-server/ipa-gui/ipagui/controllers.py	Mon Oct 01 13:27:40 2007 -0700
@@ -134,7 +134,7 @@ class Root(controllers.RootController):
                     tg_template='ipagui.templates.usernew')
 
         #
-        # Update the user itself
+        # Create the user itself
         #
         try:
             new_user = ipa.user.User()
@@ -198,7 +198,7 @@ class Root(controllers.RootController):
             failed_adds = dnadds
 
         if len(failed_adds) > 0:
-            message = "Person successfully updated.<br />"
+            message = "Person successfully created.<br />"
             message += "There was an error adding groups.<br />"
             message += "Failures have been preserved in the add/remove lists."
             turbogears.flash(message)
@@ -569,7 +569,7 @@ class Root(controllers.RootController):
 
         client.set_krbccache(os.environ["KRB5CCNAME"])
 
-        return dict(form=group_new_form)
+        return dict(form=group_new_form, group={})
 
     @expose()
     @identity.require(identity.not_anonymous())
@@ -584,23 +584,73 @@ class Root(controllers.RootController):
 
         tg_errors, kw = self.groupcreatevalidate(**kw)
         if tg_errors:
-            return dict(form=group_new_form, tg_template='ipagui.templates.groupnew')
-
+            return dict(form=group_new_form, group=kw,
+                    tg_template='ipagui.templates.groupnew')
+
+        #
+        # Create the group itself
+        #
         try:
             new_group = ipa.group.Group()
             new_group.setValue('cn', kw.get('cn'))
             new_group.setValue('description', kw.get('description'))
 
             rv = client.add_group(new_group)
-            turbogears.flash("%s added!" % kw.get('cn'))
-            raise turbogears.redirect('/groupshow', cn=kw.get('cn'))
         except ipaerror.exception_for(ipaerror.LDAP_DUPLICATE):
             turbogears.flash("Group with name '%s' already exists" %
                     kw.get('cn'))
-            return dict(form=group_new_form, tg_template='ipagui.templates.groupnew')
+            return dict(form=group_new_form, group=kw,
+                    tg_template='ipagui.templates.groupnew')
         except ipaerror.IPAError, e:
             turbogears.flash("Group add failed: " + str(e) + "<br/>" + str(e.detail))
-            return dict(form=group_new_form, tg_template='ipagui.templates.groupnew')
+            return dict(form=group_new_form, group=kw,
+                    tg_template='ipagui.templates.groupnew')
+
+        #
+        # NOTE: from here on, the group now exists.
+        #       on any error, we redirect to the _edit_ group page.
+        #       this code does data setup, similar to groupedit()
+        #
+        group = client.get_group_by_cn(kw['cn'], group_fields)
+        group_dict = group.toDict()
+        member_dicts = []
+
+        # store a copy of the original group for the update later
+        group_data = b64encode(dumps(group_dict))
+        member_data = b64encode(dumps(member_dicts))
+        group_dict['group_orig'] = group_data
+        group_dict['member_data'] = member_data
+
+        # preserve group add info in case of errors
+        group_dict['dnadd'] = kw.get('dnadd')
+        group_dict['dn_to_info_json'] = kw.get('dn_to_info_json')
+
+        #
+        # Add members
+        #
+        failed_adds = []
+        try:
+            dnadds = kw.get('dnadd')
+            if dnadds != None:
+                if not(isinstance(dnadds,list) or isinstance(dnadds,tuple)):
+                    dnadds = [dnadds]
+                failed_adds = client.add_members_to_group(
+                        utf8_encode_values(dnadds), kw.get('cn'))
+                kw['dnadd'] = failed_adds
+        except ipaerror.IPAError, e:
+            failed_adds = dnadds
+
+        if len(failed_adds) > 0:
+            message = "Group successfully created.<br />"
+            message += "There was an error adding group members.<br />"
+            message += "Failures have been preserved in the add/remove lists."
+            turbogears.flash(message)
+            return dict(form=group_edit_form, group=group_dict,
+                        members=member_dicts,
+                        tg_template='ipagui.templates.groupedit')
+
+        turbogears.flash("%s added!" % kw.get('cn'))
+        raise turbogears.redirect('/groupshow', cn=kw.get('cn'))
 
     @expose("ipagui.templates.dynamiceditsearch")
     @identity.require(identity.not_anonymous())
diff -r 23d9775392a1 -r 32edac7bca41 ipa-server/ipa-gui/ipagui/forms/group.py
--- a/ipa-server/ipa-gui/ipagui/forms/group.py	Mon Oct 01 11:26:22 2007 -0700
+++ b/ipa-server/ipa-gui/ipagui/forms/group.py	Mon Oct 01 13:27:40 2007 -0700
@@ -21,7 +21,8 @@ class GroupNewForm(widgets.Form):
 class GroupNewForm(widgets.Form):
     params = ['group']
 
-    fields = [GroupFields.cn, GroupFields.description]
+    fields = [GroupFields.cn, GroupFields.description,
+              GroupFields.dn_to_info_json]
 
     validator = GroupNewValidator()
 
diff -r 23d9775392a1 -r 32edac7bca41 ipa-server/ipa-gui/ipagui/templates/groupnew.kid
--- a/ipa-server/ipa-gui/ipagui/templates/groupnew.kid	Mon Oct 01 11:26:22 2007 -0700
+++ b/ipa-server/ipa-gui/ipagui/templates/groupnew.kid	Mon Oct 01 13:27:40 2007 -0700
@@ -8,6 +8,6 @@
 <body>
     <h2>Add Group</h2>
 
-    ${form.display(action="groupcreate")}
+    ${form.display(action="groupcreate", value=group)}
 </body>
 </html>
diff -r 23d9775392a1 -r 32edac7bca41 ipa-server/ipa-gui/ipagui/templates/groupnewform.kid
--- a/ipa-server/ipa-gui/ipagui/templates/groupnewform.kid	Mon Oct 01 11:26:22 2007 -0700
+++ b/ipa-server/ipa-gui/ipagui/templates/groupnewform.kid	Mon Oct 01 13:27:40 2007 -0700
@@ -1,6 +1,32 @@
 <div xmlns:py="http://purl.org/kid/ns#"
   class="simpleroster">
-  <form action="${action}" name="${name}" method="${method}" class="tableform">
+  <form action="${action}" name="${name}" method="${method}" class="tableform"
+      onsubmit="preSubmit()" >
+
+<?python
+from ipagui.helpers import ipahelper
+?>
+
+  <script type="text/javascript" charset="utf-8"
+    src="${tg.url('/static/javascript/dynamicedit.js')}"></script>
+
+  <?python searchurl = tg.url('/groupedit_search') ?>
+
+  <script type="text/javascript">
+    function doSearch() {
+      $('searchresults').update("Searching...");
+      new Ajax.Updater('searchresults',
+          '${searchurl}',
+          {  asynchronous:true,
+             parameters: { criteria: $('criteria').value },
+             evalScripts: true });
+      return false;
+    }
+  </script>
+
+    <div py:for="field in hidden_fields"
+      py:replace="field.display(value_for(field), **params_for(field))" 
+      />
 
     <div class="formsection">Group Details</div>
     <table class="formtable" cellpadding="2" cellspacing="0" border="0">
@@ -41,6 +67,28 @@
       </tr>
     </table>
 
+    <div style="clear:both">
+      <div class="formsection">Add Members</div>
+
+      <div class="floatlist">
+        <div class="floatheader">To Add:</div>
+        <div id="newmembers">
+        </div>
+      </div>
+
+      <div>
+        <div id="search">
+          <input id="criteria" type="text" name="criteria"
+            onkeypress="return enterDoSearch(event);" />
+          <input type="button" value="Find"
+            onclick="return doSearch();"
+          />
+        </div>
+        <div id="searchresults">
+        </div>
+      </div>
+    </div>
+
     <table class="formtable" cellpadding="2" cellspacing="0" border="0">
       <tr>
         <th></th>
@@ -52,4 +100,33 @@
     </table>
 
   </form>
+
+  <script type="text/javascript">
+    /*
+     * This section restores the contents of the add and remove lists
+     * dynamically if we have to refresh the page
+     */
+    if ($('form_dn_to_info_json').value != "") {
+      dn_to_info_hash = new Hash($('form_dn_to_info_json').value.evalJSON());
+    }
+  </script>
+
+  <?python
+  dnadds = value.get('dnadd', [])
+  if not(isinstance(dnadds,list) or isinstance(dnadds,tuple)):
+      dnadds = [dnadds]
+  ?>
+
+  <script py:for="dnadd in dnadds">
+    <?python
+    dnadd_esc = ipahelper.javascript_string_escape(dnadd)
+    ?>
+    var dn = "${dnadd_esc}";
+    var info = dn_to_info_hash[dn];
+    var newdiv = addmember(dn, info);
+    if (newdiv != null) {
+      newdiv.style.display = 'block';
+    }
+  </script>
+
 </div>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 4054 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/freeipa-devel/attachments/20071001/7c57af08/attachment.bin>


More information about the Freeipa-devel mailing list