Added new option to control mailbox creation.

see #1138
This commit is contained in:
Antoine Nguyen
2017-06-16 15:52:05 +02:00
parent ec08515942
commit defb934c95
4 changed files with 71 additions and 32 deletions
+31 -21
View File
@@ -201,6 +201,15 @@ class DomainFormOptions(forms.Form):
required=False
)
with_mailbox = YesNoField(
label=ugettext_lazy("With a mailbox"),
initial=True,
help_text=ugettext_lazy(
"Create a mailbox for the administrator."
),
required=False
)
create_aliases = YesNoField(
label=ugettext_lazy("Create aliases"),
initial=True,
@@ -260,28 +269,29 @@ class DomainFormOptions(forms.Form):
da.role = "DomainAdmins"
da.post_create(user)
dom_admin_username = self.cleaned_data["dom_admin_username"]
mb = Mailbox(
address=dom_admin_username, domain=domain,
user=da, use_domain_quota=True
)
mb.set_quota(
override_rules=user.has_perm("admin.change_domain"))
mb.save(creator=user)
if self.cleaned_data["with_mailbox"]:
dom_admin_username = self.cleaned_data["dom_admin_username"]
mb = Mailbox(
address=dom_admin_username, domain=domain,
user=da, use_domain_quota=True
)
mb.set_quota(
override_rules=user.has_perm("admin.change_domain"))
mb.save(creator=user)
condition = (
domain.type == "domain" and
self.cleaned_data["create_aliases"] and
dom_admin_username != "postmaster"
)
if condition:
core_signals.can_create_object.send(
self.__class__, context=user, klass=Alias)
address = u"postmaster@{}".format(domain.name)
alias = Alias.objects.create(
address=address, domain=domain, enabled=True)
alias.set_recipients([mb.full_address])
alias.post_create(user)
condition = (
domain.type == "domain" and
self.cleaned_data["create_aliases"] and
dom_admin_username != "postmaster"
)
if condition:
core_signals.can_create_object.send(
self.__class__, context=user, klass=Alias)
address = u"postmaster@{}".format(domain.name)
alias = Alias.objects.create(
address=address, domain=domain, enabled=True)
alias.set_recipients([mb.full_address])
alias.post_create(user)
domain.add_admin(da)
+10 -3
View File
@@ -7,9 +7,7 @@
* application.
*/
/*global
$ Listing
*/
/* global $ gettext Listing */
var Admin = function(options) {
Listing.call(this, options);
@@ -185,6 +183,7 @@ Domains.prototype = {
change_inputs_state: function(value) {
$("#id_dom_admin_username").attr("disabled", value);
$("input[name=with_mailbox]").attr("disabled", value);
$("input[name=create_aliases]").attr("disabled", value);
},
@@ -193,6 +192,12 @@ Domains.prototype = {
this.change_inputs_state(($target.val() === "True") ? false : true);
},
withMailboxChanged: function(e) {
var $target = $(e.target);
$("input[name=create_aliases]").attr(
"disabled", $target.val() === "False");
},
/**
* Initialize the main form contained in the domain edition modal.
*
@@ -214,6 +219,8 @@ Domains.prototype = {
optionsform_init: function() {
$("input[name=create_dom_admin]").click(
$.proxy(this.create_dom_admin_changed, this));
$("input[name=with_mailbox]").click(
$.proxy(this.withMailboxChanged, this));
this.change_inputs_state(
$("input[name=create_dom_admin]:checked").val() === "True" ? false : true
);
@@ -1,8 +1,10 @@
{% load i18n form_tags %}
{% if form.fields %}
{% render_field form.create_dom_admin %}
{% render_field form.dom_admin_username appended_text="@" %}
{% render_field form.create_aliases %}
{% render_field form.create_dom_admin %}
{% render_field form.dom_admin_username appended_text="@" %}
{% render_field form.with_mailbox %}
{% render_field form.create_aliases %}
{% else %}
<div class="alert alert-warning">{% trans "You can't create a new domain administrator" %}</div>
<div class="alert alert-warning">{% trans "You can't create a new domain administrator" %}</div>
{% endif %}
+24 -4
View File
@@ -55,7 +55,8 @@ class DomainTestCase(ModoTestCase):
values = {
"name": "pouet.com", "quota": 1000, "default_mailbox_quota": 100,
"create_dom_admin": True, "dom_admin_username": "toto",
"create_aliases": True, "type": "domain", "stepid": 'step3'
"with_mailbox": True, "create_aliases": True, "type": "domain",
"stepid": "step3"
}
self.ajax_post(reverse("admin:domain_add"), values)
dom = Domain.objects.get(name="pouet.com")
@@ -71,7 +72,8 @@ class DomainTestCase(ModoTestCase):
values = {
"name": "pouet2.com", "quota": 1000, "default_mailbox_quota": 100,
"create_dom_admin": True, "dom_admin_username": "postmaster",
"create_aliases": True, "type": "domain", "stepid": "step3"
"create_aliases": True, "type": "domain", "stepid": "step3",
"with_mailbox": True
}
self.ajax_post(reverse("admin:domain_add"), values)
self.assertTrue(
@@ -80,12 +82,29 @@ class DomainTestCase(ModoTestCase):
Alias.objects.filter(
address="postmaster@pouet2.com", internal=False).exists())
def test_create_with_template_and_no_mailbox(self):
"""Test domain creation with administrator but no mailbox."""
values = {
"name": "pouet.com", "quota": 1000, "default_mailbox_quota": 100,
"create_dom_admin": True, "dom_admin_username": "toto",
"with_mailbox": False, "create_aliases": True, "type": "domain",
"stepid": "step3"
}
self.ajax_post(reverse("admin:domain_add"), values)
dom = Domain.objects.get(name="pouet.com")
da = User.objects.get(username="toto@pouet.com")
self.assertIn(da, dom.admins)
self.assertFalse(hasattr(da, "mailbox"))
self.assertFalse(
Alias.objects.filter(address="postmaster@pouet.com").exists())
def test_create_with_template_and_empty_quota(self):
"""Test the creation of a domain with a template and no quota"""
values = {
"name": "pouet.com", "quota": 0, "default_mailbox_quota": 0,
"create_dom_admin": True, "dom_admin_username": "toto",
"create_aliases": True, "type": "domain", "stepid": 'step3'
"create_aliases": True, "type": "domain", "stepid": "step3",
"with_mailbox": True
}
self.ajax_post(
reverse("admin:domain_add"),
@@ -108,7 +127,8 @@ class DomainTestCase(ModoTestCase):
values = {
"name": "pouet.com", "quota": 0, "default_mailbox_quota": 0,
"create_dom_admin": True, "dom_admin_username": "toto",
"create_aliases": True, "type": "domain", "stepid": 'step3'
"create_aliases": True, "type": "domain", "stepid": "step3",
"with_mailbox": True
}
self.ajax_post(
reverse("admin:domain_add"),