Fixed mailbox removal.

see #1046
This commit is contained in:
Antoine Nguyen
2017-02-27 16:17:08 +01:00
parent 7e6f02a536
commit 55bdf3a82f
3 changed files with 12 additions and 9 deletions
@@ -2,10 +2,11 @@
import logging
import os
import shutil
from django.core.management.base import BaseCommand
from param_tools import tools as param_tools
from modoboa.parameters import tools as param_tools
from modoboa.lib.sysutils import exec_cmd
from modoboa.lib.exceptions import InternalError
@@ -52,13 +53,16 @@ class Command(BaseCommand):
raise OperationError(output)
def delete_mailbox(self, operation):
"""Try to delete a mailbox tree on filesystem."""
if not os.path.exists(operation.argument):
return
code, output = exec_cmd(
"rm -r %s" % operation.argument
)
if code:
raise OperationError(output)
def onerror(function, path, excinfo):
"""Handle errors."""
self.logger.critical(
"delete failed (reason: {})".format(excinfo))
shutil.rmtree(operation.argument, False, onerror)
def check_pidfile(self, path):
"""Check if this command is already running
+1 -2
View File
@@ -226,8 +226,7 @@ class Domain(AdminObject):
if self.alias_set.count():
ungrant_access_to_objects(self.alias_set.all())
if param_tools.get_global_parameter("auto_account_removal"):
for account in User.objects.filter(mailbox__domain=self):
account.delete(fromuser, keepdir)
User.objects.filter(mailbox__domain=self).delete()
elif self.mailbox_set.count():
Quota.objects.filter(username__contains="@%s" % self.name).delete()
ungrant_access_to_objects(self.mailbox_set.all())
+1 -1
View File
@@ -135,7 +135,7 @@ def editdomain(request, dom_id):
@login_required
@permission_required("admin.delete_domain")
def deldomain(request, dom_id):
keepdir = True if request.POST.get("keepdir", "false") == "true" else False
keepdir = request.POST.get("keepdir", "false") == "true"
try:
mb = Mailbox.objects.get(user__id=request.user.id)
except Mailbox.DoesNotExist: