New option to automaticaly remove accounts with mailboxes.

Beware: activating this mode will make domain removal longer.

fix #364
This commit is contained in:
Antoine Nguyen
2013-01-21 22:59:23 +01:00
parent 64c6bdde18
commit 2d89bb11ee
5 changed files with 26 additions and 5 deletions
+4
View File
@@ -23,6 +23,10 @@ parameters.register_admin("MAILBOX_TYPE", type="list", deflt="maildir",
parameters.register_admin("MAILDIR_ROOT", type="string", deflt=".maildir",
visible_if="MAILBOX_TYPE=maildir",
help=ugettext_lazy("Sub-directory (inside the mailbox) where messages are stored when using the maildir format"))
parameters.register_admin(
"AUTO_ACCOUNT_REMOVAL", type="list_yesno", deflt="no",
help=ugettext_lazy("When a mailbox is removed, also remove the associated account")
)
parameters.register_admin(
"PASSWORD_SCHEME", type="list", deflt="md5crypt",
values=[("crypt", "crypt"),
+5 -2
View File
@@ -558,7 +558,7 @@ class Domain(DatesAware):
self.name))
return True
def delete(self, keepdir=False):
def delete(self, fromuser, keepdir=False):
from modoboa.lib.permissions import ungrant_access_to_object, ungrant_access_to_objects
if self.domainalias_set.count():
@@ -570,6 +570,9 @@ class Domain(DatesAware):
if self.alias_set.count():
events.raiseEvent("MailboxAliasDelete", self.alias_set.all())
ungrant_access_to_objects(self.alias_set.all())
if parameters.get_admin("AUTO_ACCOUNT_REMOVAL") == "yes":
for account in User.objects.filter(mailbox__domain__name=self.name):
account.delete(fromuser, keepdir)
events.raiseEvent("DeleteDomain", self)
ungrant_access_to_object(self)
super(Domain, self).delete()
@@ -811,7 +814,7 @@ def mailbox_deleted_handler(sender, **kwargs):
alias.mboxes.remove(mb)
if alias.mboxes.count() == 0:
alias.delete()
class Alias(DatesAware):
address = models.CharField(
ugettext_lazy('address'), max_length=254,
+1
View File
@@ -113,6 +113,7 @@ Domains.prototype = {
$("a[name=deldomain]").confirm({
question: gettext("Delete this domain?"),
warning: gettext("This operation will remove ALL data associated to this domain."),
checkboxes: {keepdir: gettext("Do not delete domain directory")},
success_cb: $.proxy(this.reload_listing, this)
});
+1 -1
View File
@@ -153,7 +153,7 @@ def deldomain(request):
raise PermDeniedException
if mb and mb.domain == dom:
raise AdminError(_("You can't delete your own domain"))
dom.delete(keepdir=keepdir)
dom.delete(request.user, keepdir)
msg = ungettext("Domain deleted", "Domains deleted", len(selection))
return ajax_simple_response({"status" : "ok", "respmsg" : msg})
+15 -2
View File
@@ -38,8 +38,20 @@
});
box.append($('<div class="modal-body">'
+ '<h4>' + this.options.question + '</h4>'
+ '<p>' + this.buildcheckboxes() + '</p></div>'));
+ '<h4>' + this.options.question + '</h4>'));
var $container = $("<div />", {"class" : "container-fluid"});
box.append($container);
if (this.options.warning) {
$container.append($("<div />", {"class" : "row-fluid"})
.append($("<div />", {
"class": "alert alert-danger",
html: "<h4>" + gettext("Warning") + "</h4>" + this.options.warning
}))
);
}
$container.append('<p>' + this.buildcheckboxes() + '</p>');
box.append("</div>");
var footer = $('<div class="modal-footer" />');
var cancel_btn = $('<a href="#" class="btn">' + gettext("Cancel") + "</a>");
@@ -117,6 +129,7 @@
$.fn.confirm.defaults = {
question: "",
warning: null,
checkboxes: null
};