diff options
-rw-r--r-- | ipa-server/ipa-gui/ipagui/controllers.py | 66 | ||||
-rw-r--r-- | ipa-server/ipa-gui/ipagui/forms/group.py | 3 | ||||
-rw-r--r-- | ipa-server/ipa-gui/ipagui/templates/groupnew.kid | 2 | ||||
-rw-r--r-- | ipa-server/ipa-gui/ipagui/templates/groupnewform.kid | 79 |
4 files changed, 139 insertions, 11 deletions
diff --git a/ipa-server/ipa-gui/ipagui/controllers.py b/ipa-server/ipa-gui/ipagui/controllers.py index 36264351d..9e8f7114f 100644 --- a/ipa-server/ipa-gui/ipagui/controllers.py +++ b/ipa-server/ipa-gui/ipagui/controllers.py @@ -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 --git a/ipa-server/ipa-gui/ipagui/forms/group.py b/ipa-server/ipa-gui/ipagui/forms/group.py index 5c836ec17..82103aee8 100644 --- a/ipa-server/ipa-gui/ipagui/forms/group.py +++ b/ipa-server/ipa-gui/ipagui/forms/group.py @@ -21,7 +21,8 @@ class GroupNewValidator(validators.Schema): class GroupNewForm(widgets.Form): params = ['group'] - fields = [GroupFields.cn, GroupFields.description] + fields = [GroupFields.cn, GroupFields.description, + GroupFields.dn_to_info_json] validator = GroupNewValidator() diff --git a/ipa-server/ipa-gui/ipagui/templates/groupnew.kid b/ipa-server/ipa-gui/ipagui/templates/groupnew.kid index 14c618d06..083efd780 100644 --- a/ipa-server/ipa-gui/ipagui/templates/groupnew.kid +++ b/ipa-server/ipa-gui/ipagui/templates/groupnew.kid @@ -8,6 +8,6 @@ <body> <h2>Add Group</h2> - ${form.display(action="groupcreate")} + ${form.display(action="groupcreate", value=group)} </body> </html> diff --git a/ipa-server/ipa-gui/ipagui/templates/groupnewform.kid b/ipa-server/ipa-gui/ipagui/templates/groupnewform.kid index 66b7c43bb..17fd9013a 100644 --- a/ipa-server/ipa-gui/ipagui/templates/groupnewform.kid +++ b/ipa-server/ipa-gui/ipagui/templates/groupnewform.kid @@ -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> |