mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-10-13 17:02:02 -05:00
Add group management to the newgroup page.
This commit is contained in:
1 parent
59ee94e378
commit
050157ace0
4 files changed
+139
-11
No files matched your search
@@ -134,7 +134,7 @@ class Root(controllers.RootController):
|
|||||||
tg_template='ipagui.templates.usernew')
|
tg_template='ipagui.templates.usernew')
|
||||||
|
|
||||||
#
|
#
|
||||||
# Update the user itself
|
# Create the user itself
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
new_user = ipa.user.User()
|
new_user = ipa.user.User()
|
||||||
@@ -198,7 +198,7 @@ class Root(controllers.RootController):
|
|||||||
failed_adds = dnadds
|
failed_adds = dnadds
|
||||||
|
|
||||||
if len(failed_adds) > 0:
|
if len(failed_adds) > 0:
|
||||||
message = "Person successfully updated.<br />"
|
message = "Person successfully created.<br />"
|
||||||
message += "There was an error adding groups.<br />"
|
message += "There was an error adding groups.<br />"
|
||||||
message += "Failures have been preserved in the add/remove lists."
|
message += "Failures have been preserved in the add/remove lists."
|
||||||
turbogears.flash(message)
|
turbogears.flash(message)
|
||||||
@@ -569,7 +569,7 @@ class Root(controllers.RootController):
|
|||||||
|
|
||||||
client.set_krbccache(os.environ["KRB5CCNAME"])
|
client.set_krbccache(os.environ["KRB5CCNAME"])
|
||||||
|
|
||||||
return dict(form=group_new_form)
|
return dict(form=group_new_form, group={})
|
||||||
|
|
||||||
@expose()
|
@expose()
|
||||||
@identity.require(identity.not_anonymous())
|
@identity.require(identity.not_anonymous())
|
||||||
@@ -584,23 +584,73 @@ class Root(controllers.RootController):
|
|||||||
|
|
||||||
tg_errors, kw = self.groupcreatevalidate(**kw)
|
tg_errors, kw = self.groupcreatevalidate(**kw)
|
||||||
if tg_errors:
|
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:
|
try:
|
||||||
new_group = ipa.group.Group()
|
new_group = ipa.group.Group()
|
||||||
new_group.setValue('cn', kw.get('cn'))
|
new_group.setValue('cn', kw.get('cn'))
|
||||||
new_group.setValue('description', kw.get('description'))
|
new_group.setValue('description', kw.get('description'))
|
||||||
|
|
||||||
rv = client.add_group(new_group)
|
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):
|
except ipaerror.exception_for(ipaerror.LDAP_DUPLICATE):
|
||||||
turbogears.flash("Group with name '%s' already exists" %
|
turbogears.flash("Group with name '%s' already exists" %
|
||||||
kw.get('cn'))
|
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:
|
except ipaerror.IPAError, e:
|
||||||
turbogears.flash("Group add failed: " + str(e) + "<br/>" + str(e.detail))
|
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")
|
@expose("ipagui.templates.dynamiceditsearch")
|
||||||
@identity.require(identity.not_anonymous())
|
@identity.require(identity.not_anonymous())
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ class GroupNewValidator(validators.Schema):
|
|||||||
class GroupNewForm(widgets.Form):
|
class GroupNewForm(widgets.Form):
|
||||||
params = ['group']
|
params = ['group']
|
||||||
|
|
||||||
fields = [GroupFields.cn, GroupFields.description]
|
fields = [GroupFields.cn, GroupFields.description,
|
||||||
|
GroupFields.dn_to_info_json]
|
||||||
|
|
||||||
validator = GroupNewValidator()
|
validator = GroupNewValidator()
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,6 @@
|
|||||||
<body>
|
<body>
|
||||||
<h2>Add Group</h2>
|
<h2>Add Group</h2>
|
||||||
|
|
||||||
${form.display(action="groupcreate")}
|
${form.display(action="groupcreate", value=group)}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -1,6 +1,32 @@
|
|||||||
<div xmlns:py="http://purl.org/kid/ns#"
|
<div xmlns:py="http://purl.org/kid/ns#"
|
||||||
class="simpleroster">
|
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>
|
<div class="formsection">Group Details</div>
|
||||||
<table class="formtable" cellpadding="2" cellspacing="0" border="0">
|
<table class="formtable" cellpadding="2" cellspacing="0" border="0">
|
||||||
@@ -41,6 +67,28 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</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">
|
<table class="formtable" cellpadding="2" cellspacing="0" border="0">
|
||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
<th></th>
|
||||||
@@ -52,4 +100,33 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
</form>
|
</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>
|
</div>
|
||||||
Reference in new issue
Block a user