Prepare Coulobre Core 1.1.0 #232

Merged
parkel merged 12 commits from release/1.1.0 into main 2026-12-01 15:15:30 +01:00
4 changed files with 96 additions and 11 deletions
Showing only changes of commit 360ecc0af2 - Show all commits

No files matched your search

@@ -62,6 +62,9 @@ class CustomerOnboardingForm(InviteLoginForm):
manage_mail = forms.BooleanField(
required=False, label="Manage email in Coulobre"
)
setup_info_mailbox = forms.BooleanField(
required=False, initial=True, label="Create an info@ mailbox"
)
send_invitation = forms.BooleanField(
required=False, initial=True, label="Send a welcome email"
)
@@ -111,6 +114,8 @@ class CustomerOnboardingForm(InviteLoginForm):
capabilities["manage_mail"]
and panel_feature_allowed("LOCAL_MAILBOX_PROVISIONING")
)
if self.fields["manage_mail"].disabled:
del self.fields["setup_info_mailbox"]
def clean_primary_domain(self):
try:
@@ -235,13 +240,14 @@ class CustomerOnboardingView(UserPassesTestMixin, FormView):
mail_managed=data["manage_mail"],
)
defaults = zone_defaults()
setup_new_account(
notice = setup_new_account(
account,
{
"setup_website": capabilities["website"]
and panel_feature_allowed("LOCAL_WEB_ACTIVATION"),
"setup_dns": data["manage_dns"],
"setup_email": data["manage_mail"],
"setup_info_mailbox": data.get("setup_info_mailbox"),
"setup_www": defaults.include_www,
"setup_wildcard": defaults.include_wildcard,
},
@@ -268,6 +274,8 @@ class CustomerOnboardingView(UserPassesTestMixin, FormView):
messages.success(
self.request, "The customer and hosting account were created."
)
if notice:
messages.warning(self.request, notice)
return redirect(account)
+27 -3
View File
@@ -22,6 +22,7 @@ from .models import (
WebsiteDomain,
)
from .php_settings import plan_php_settings
from .resource_requests import create_mailbox_request
def website_records(domain, *, www=True, wildcard=True, addresses=None):
@@ -79,14 +80,37 @@ def setup_new_account(account, options):
account,
www=add_www,
wildcard=add_wildcard,
managed_mail=options.get("setup_email") or existing_managed_mail,
managed_mail=existing_managed_mail
or (
options.get("setup_email")
and panel_feature_allowed("MANAGE_MAIL_DNS")
),
)
if options.get("setup_email"):
_, created = HostingMailDomain.objects.get_or_create(
mail_domain, _ = HostingMailDomain.objects.get_or_create(
domain=domain, defaults={"account": account}
)
if not created:
if mail_domain.account_id != account.pk:
raise ValidationError("This domain already has email configured.")
if options.get("setup_info_mailbox"):
return setup_info_mailbox(account, options.get("setup_email"))
return ""
def setup_info_mailbox(account, managed_mail):
if not managed_mail or not panel_feature_allowed(
"LOCAL_MAILBOX_PROVISIONING"
):
return "The info@ mailbox was skipped. Email is not managed here."
if account.mail_domains.filter(
domain=account.primary_domain, mailboxes__local_part="info"
).exists():
return ""
try:
create_mailbox_request(account.pk, "info", auto_provision=True)
except ValidationError as error:
return f"The info@ mailbox was skipped. {' '.join(error.messages)}"
return ""
def default_dns_zone(account, *, www=None, wildcard=None, managed_mail=False):
@@ -40,6 +40,7 @@ class HostingAccountSetupTests(TestCase):
"setup_www": "on",
"setup_wildcard": "on",
"setup_email": "on",
"setup_info_mailbox": "on",
},
)
account = HostingAccount.objects.get(primary_domain="new.example.test")
@@ -64,9 +65,59 @@ class HostingAccountSetupTests(TestCase):
any("v=spf1" in record.text for record in zone.spec.txt_records)
)
self.assertEqual(account.mail_domains.get().dkim_record, "")
mailbox = account.mail_domains.get().mailboxes.get()
self.assertEqual(mailbox.local_part, "info")
self.assertEqual(mailbox.provisioning.state, "queued")
self.assertFalse(self.old_account.dns_zones.exists())
self.assertFalse(self.old_account.webprovisioningplan_set.exists())
@override_settings(MANAGE_MAIL_DNS=False)
def test_default_mailbox_with_external_dns_and_package_limits(self):
from .models import HostingPlan
self.client.force_login(self.operator)
url = reverse("panel:account_create")
self.assertTrue(
self.client.get(url).context["form"]["setup_info_mailbox"].value()
)
allowed = HostingPlan.objects.create(
name="Mailbox permitted", mailbox_limit=1, mailbox_quota_mib=256
)
blocked = HostingPlan.objects.create(name="No mail", mailbox_limit=0)
fields = {
"name": "Managed mail",
"setup_email": "on",
"setup_info_mailbox": "on",
}
self.client.post(
url,
fields
| {
"primary_domain": "managed.example.test",
"hosting_plan": allowed.pk,
},
)
account = HostingAccount.objects.get(
primary_domain="managed.example.test"
)
mailbox = account.mail_domains.get().mailboxes.get(local_part="info")
self.assertEqual(mailbox.quota_mib, 256)
self.assertFalse(account.dns_zones.exists())
response = self.client.post(
url,
fields
| {
"primary_domain": "blocked.example.test",
"hosting_plan": blocked.pk,
},
follow=True,
)
self.assertContains(response, "reached its mailbox limit")
account = HostingAccount.objects.get(
primary_domain="blocked.example.test"
)
self.assertFalse(account.mail_domains.get().mailboxes.exists())
def test_external_dns_has_copyable_records(self):
self.client.force_login(self.operator)
response = self.client.get(self.old_account.get_absolute_url())
+9 -7
View File
@@ -2,6 +2,7 @@ from operator import attrgetter
from django import forms
from django.conf import settings
from django.contrib import messages
from django.contrib.admin.models import ADDITION, CHANGE, LogEntry
from django.contrib.auth import get_user_model
from django.contrib.auth.mixins import PermissionRequiredMixin
@@ -491,6 +492,9 @@ class AccountCreate(PermissionRequiredMixin, AccountEditor, CreateView):
reseller
or actor.has_perms((*PUBLISH_DNS, "hosting.add_hostingdnszone"))
)
mail = panel_feature_allowed("LOCAL_MAILBOX_PROVISIONING") and (
reseller or actor.has_perms(PROVISION_MAILBOX)
)
choices = {
"setup_website": (web, "Set up the primary website"),
"setup_landing_page": (
@@ -500,12 +504,8 @@ class AccountCreate(PermissionRequiredMixin, AccountEditor, CreateView):
"setup_dns": (dns, "Publish a Coulobre DNS zone"),
"setup_www": (web or dns, "Include the www hostname"),
"setup_wildcard": (dns, "Include a wildcard (*) DNS record"),
"setup_email": (
panel_feature_allowed("LOCAL_MAILBOX_PROVISIONING")
and panel_feature_allowed("MANAGE_MAIL_DNS")
and (reseller or actor.has_perms(PROVISION_MAILBOX)),
"Set up email DNS for this domain",
),
"setup_email": (mail, "Manage email in Coulobre"),
"setup_info_mailbox": (mail, "Create an info@ mailbox"),
}
for name, (available, label) in choices.items():
if available:
@@ -580,7 +580,7 @@ class AccountCreate(PermissionRequiredMixin, AccountEditor, CreateView):
save_operator_account(self.object, actor.get_username())
else:
create_reseller_account(reseller, self.object)
setup_new_account(self.object, form.cleaned_data)
notice = setup_new_account(self.object, form.cleaned_data)
except ValidationError as error:
form.add_error(None, error)
return self.form_invalid(form)
@@ -591,6 +591,8 @@ class AccountCreate(PermissionRequiredMixin, AccountEditor, CreateView):
raise
form.add_error("primary_domain", "This domain is unavailable.")
return self.form_invalid(form)
if notice:
messages.warning(self.request, notice)
return redirect(self.object)