1 parent
8cec7841f1
commit
5ec3d1fa77
24 files changed
+509
-28
No files matched your search
@@ -3094,6 +3094,21 @@ Keep the managed data directories on their service filesystems to allow
|
|||||||
an atomic move into the archive directory. Existing backup archives remain
|
an atomic move into the archive directory. Existing backup archives remain
|
||||||
available to operators with backup access.
|
available to operators with backup access.
|
||||||
|
|
||||||
|
### Remove a mailbox
|
||||||
|
|
||||||
|
On **Email Accounts**, choose **Remove mailbox** and confirm the full
|
||||||
|
address. Remove any forwarders or catch-all destination that use the
|
||||||
|
address first. If the job fails, retry it from the mailbox list. Removal
|
||||||
|
stops delivery and login for the selected address and releases its mailbox
|
||||||
|
slot after the mail node confirms the operation.
|
||||||
|
|
||||||
|
Operators can find the reference under **Hosting accounts → Email →
|
||||||
|
Archived mailboxes**. Retrieve the Maildir by that reference on the mail node
|
||||||
|
using the table above. To recover messages, provision the destination
|
||||||
|
mailbox first and import a private copy of the archived Maildir with
|
||||||
|
Dovecot. The archive is root-only and may contain private credentials.
|
||||||
|
Recover the messages from the Maildir and set a new password separately.
|
||||||
|
|
||||||
## Configure installed features in the panel
|
## Configure installed features in the panel
|
||||||
|
|
||||||
Open **About Coulobre → Configure features** as a superuser with a verified
|
Open **About Coulobre → Configure features** as a superuser with a verified
|
||||||
|
|||||||
@@ -236,6 +236,10 @@ def request_retirement(account_id, policy, confirmation, digest, actor):
|
|||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
"Remove folder SFTP logins before retiring the hosting account."
|
"Remove folder SFTP logins before retiring the hosting account."
|
||||||
)
|
)
|
||||||
|
if account.mailbox_removals.filter(mailbox__isnull=False).exists():
|
||||||
|
raise ValidationError(
|
||||||
|
"Finish the mailbox removal before retiring the account."
|
||||||
|
)
|
||||||
targets = cleanup_targets(account)
|
targets = cleanup_targets(account)
|
||||||
if policy == Policy.RELEASE:
|
if policy == Policy.RELEASE:
|
||||||
for kind, target, _ in targets:
|
for kind, target, _ in targets:
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ class DatabaseCredentialView(ServiceCredentialView):
|
|||||||
class MailboxCredentialView(ServiceCredentialView):
|
class MailboxCredentialView(ServiceCredentialView):
|
||||||
kind = CredentialKind.MAILBOX
|
kind = CredentialKind.MAILBOX
|
||||||
queryset = HostingMailbox.objects.filter(
|
queryset = HostingMailbox.objects.filter(
|
||||||
mail_domain__account__retired_at__isnull=True
|
mail_domain__account__retired_at__isnull=True, removal__isnull=True
|
||||||
).select_related("mail_domain__account")
|
).select_related("mail_domain__account")
|
||||||
customer_relation = "mail_domain__account__customer"
|
customer_relation = "mail_domain__account__customer"
|
||||||
|
|
||||||
|
|||||||
@@ -208,6 +208,7 @@ def domain_workspace(request, pk, page):
|
|||||||
"replies": "Automatic replies",
|
"replies": "Automatic replies",
|
||||||
}
|
}
|
||||||
from .mail_policies import mail_policy_available
|
from .mail_policies import mail_policy_available
|
||||||
|
from .mailbox_removal import can_remove_mailbox
|
||||||
from .roundcube import roundcube_available
|
from .roundcube import roundcube_available
|
||||||
|
|
||||||
defaults = zone_defaults() if page == "dns" else None
|
defaults = zone_defaults() if page == "dns" else None
|
||||||
@@ -241,6 +242,7 @@ def domain_workspace(request, pk, page):
|
|||||||
),
|
),
|
||||||
"can_edit_routing": mail_policy_available("routing"),
|
"can_edit_routing": mail_policy_available("routing"),
|
||||||
"can_edit_mailbox": mail_policy_available("vacation"),
|
"can_edit_mailbox": mail_policy_available("vacation"),
|
||||||
|
"can_remove_mailbox": can_remove_mailbox(request),
|
||||||
"show_mailbox_credentials": show_mailbox_credentials,
|
"show_mailbox_credentials": show_mailbox_credentials,
|
||||||
"show_mailbox_rotation": show_rotation_action(
|
"show_mailbox_rotation": show_rotation_action(
|
||||||
request, CredentialKind.MAILBOX
|
request, CredentialKind.MAILBOX
|
||||||
@@ -255,7 +257,9 @@ def domain_workspace(request, pk, page):
|
|||||||
),
|
),
|
||||||
"mail_imap_host": settings.MAIL_IMAP_HOST,
|
"mail_imap_host": settings.MAIL_IMAP_HOST,
|
||||||
"mail_submission_host": settings.MAIL_SUBMISSION_HOST,
|
"mail_submission_host": settings.MAIL_SUBMISSION_HOST,
|
||||||
"mailboxes": mail_domain.mailboxes.select_related("provisioning")
|
"mailboxes": mail_domain.mailboxes.select_related(
|
||||||
|
"provisioning", "removal"
|
||||||
|
)
|
||||||
if mail_domain
|
if mail_domain
|
||||||
else (),
|
else (),
|
||||||
"website": website,
|
"website": website,
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ def validate_policy(resource, spec, account):
|
|||||||
else:
|
else:
|
||||||
mailbox_ready = resource.__class__.objects.filter(
|
mailbox_ready = resource.__class__.objects.filter(
|
||||||
pk=resource.pk,
|
pk=resource.pk,
|
||||||
|
removal__isnull=True,
|
||||||
provisioning__finished_at__isnull=False,
|
provisioning__finished_at__isnull=False,
|
||||||
provisioning__problem="",
|
provisioning__problem="",
|
||||||
).exists()
|
).exists()
|
||||||
@@ -51,14 +52,17 @@ def validate_routing(domain, spec, plan):
|
|||||||
mailboxes = domain.mailboxes.all()
|
mailboxes = domain.mailboxes.all()
|
||||||
if mailboxes.filter(local_part__in=spec.aliases).exists():
|
if mailboxes.filter(local_part__in=spec.aliases).exists():
|
||||||
raise ValidationError("An alias cannot replace a requested mailbox.")
|
raise ValidationError("An alias cannot replace a requested mailbox.")
|
||||||
provisioned = {
|
configured = mailboxes.filter(
|
||||||
f"{local}@{domain.domain}"
|
|
||||||
for local in mailboxes.filter(
|
|
||||||
provisioning__finished_at__isnull=False,
|
provisioning__finished_at__isnull=False,
|
||||||
provisioning__problem="",
|
provisioning__problem="",
|
||||||
).values_list("local_part", flat=True)
|
)
|
||||||
|
provisioned = {
|
||||||
|
f"{local}@{domain.domain}"
|
||||||
|
for local in configured.filter(removal__isnull=True).values_list(
|
||||||
|
"local_part", flat=True
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if not provisioned:
|
if not provisioned and (spec.destinations or not configured.exists()):
|
||||||
raise ValidationError("Provision a mailbox on this mail domain first.")
|
raise ValidationError("Provision a mailbox on this mail domain first.")
|
||||||
for address in sorted(spec.destinations):
|
for address in sorted(spec.destinations):
|
||||||
if address.endswith(f"@{domain.domain}"):
|
if address.endswith(f"@{domain.domain}"):
|
||||||
|
|||||||
@@ -0,0 +1,166 @@
|
|||||||
|
from django import forms
|
||||||
|
from django.conf import settings
|
||||||
|
from django.contrib import messages
|
||||||
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.db import transaction
|
||||||
|
from django.http import Http404
|
||||||
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.utils.decorators import method_decorator
|
||||||
|
from django.utils.functional import cached_property
|
||||||
|
from django.views.decorators.cache import never_cache
|
||||||
|
from django.views.generic import FormView
|
||||||
|
|
||||||
|
from coulobre.mail_node import MailboxRemovalRequest
|
||||||
|
from coulobre.mail_policy import parse_mail_policy
|
||||||
|
|
||||||
|
from .access import can_manage_hosting, customer_for_user
|
||||||
|
from .domain_policies import require_managed
|
||||||
|
from .models import HostingAccount, HostingMailbox, MailboxRemoval
|
||||||
|
from .node_client import apply_on_local_node
|
||||||
|
from .resource_requests import lock_hosting_account, require_active_services
|
||||||
|
from .service_credentials import (
|
||||||
|
UNCONFIRMED_ROTATION,
|
||||||
|
CredentialKind,
|
||||||
|
rotation_history,
|
||||||
|
)
|
||||||
|
|
||||||
|
PERMISSIONS = ("hosting.view_hostingmailbox", "hosting.delete_hostingmailbox")
|
||||||
|
|
||||||
|
|
||||||
|
def can_remove_mailbox(request):
|
||||||
|
return (
|
||||||
|
settings.LOCAL_MAILBOX_PROVISIONING
|
||||||
|
and getattr(request, "impersonation", None) is None
|
||||||
|
and can_manage_hosting(request.user, PERMISSIONS)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@transaction.atomic
|
||||||
|
def request_removal(mailbox, actor, customer_id):
|
||||||
|
account = lock_hosting_account(mailbox.mail_domain.account_id, customer_id)
|
||||||
|
require_active_services(account)
|
||||||
|
current = HostingMailbox.objects.select_related("mail_domain").get(
|
||||||
|
pk=mailbox.pk, mail_domain__account=account
|
||||||
|
)
|
||||||
|
require_managed(account, current.mail_domain.domain, "mail_managed")
|
||||||
|
existing = getattr(current, "removal", None)
|
||||||
|
if existing is not None:
|
||||||
|
MailboxRemoval.objects.requeue(
|
||||||
|
MailboxRemoval.objects.filter(pk=existing.pk).exclude(problem=""),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
if getattr(current, "provisioning", None) is None or (
|
||||||
|
current.provisioning.state != "configured"
|
||||||
|
):
|
||||||
|
raise ValidationError("Complete the mailbox setup before removing it.")
|
||||||
|
rotation = rotation_history(
|
||||||
|
account.pk, CredentialKind.MAILBOX, str(current)
|
||||||
|
).first()
|
||||||
|
if rotation is not None and rotation.outcome in UNCONFIRMED_ROTATION:
|
||||||
|
raise ValidationError("Finish the mailbox password change first.")
|
||||||
|
vacation = getattr(current, "vacation", None)
|
||||||
|
if vacation is not None and vacation.finished_at is None:
|
||||||
|
raise ValidationError("Wait for the automatic reply change first.")
|
||||||
|
routing = getattr(current.mail_domain, "routing", None)
|
||||||
|
if routing is not None and (
|
||||||
|
routing.finished_at is None
|
||||||
|
or any(
|
||||||
|
str(current) in parse_mail_policy(manifest).destinations
|
||||||
|
for manifest in (routing.manifest, routing.applied_manifest)
|
||||||
|
if manifest
|
||||||
|
)
|
||||||
|
):
|
||||||
|
raise ValidationError(
|
||||||
|
"Remove forwarders and catch-all destinations that use this "
|
||||||
|
"mailbox, then wait for the routing change to apply."
|
||||||
|
)
|
||||||
|
MailboxRemoval.objects.create(
|
||||||
|
account=account, mailbox=current, actor=actor, address=str(current)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def apply_removal(job):
|
||||||
|
if job.mailbox is None:
|
||||||
|
return
|
||||||
|
request = MailboxRemovalRequest(job.mailbox.spec, str(job.archive_id))
|
||||||
|
apply_on_local_node(
|
||||||
|
request,
|
||||||
|
"/run/coulobre-mail-apply.sock",
|
||||||
|
"mail node",
|
||||||
|
"mailbox removal",
|
||||||
|
identity=request.identity(),
|
||||||
|
)
|
||||||
|
with transaction.atomic():
|
||||||
|
lock_hosting_account(job.account_id, customer_id=None)
|
||||||
|
HostingMailbox.objects.filter(pk=job.mailbox_id, removal=job).delete()
|
||||||
|
|
||||||
|
|
||||||
|
class ConfirmMailboxRemoval(forms.Form):
|
||||||
|
address = forms.CharField(label="Email address to remove", max_length=254)
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(never_cache, name="dispatch")
|
||||||
|
class MailboxRemovalView(PermissionRequiredMixin, FormView):
|
||||||
|
form_class = ConfirmMailboxRemoval
|
||||||
|
template_name = "hosting/mailbox_removal.html"
|
||||||
|
|
||||||
|
def has_permission(self):
|
||||||
|
return can_remove_mailbox(self.request)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def customer(self):
|
||||||
|
return customer_for_user(self.request.user)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def mailbox(self):
|
||||||
|
mailboxes = HostingMailbox.objects.select_related(
|
||||||
|
"mail_domain__account", "removal"
|
||||||
|
).filter(mail_domain__account__retired_at__isnull=True)
|
||||||
|
if self.customer is not None:
|
||||||
|
mailboxes = mailboxes.filter(
|
||||||
|
mail_domain__account__customer=self.customer
|
||||||
|
)
|
||||||
|
return get_object_or_404(mailboxes, pk=self.kwargs["pk"])
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
account = self.mailbox.mail_domain.account
|
||||||
|
if self.customer is not None:
|
||||||
|
return reverse(
|
||||||
|
"panel:domain_workspace",
|
||||||
|
args=[account.pk, "email"],
|
||||||
|
query={"domain": self.mailbox.mail_domain.domain},
|
||||||
|
)
|
||||||
|
return account.get_absolute_url() + "#email"
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
return super().get_context_data(
|
||||||
|
mailbox=self.mailbox,
|
||||||
|
removal=getattr(self.mailbox, "removal", None),
|
||||||
|
return_url=self.get_success_url(),
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
if form.cleaned_data["address"] != str(self.mailbox):
|
||||||
|
form.add_error(
|
||||||
|
"address", "Enter the full email address shown above."
|
||||||
|
)
|
||||||
|
return self.form_invalid(form)
|
||||||
|
try:
|
||||||
|
request_removal(
|
||||||
|
self.mailbox,
|
||||||
|
self.request.user,
|
||||||
|
self.customer.pk if self.customer is not None else None,
|
||||||
|
)
|
||||||
|
except (
|
||||||
|
HostingAccount.DoesNotExist,
|
||||||
|
HostingMailbox.DoesNotExist,
|
||||||
|
) as error:
|
||||||
|
raise Http404 from error
|
||||||
|
except ValidationError as error:
|
||||||
|
form.add_error(None, error)
|
||||||
|
return self.form_invalid(form)
|
||||||
|
messages.success(self.request, "Mailbox removal queued.")
|
||||||
|
return redirect(self.get_success_url())
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
# Generated by Django 5.2.19 on 2026-12-01 13:15
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
import django.utils.timezone
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("hosting", "0082_readable_database_names"),
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="MailboxRemoval",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
models.BigAutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"requested_at",
|
||||||
|
models.DateTimeField(default=django.utils.timezone.now),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"last_dispatched_at",
|
||||||
|
models.DateTimeField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
("started_at", models.DateTimeField(blank=True, null=True)),
|
||||||
|
("finished_at", models.DateTimeField(blank=True, null=True)),
|
||||||
|
("problem", models.TextField(blank=True)),
|
||||||
|
(
|
||||||
|
"archive_id",
|
||||||
|
models.UUIDField(
|
||||||
|
default=uuid.uuid4, editable=False, unique=True
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("address", models.CharField(max_length=254)),
|
||||||
|
(
|
||||||
|
"account",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="mailbox_removals",
|
||||||
|
to="hosting.hostingaccount",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"actor",
|
||||||
|
models.ForeignKey(
|
||||||
|
null=True,
|
||||||
|
on_delete=django.db.models.deletion.SET_NULL,
|
||||||
|
to=settings.AUTH_USER_MODEL,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"mailbox",
|
||||||
|
models.OneToOneField(
|
||||||
|
null=True,
|
||||||
|
on_delete=django.db.models.deletion.SET_NULL,
|
||||||
|
related_name="removal",
|
||||||
|
to="hosting.hostingmailbox",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
"abstract": False,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1523,6 +1523,27 @@ class MailboxProvisioning(ProvisioningJob):
|
|||||||
quota_update = models.BooleanField(default=False)
|
quota_update = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
|
||||||
|
class MailboxRemoval(ProvisioningJob):
|
||||||
|
archive_id = models.UUIDField(
|
||||||
|
default=uuid.uuid4, unique=True, editable=False
|
||||||
|
)
|
||||||
|
mailbox = models.OneToOneField(
|
||||||
|
HostingMailbox,
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
null=True,
|
||||||
|
related_name="removal",
|
||||||
|
)
|
||||||
|
account = models.ForeignKey(
|
||||||
|
HostingAccount,
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
related_name="mailbox_removals",
|
||||||
|
)
|
||||||
|
actor = models.ForeignKey(
|
||||||
|
settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True
|
||||||
|
)
|
||||||
|
address = models.CharField(max_length=254)
|
||||||
|
|
||||||
|
|
||||||
class MailPolicyPublication(ProvisioningJob):
|
class MailPolicyPublication(ProvisioningJob):
|
||||||
manifest = models.JSONField()
|
manifest = models.JSONField()
|
||||||
applied_manifest = models.JSONField(default=dict, blank=True)
|
applied_manifest = models.JSONField(default=dict, blank=True)
|
||||||
|
|||||||
@@ -157,6 +157,10 @@ def queue_mailbox_provisioning(mailbox):
|
|||||||
)
|
)
|
||||||
require_managed(account, mailbox.mail_domain.domain, "mail_managed")
|
require_managed(account, mailbox.mail_domain.domain, "mail_managed")
|
||||||
require_active_services(account)
|
require_active_services(account)
|
||||||
|
if not HostingMailbox.objects.filter(
|
||||||
|
pk=mailbox.pk, removal__isnull=True
|
||||||
|
).exists():
|
||||||
|
raise ValidationError("This mailbox is being removed.")
|
||||||
return MailboxProvisioning.objects.queue(mailbox=mailbox)
|
return MailboxProvisioning.objects.queue(mailbox=mailbox)
|
||||||
|
|
||||||
|
|
||||||
@@ -208,6 +212,8 @@ def change_mailbox_quota(mailbox, quota_mib, *, customer_id=None):
|
|||||||
current = HostingMailbox.objects.select_related("mail_domain").get(
|
current = HostingMailbox.objects.select_related("mail_domain").get(
|
||||||
pk=mailbox.pk, mail_domain__account=account
|
pk=mailbox.pk, mail_domain__account=account
|
||||||
)
|
)
|
||||||
|
if hasattr(current, "removal"):
|
||||||
|
raise ValidationError("This mailbox is being removed.")
|
||||||
if customer_id is not None:
|
if customer_id is not None:
|
||||||
require_managed(account, current.mail_domain.domain, "mail_managed")
|
require_managed(account, current.mail_domain.domain, "mail_managed")
|
||||||
limit = customer_mailbox_quota_limit(account)
|
limit = customer_mailbox_quota_limit(account)
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ def mailbox_can_open_webmail(mailbox):
|
|||||||
return (
|
return (
|
||||||
not account.services_suspended
|
not account.services_suspended
|
||||||
and account.retired_at is None
|
and account.retired_at is None
|
||||||
|
and not hasattr(mailbox, "removal")
|
||||||
and (job is None or job.state == "configured")
|
and (job is None or job.state == "configured")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -120,6 +120,10 @@ def current_service_jobs(account):
|
|||||||
def request_service_change(account_id, action, operator_username):
|
def request_service_change(account_id, action, operator_username):
|
||||||
account = lock_hosting_account(account_id, customer_id=None)
|
account = lock_hosting_account(account_id, customer_id=None)
|
||||||
require_open_account(account)
|
require_open_account(account)
|
||||||
|
if account.mailbox_removals.filter(mailbox__isnull=False).exists():
|
||||||
|
raise ValidationError(
|
||||||
|
"Finish the mailbox removal before changing account access."
|
||||||
|
)
|
||||||
previous = account.service_changes.first()
|
previous = account.service_changes.first()
|
||||||
jobs = list(previous.jobs.all()) if previous is not None else []
|
jobs = list(previous.jobs.all()) if previous is not None else []
|
||||||
if any(job.finished_at is None for job in jobs):
|
if any(job.finished_at is None for job in jobs):
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ from .backup_retention import plan_backup_expirations
|
|||||||
from .independent_websites import active_websites, apply_website_operation
|
from .independent_websites import active_websites, apply_website_operation
|
||||||
from .mail_dns_setup import sync_mail_dns
|
from .mail_dns_setup import sync_mail_dns
|
||||||
from .mail_policies import apply_policy, mail_policy_available
|
from .mail_policies import apply_policy, mail_policy_available
|
||||||
|
from .mailbox_removal import apply_removal
|
||||||
from .models import (
|
from .models import (
|
||||||
AccountBackupExpiration,
|
AccountBackupExpiration,
|
||||||
AccountBackupJob,
|
AccountBackupJob,
|
||||||
@@ -52,6 +53,7 @@ from .models import (
|
|||||||
HostingMailDomain,
|
HostingMailDomain,
|
||||||
IndependentWebsite,
|
IndependentWebsite,
|
||||||
MailboxProvisioning,
|
MailboxProvisioning,
|
||||||
|
MailboxRemoval,
|
||||||
MailDeliverySearch,
|
MailDeliverySearch,
|
||||||
MailRoutingPublication,
|
MailRoutingPublication,
|
||||||
MailVacationPublication,
|
MailVacationPublication,
|
||||||
@@ -311,6 +313,9 @@ def dispatch_mailbox_provisioning():
|
|||||||
dispatch_provisioning_jobs(
|
dispatch_provisioning_jobs(
|
||||||
MailboxProvisioning, provision_mailbox, MAILBOX_PROVISIONING_QUEUE
|
MailboxProvisioning, provision_mailbox, MAILBOX_PROVISIONING_QUEUE
|
||||||
)
|
)
|
||||||
|
dispatch_provisioning_jobs(
|
||||||
|
MailboxRemoval, remove_mailbox, MAILBOX_PROVISIONING_QUEUE
|
||||||
|
)
|
||||||
|
|
||||||
if mail_policy_available("routing"):
|
if mail_policy_available("routing"):
|
||||||
dispatch_provisioning_jobs(
|
dispatch_provisioning_jobs(
|
||||||
@@ -801,6 +806,17 @@ def apply_mailbox_provisioning(provisioning):
|
|||||||
provision_local_mailbox(provisioning.mailbox.spec)
|
provision_local_mailbox(provisioning.mailbox.spec)
|
||||||
|
|
||||||
|
|
||||||
|
@shared_task(acks_late=True, reject_on_worker_lost=True)
|
||||||
|
def remove_mailbox(removal_id):
|
||||||
|
if settings.LOCAL_MAILBOX_PROVISIONING:
|
||||||
|
run_provisioning_job(
|
||||||
|
MailboxRemoval.objects.select_related("mailbox__mail_domain"),
|
||||||
|
removal_id,
|
||||||
|
apply_removal,
|
||||||
|
"Could not reach the mail node. Check its connection and retry.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@shared_task(acks_late=True, reject_on_worker_lost=True)
|
@shared_task(acks_late=True, reject_on_worker_lost=True)
|
||||||
def publish_mail_routing(job_id):
|
def publish_mail_routing(job_id):
|
||||||
if mail_policy_available("routing"):
|
if mail_policy_available("routing"):
|
||||||
|
|||||||
@@ -332,6 +332,9 @@
|
|||||||
<td>{% if mailbox.quota_mib is not None %}{{ mailbox.quota_mib }} MiB{% else %}Unlimited{% endif %}</td>
|
<td>{% if mailbox.quota_mib is not None %}{{ mailbox.quota_mib }} MiB{% else %}Unlimited{% endif %}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="table-actions">
|
<div class="table-actions">
|
||||||
|
{% if mailbox.removal %}
|
||||||
|
<span class="status pending">Removal {{ mailbox.removal.state }}</span>
|
||||||
|
{% else %}
|
||||||
{% if manage_mailbox_provisioning %}
|
{% if manage_mailbox_provisioning %}
|
||||||
{% url 'panel:mailbox_provision' mailbox.pk as provision_url %}
|
{% url 'panel:mailbox_provision' mailbox.pk as provision_url %}
|
||||||
{% include "hosting/resource_provisioning.html" with provisioning=mailbox.provisioning enabled=local_mailbox_enabled action=provision_url resource=mailbox provision_label="Provision mailbox" %}
|
{% include "hosting/resource_provisioning.html" with provisioning=mailbox.provisioning enabled=local_mailbox_enabled action=provision_url resource=mailbox provision_label="Provision mailbox" %}
|
||||||
@@ -354,6 +357,7 @@
|
|||||||
{% if is_operator %}
|
{% if is_operator %}
|
||||||
<a class="record-link" href="{% url 'panel:mailbox_manifest' mailbox.pk %}" aria-label="Download mailbox manifest for {{ mailbox }}">Download manifest</a>
|
<a class="record-link" href="{% url 'panel:mailbox_manifest' mailbox.pk %}" aria-label="Download mailbox manifest for {{ mailbox }}">Download manifest</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
{% include "hosting/mailbox_management_links.html" %}
|
{% include "hosting/mailbox_management_links.html" %}
|
||||||
</div>
|
</div>
|
||||||
{% if is_operator and manage_mailbox_provisioning and mailbox.provisioning.problem %}
|
{% if is_operator and manage_mailbox_provisioning and mailbox.provisioning.problem %}
|
||||||
@@ -369,6 +373,19 @@
|
|||||||
<p class="empty">No mailboxes yet.</p>
|
<p class="empty">No mailboxes yet.</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</section>
|
</section>
|
||||||
|
{% if archived_mailboxes %}
|
||||||
|
<section class="surface">
|
||||||
|
<header class="section-heading"><h2>Archived mailboxes</h2></header>
|
||||||
|
<div class="table-scroll">
|
||||||
|
<table>
|
||||||
|
<thead><tr><th scope="col">Email address</th><th scope="col">Removed</th><th scope="col">Mail node archive ID</th></tr></thead>
|
||||||
|
<tbody>{% for archive in archived_mailboxes %}
|
||||||
|
<tr><th scope="row">{{ archive.address }}</th><td>{{ archive.finished_at }}</td><td><code>{{ archive.archive_id }}</code></td></tr>
|
||||||
|
{% endfor %}</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{% endif %}
|
||||||
</section>
|
</section>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if show_account_backups or export_backup_manifest %}
|
{% if show_account_backups or export_backup_manifest %}
|
||||||
|
|||||||
@@ -53,12 +53,14 @@
|
|||||||
<div class="table-scroll"><table>
|
<div class="table-scroll"><table>
|
||||||
<thead><tr><th scope="col">Email address</th><th scope="col">Quota</th><th scope="col">State</th><th scope="col">Actions</th></tr></thead>
|
<thead><tr><th scope="col">Email address</th><th scope="col">Quota</th><th scope="col">State</th><th scope="col">Actions</th></tr></thead>
|
||||||
<tbody>{% for mailbox in mailboxes %}<tr><th scope="row">{{ mailbox.spec.address }}</th><td>{{ mailbox.quota_mib|default_if_none:"Unlimited" }}{% if mailbox.quota_mib %} MiB{% endif %}</td><td>
|
<tbody>{% for mailbox in mailboxes %}<tr><th scope="row">{{ mailbox.spec.address }}</th><td>{{ mailbox.quota_mib|default_if_none:"Unlimited" }}{% if mailbox.quota_mib %} MiB{% endif %}</td><td>
|
||||||
{% if mailbox.provisioning.quota_update and mailbox.provisioning.state != 'configured' %}
|
{% if mailbox.removal %}
|
||||||
|
Removal {{ mailbox.removal.state }}
|
||||||
|
{% elif mailbox.provisioning.quota_update and mailbox.provisioning.state != 'configured' %}
|
||||||
Storage limit change {{ mailbox.provisioning.state }}
|
Storage limit change {{ mailbox.provisioning.state }}
|
||||||
{% else %}{{ mailbox.provisioning.state|default:"Requested"|capfirst }}{% endif %}
|
{% else %}{{ mailbox.provisioning.state|default:"Requested"|capfirst }}{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td><div class="form-actions">
|
<td><div class="form-actions">
|
||||||
{% if mailbox.provisioning.state == 'configured' %}
|
{% if mailbox.provisioning.state == 'configured' and not mailbox.removal %}
|
||||||
{% if show_mailbox_credentials %}
|
{% if show_mailbox_credentials %}
|
||||||
<a href="{% url 'panel:mailbox_credentials' mailbox.pk %}">Credentials</a>
|
<a href="{% url 'panel:mailbox_credentials' mailbox.pk %}">Credentials</a>
|
||||||
{% elif not show_mailbox_rotation and not customer_mailbox_quota %}Use the current mailbox password{% endif %}
|
{% elif not show_mailbox_rotation and not customer_mailbox_quota %}Use the current mailbox password{% endif %}
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
{% if show_mailbox_rotation and mailbox.provisioning.state == "configured" %}
|
{% if mailbox.removal %}
|
||||||
|
{% if can_remove_mailbox and mailbox.removal.problem %}
|
||||||
|
<a class="record-link" href="{% url 'panel:mailbox_removal' mailbox.pk %}" aria-label="Retry removal of {{ mailbox }}">Retry removal</a>
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
{% if show_mailbox_rotation and mailbox.provisioning.state == "configured" %}
|
||||||
<a class="record-link" href="{% url 'panel:mailbox_credential_rotation' mailbox.pk %}" aria-label="Change password for {{ mailbox }}">Change password</a>
|
<a class="record-link" href="{% url 'panel:mailbox_credential_rotation' mailbox.pk %}" aria-label="Change password for {{ mailbox }}">Change password</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if change_mailbox_quota or customer_mailbox_quota and mailbox.provisioning.state == "configured" %}
|
{% if change_mailbox_quota or customer_mailbox_quota and mailbox.provisioning.state == "configured" %}
|
||||||
<a class="record-link" href="{% url 'panel:mailbox_quota' mailbox.pk %}" aria-label="Change storage limit for {{ mailbox }}">Change storage limit</a>
|
<a class="record-link" href="{% url 'panel:mailbox_quota' mailbox.pk %}" aria-label="Change storage limit for {{ mailbox }}">Change storage limit</a>
|
||||||
{% elif customer_mailbox_quota and mailbox.provisioning.state == "failed" and mailbox.provisioning.quota_update %}
|
{% elif customer_mailbox_quota and mailbox.provisioning.state == "failed" and mailbox.provisioning.quota_update %}
|
||||||
<a class="record-link" href="{% url 'panel:mailbox_quota' mailbox.pk %}" aria-label="Retry storage limit change for {{ mailbox }}">Retry storage limit change</a>
|
<a class="record-link" href="{% url 'panel:mailbox_quota' mailbox.pk %}" aria-label="Retry storage limit change for {{ mailbox }}">Retry storage limit change</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if can_remove_mailbox and mailbox.provisioning.state == "configured" %}
|
||||||
|
<a class="record-link" href="{% url 'panel:mailbox_removal' mailbox.pk %}" aria-label="Remove {{ mailbox }}">Remove mailbox</a>
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
{% extends "hosting/base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Remove mailbox · Coulobre Panel{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<header class="page-heading">
|
||||||
|
<h1>Remove mailbox</h1>
|
||||||
|
<p class="heading-meta">{{ mailbox }}</p>
|
||||||
|
</header>
|
||||||
|
<section class="surface form-panel">
|
||||||
|
{% if removal.problem %}<p role="alert">{{ removal.problem }}</p>{% endif %}
|
||||||
|
{% if removal and not removal.problem %}
|
||||||
|
<p>Mailbox removal {{ removal.state }}.</p>
|
||||||
|
<a class="button secondary" href="{{ return_url }}">Back to mailboxes</a>
|
||||||
|
{% else %}
|
||||||
|
<p>Stop delivery and sign-in for this address. An operator can recover the archived messages on the mail server.</p>
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<div class="form-actions">
|
||||||
|
<button class="button danger" type="submit">{% if removal %}Retry removal{% else %}Remove mailbox{% endif %}</button>
|
||||||
|
<a class="button secondary" href="{{ return_url }}">Cancel</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
</section>
|
||||||
|
{% endblock %}
|
||||||
@@ -12,7 +12,12 @@ from uuid import uuid4
|
|||||||
|
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
|
|
||||||
from coulobre.mail_node import MailboxQuotaUpdate, MailboxSpec, main
|
from coulobre.mail_node import (
|
||||||
|
MailboxQuotaUpdate,
|
||||||
|
MailboxRemovalRequest,
|
||||||
|
MailboxSpec,
|
||||||
|
main,
|
||||||
|
)
|
||||||
from coulobre.mail_node_apply import (
|
from coulobre.mail_node_apply import (
|
||||||
apply_mailbox,
|
apply_mailbox,
|
||||||
check_dovecot_maildir,
|
check_dovecot_maildir,
|
||||||
@@ -81,6 +86,15 @@ class MailboxApplyRequestTests(SimpleTestCase):
|
|||||||
change.assert_called_once_with(mailbox)
|
change.assert_called_once_with(mailbox)
|
||||||
self.apply.assert_not_called()
|
self.apply.assert_not_called()
|
||||||
|
|
||||||
|
def test_removal_request_can_archive_an_active_mailbox(self):
|
||||||
|
removal = MailboxRemovalRequest(self.mailbox, str(uuid4()))
|
||||||
|
with patch("coulobre.mail_node_retirement.retire_mailbox") as retire:
|
||||||
|
code, reply = self.request(removal.manifest())
|
||||||
|
self.assertEqual(code, 0)
|
||||||
|
self.assertEqual(reply["operation_id"], removal.operation_id)
|
||||||
|
retire.assert_called_once_with(removal, allow_active=True)
|
||||||
|
self.apply.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
class MailboxApplyTests(SimpleTestCase):
|
class MailboxApplyTests(SimpleTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|||||||
@@ -15,9 +15,14 @@ from .models import (
|
|||||||
HostingMailDomain,
|
HostingMailDomain,
|
||||||
HostingPlan,
|
HostingPlan,
|
||||||
MailboxProvisioning,
|
MailboxProvisioning,
|
||||||
|
MailboxRemoval,
|
||||||
Reseller,
|
Reseller,
|
||||||
)
|
)
|
||||||
from .tasks import dispatch_mailbox_provisioning, provision_mailbox
|
from .tasks import (
|
||||||
|
dispatch_mailbox_provisioning,
|
||||||
|
provision_mailbox,
|
||||||
|
remove_mailbox,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@override_settings(LOCAL_MAILBOX_PROVISIONING=True)
|
@override_settings(LOCAL_MAILBOX_PROVISIONING=True)
|
||||||
@@ -124,6 +129,55 @@ class MailboxProvisioningTests(TestCase):
|
|||||||
self.assertEqual(job.state, "queued")
|
self.assertEqual(job.state, "queued")
|
||||||
self.assertFalse(job.problem)
|
self.assertFalse(job.problem)
|
||||||
|
|
||||||
|
def test_customer_mailbox_removal_retries_and_retains_archive_reference(
|
||||||
|
self,
|
||||||
|
):
|
||||||
|
MailboxProvisioning.objects.create(
|
||||||
|
mailbox=self.mailbox, finished_at=timezone.now()
|
||||||
|
)
|
||||||
|
self.client.force_login(self.customer)
|
||||||
|
url = reverse("panel:mailbox_removal", args=[self.mailbox.pk])
|
||||||
|
self.assertContains(self.client.get(url), "Remove mailbox")
|
||||||
|
self.assertContains(
|
||||||
|
self.client.post(url, {"address": "other@site.example"}),
|
||||||
|
"Enter the full email address",
|
||||||
|
)
|
||||||
|
self.assertFalse(MailboxRemoval.objects.exists())
|
||||||
|
self.assertEqual(
|
||||||
|
self.client.post(url, {"address": str(self.mailbox)}).status_code,
|
||||||
|
302,
|
||||||
|
)
|
||||||
|
job = MailboxRemoval.objects.get()
|
||||||
|
with patch(
|
||||||
|
"coulobre.hosting.mailbox_removal.apply_on_local_node",
|
||||||
|
side_effect=[OSError(), {}],
|
||||||
|
) as apply:
|
||||||
|
remove_mailbox.run(job.pk)
|
||||||
|
job.refresh_from_db()
|
||||||
|
self.assertEqual(job.state, "failed")
|
||||||
|
self.assertContains(self.client.get(url), "Retry removal")
|
||||||
|
self.client.post(url, {"address": str(self.mailbox)})
|
||||||
|
remove_mailbox.run(job.pk)
|
||||||
|
job.refresh_from_db()
|
||||||
|
self.assertEqual(job.state, "configured")
|
||||||
|
self.assertEqual(apply.call_args_list[0], apply.call_args_list[1])
|
||||||
|
self.assertIsNone(job.mailbox_id)
|
||||||
|
self.assertEqual(job.address, "support@site.example")
|
||||||
|
self.assertFalse(
|
||||||
|
HostingMailbox.objects.filter(pk=self.mailbox.pk).exists()
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_other_customer_cannot_remove_mailbox(self):
|
||||||
|
user = get_user_model().objects.create_user("other-customer")
|
||||||
|
Customer.objects.create(user=user)
|
||||||
|
self.client.force_login(user)
|
||||||
|
url = reverse("panel:mailbox_removal", args=[self.mailbox.pk])
|
||||||
|
self.assertEqual(
|
||||||
|
self.client.post(url, {"address": str(self.mailbox)}).status_code,
|
||||||
|
404,
|
||||||
|
)
|
||||||
|
self.assertFalse(MailboxRemoval.objects.exists())
|
||||||
|
|
||||||
def allow_quota_changes(self, user):
|
def allow_quota_changes(self, user):
|
||||||
user.user_permissions.add(
|
user.user_permissions.add(
|
||||||
Permission.objects.get(
|
Permission.objects.get(
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ from .mail_policy_views import (
|
|||||||
MailVacationEditor,
|
MailVacationEditor,
|
||||||
)
|
)
|
||||||
from .mail_queue_views import MailQueueIndex, MailQueueView, mail_queue_action
|
from .mail_queue_views import MailQueueIndex, MailQueueView, mail_queue_action
|
||||||
|
from .mailbox_removal import MailboxRemovalView
|
||||||
from .operator_backups import OperatorBackupsView
|
from .operator_backups import OperatorBackupsView
|
||||||
from .operator_tools import (
|
from .operator_tools import (
|
||||||
ConnectedNodesView,
|
ConnectedNodesView,
|
||||||
@@ -719,6 +720,11 @@ urlpatterns = [
|
|||||||
views.MailboxQuotaEdit.as_view(),
|
views.MailboxQuotaEdit.as_view(),
|
||||||
name="mailbox_quota",
|
name="mailbox_quota",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"mailboxes/<int:pk>/remove/",
|
||||||
|
MailboxRemovalView.as_view(),
|
||||||
|
name="mailbox_removal",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"mailboxes/<int:pk>/provision/",
|
"mailboxes/<int:pk>/provision/",
|
||||||
views.RequestMailboxProvisioning.as_view(),
|
views.RequestMailboxProvisioning.as_view(),
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ from .installation_features import (
|
|||||||
from .invitations import InviteLoginForm, queue_invitation
|
from .invitations import InviteLoginForm, queue_invitation
|
||||||
from .limit_forms import add_unlimited_fields
|
from .limit_forms import add_unlimited_fields
|
||||||
from .mail_policy_views import mail_policy_enabled
|
from .mail_policy_views import mail_policy_enabled
|
||||||
|
from .mailbox_removal import can_remove_mailbox
|
||||||
from .models import (
|
from .models import (
|
||||||
AccountBackupJob,
|
AccountBackupJob,
|
||||||
AccountBackupSchedule,
|
AccountBackupSchedule,
|
||||||
@@ -985,7 +986,16 @@ class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView):
|
|||||||
)
|
)
|
||||||
mailboxes = HostingMailbox.objects.filter(
|
mailboxes = HostingMailbox.objects.filter(
|
||||||
mail_domain__account=self.object
|
mail_domain__account=self.object
|
||||||
).select_related("mail_domain", "provisioning")
|
).select_related("mail_domain", "provisioning", "removal")
|
||||||
|
context["can_remove_mailbox"] = can_remove_mailbox(self.request)
|
||||||
|
if context["can_remove_mailbox"] and not tenant:
|
||||||
|
context["archived_mailboxes"] = (
|
||||||
|
self.object.mailbox_removals.filter(
|
||||||
|
mailbox__isnull=True,
|
||||||
|
finished_at__isnull=False,
|
||||||
|
problem="",
|
||||||
|
).order_by("-finished_at")[:20]
|
||||||
|
)
|
||||||
if not tenant and user.has_perms(PROVISION_MAILBOX):
|
if not tenant and user.has_perms(PROVISION_MAILBOX):
|
||||||
context["manage_mailbox_provisioning"] = True
|
context["manage_mailbox_provisioning"] = True
|
||||||
context["local_mailbox_enabled"] = panel_feature_allowed(
|
context["local_mailbox_enabled"] = panel_feature_allowed(
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ CUSTOMER_NAV_ROUTES = {
|
|||||||
"mailbox_credentials": "email",
|
"mailbox_credentials": "email",
|
||||||
"mailbox_credential_rotation": "email",
|
"mailbox_credential_rotation": "email",
|
||||||
"mailbox_quota": "email",
|
"mailbox_quota": "email",
|
||||||
|
"mailbox_removal": "email",
|
||||||
"mail_routing": "forwarders",
|
"mail_routing": "forwarders",
|
||||||
"mail_vacation": "replies",
|
"mail_vacation": "replies",
|
||||||
"mail_spam": "spam",
|
"mail_spam": "spam",
|
||||||
|
|||||||
@@ -165,6 +165,10 @@ class MailboxSigningRequest:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class MailboxRemovalRequest(RetirementRequest):
|
||||||
|
operation = "remove_mailbox"
|
||||||
|
|
||||||
|
|
||||||
def parse_mailbox_request(data):
|
def parse_mailbox_request(data):
|
||||||
from .mail_delivery import OPERATION, MailDeliveryRequest
|
from .mail_delivery import OPERATION, MailDeliveryRequest
|
||||||
from .mail_policy import OPERATIONS, parse_mail_policy
|
from .mail_policy import OPERATIONS, parse_mail_policy
|
||||||
@@ -188,6 +192,16 @@ def parse_mailbox_request(data):
|
|||||||
return MailQueueAction.from_manifest(data)
|
return MailQueueAction.from_manifest(data)
|
||||||
if isinstance(data, dict) and data.get("operation") in OPERATIONS:
|
if isinstance(data, dict) and data.get("operation") in OPERATIONS:
|
||||||
return parse_mail_policy(data)
|
return parse_mail_policy(data)
|
||||||
|
if (
|
||||||
|
isinstance(data, dict)
|
||||||
|
and data.get("operation") == MailboxRemovalRequest.operation
|
||||||
|
):
|
||||||
|
return parse_retirement(
|
||||||
|
data,
|
||||||
|
MailboxSpec.from_manifest,
|
||||||
|
parse_mailbox_apply,
|
||||||
|
MailboxRemovalRequest,
|
||||||
|
)
|
||||||
return parse_retirement(
|
return parse_retirement(
|
||||||
data, MailboxSpec.from_manifest, parse_mailbox_apply
|
data, MailboxSpec.from_manifest, parse_mailbox_apply
|
||||||
)
|
)
|
||||||
@@ -253,7 +267,9 @@ def apply_mailbox_request(request):
|
|||||||
if isinstance(request, RetirementRequest):
|
if isinstance(request, RetirementRequest):
|
||||||
from .mail_node_retirement import retire_mailbox
|
from .mail_node_retirement import retire_mailbox
|
||||||
|
|
||||||
retire_mailbox(request)
|
retire_mailbox(
|
||||||
|
request, allow_active=isinstance(request, MailboxRemovalRequest)
|
||||||
|
)
|
||||||
elif isinstance(request, ServiceAccessRequest):
|
elif isinstance(request, ServiceAccessRequest):
|
||||||
from .mail_node_quota import set_mailbox_access
|
from .mail_node_quota import set_mailbox_access
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from .node_retirement import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def retire_mailbox(request):
|
def retire_mailbox(request, *, allow_active=False):
|
||||||
mailbox = request.resource
|
mailbox = request.resource
|
||||||
path = mail.credential_path(mailbox)
|
path = mail.credential_path(mailbox)
|
||||||
with mail.locked_state(create=False, exclusive=True) as state:
|
with mail.locked_state(create=False, exclusive=True) as state:
|
||||||
@@ -43,12 +43,12 @@ def retire_mailbox(request):
|
|||||||
if os.path.lexists(path):
|
if os.path.lexists(path):
|
||||||
record = mail.load_credentials(path)
|
record = mail.load_credentials(path)
|
||||||
mail.check_registered_manifest(record, mailbox)
|
mail.check_registered_manifest(record, mailbox)
|
||||||
if not record.suspended or (
|
if not record.suspended and not allow_active:
|
||||||
not started and not mail.home_is_prepared(record)
|
|
||||||
):
|
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Suspend the managed mailbox before retiring it."
|
"Suspend the managed mailbox before retiring it."
|
||||||
)
|
)
|
||||||
|
if not started and not mail.home_is_prepared(record):
|
||||||
|
raise ValueError("Complete mailbox setup before retiring it.")
|
||||||
elif (
|
elif (
|
||||||
not started or not (retirement.directory / "credentials").is_file()
|
not started or not (retirement.directory / "credentials").is_file()
|
||||||
):
|
):
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ OPERATION = "retire_resource"
|
|||||||
class RetirementRequest:
|
class RetirementRequest:
|
||||||
resource: object
|
resource: object
|
||||||
operation_id: str
|
operation_id: str
|
||||||
|
operation = OPERATION
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
try:
|
try:
|
||||||
@@ -22,24 +23,30 @@ class RetirementRequest:
|
|||||||
raise ValueError("Expected a valid retirement operation ID.")
|
raise ValueError("Expected a valid retirement operation ID.")
|
||||||
|
|
||||||
def identity(self):
|
def identity(self):
|
||||||
return {"operation": OPERATION, "operation_id": self.operation_id}
|
return {
|
||||||
|
"operation": self.operation,
|
||||||
|
"operation_id": self.operation_id,
|
||||||
|
}
|
||||||
|
|
||||||
def manifest(self):
|
def manifest(self):
|
||||||
return {
|
return {
|
||||||
"operation": OPERATION,
|
"operation": self.operation,
|
||||||
"resource": self.resource.manifest(),
|
"resource": self.resource.manifest(),
|
||||||
"operation_id": self.operation_id,
|
"operation_id": self.operation_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def parse_retirement(data, parse_resource, fallback):
|
def parse_retirement(
|
||||||
if not isinstance(data, dict) or data.get("operation") != OPERATION:
|
data, parse_resource, fallback, request_type=RetirementRequest
|
||||||
|
):
|
||||||
|
if (
|
||||||
|
not isinstance(data, dict)
|
||||||
|
or data.get("operation") != request_type.operation
|
||||||
|
):
|
||||||
return fallback(data)
|
return fallback(data)
|
||||||
if data.keys() != {"operation", "resource", "operation_id"}:
|
if data.keys() != {"operation", "resource", "operation_id"}:
|
||||||
raise ValueError("Expected a retirement request.")
|
raise ValueError("Expected a retirement request.")
|
||||||
return RetirementRequest(
|
return request_type(parse_resource(data["resource"]), data["operation_id"])
|
||||||
parse_resource(data["resource"]), data["operation_id"]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class RetirementRecord:
|
class RetirementRecord:
|
||||||
|
|||||||
Reference in new issue
Block a user