Keep welcome previews in bounds and brand invitation emails

This commit is contained in:
parkel committed 2026-11-24 13:34:43 +01:00
1 parent c0f3f6c4fa
commit 5293e9497d
18 files changed
+297 -35

No files matched your search

+6
View File
@@ -2771,6 +2771,12 @@ Operators can open **Contact and invitation** from **Show All Users** to
review the welcome email and send a fresh password setup link to a pending
login. Sending a new invitation replaces the previous link.
Verified server administrators can edit the welcome email sender in
**Server Manager → Operator Settings → Email → Edit sender**. Leave the
From address blank to use the address configured for the installation.
Choose a From address accepted by the SMTP relay. The optional Reply-to
address directs replies to a separate inbox.
Managers handle customer onboarding and hosting assignments in their
portfolio. Customers manage their own website files, databases, mailboxes,
and other hosting resources in the customer workspace. Operators can
+1
View File
@@ -47,6 +47,7 @@ server = ["gunicorn>=27.0.1,<28"]
"static/hosting/*.js",
"static/hosting/*.css",
"static/hosting/*.svg",
"static/hosting/*.png",
"templates/*.html",
"templates/hosting/*.conf",
"templates/hosting/*.html",
@@ -29,7 +29,7 @@ from .installation_features import (
from .invitations import (
InviteLoginForm,
queue_invitation,
render_welcome_message,
welcome_message_context,
)
from .models import (
Customer,
@@ -189,10 +189,10 @@ class CustomerOnboardingView(UserPassesTestMixin, FormView):
data = form.cleaned_data
if self.request.POST.get("action") == "preview":
defaults = zone_defaults()
preview = render_welcome_message(
preview = welcome_message_context(
username=data["username"],
welcome_message=data["welcome_message"],
setup_url="[Personal password setup link]",
setup_url="",
account=HostingAccount(
primary_domain=data["primary_domain"],
hosting_plan=data["plan"],
+56 -1
View File
@@ -1,3 +1,4 @@
from email.utils import parseaddr
from importlib.metadata import PackageNotFoundError, version
from django import forms
@@ -15,7 +16,7 @@ from django.views.generic import FormView, TemplateView
from .access import is_tenant
from .installation_features import FEATURES, FeaturePolicy
from .models import PanelFeaturePolicy
from .models import InvitationMailSettings, PanelFeaturePolicy
from .update_views import inspect_linked_nodes
@@ -228,3 +229,57 @@ class FeatureConfigurationView(UserPassesTestMixin, FormView):
return self.render_to_response(
self.get_context_data(form=form), status=409
)
class InvitationMailSettingsForm(forms.ModelForm):
class Meta:
model = InvitationMailSettings
fields = ("sender_name", "sender_address", "reply_to")
labels = {
"sender_name": "Sender display name",
"sender_address": "From address",
"reply_to": "Reply-to address",
}
help_texts = {
"sender_name": "Leave blank to use the installed sender name.",
"sender_address": "Use an address your SMTP server allows.",
"reply_to": "Leave blank to receive replies at the From address.",
}
@method_decorator(never_cache, name="dispatch")
class InvitationMailSettingsView(UserPassesTestMixin, FormView):
form_class = InvitationMailSettingsForm
template_name = "hosting/invitation_mail_settings.html"
success_url = reverse_lazy("panel:invitation_mail_settings")
def test_func(self):
return (
self.request.user.is_superuser and self.request.user.is_verified()
)
def get_form_kwargs(self):
return super().get_form_kwargs() | {
"instance": InvitationMailSettings.objects.filter(pk=1).first(),
}
def get_context_data(self, **kwargs):
_, installed_address = parseaddr(settings.DEFAULT_FROM_EMAIL)
return super().get_context_data(
installed_address=installed_address, **kwargs
)
@transaction.atomic
def form_valid(self, form):
saved, _ = InvitationMailSettings.objects.update_or_create(
pk=1, defaults=form.cleaned_data
)
if form.has_changed():
LogEntry.objects.log_actions(
self.request.user.pk,
[saved],
CHANGE,
"Updated welcome email sender.",
)
messages.success(self.request, "Welcome email sender saved.")
return super().form_valid(form)
+65 -18
View File
@@ -1,5 +1,9 @@
import uuid
from datetime import timedelta
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.utils import parseaddr
from pathlib import Path
from django import forms
from django.conf import settings
@@ -10,7 +14,8 @@ from django.contrib.auth.views import (
INTERNAL_RESET_SESSION_TOKEN,
PasswordResetConfirmView,
)
from django.core.mail import send_mail
from django.core.mail import EmailMultiAlternatives
from django.core.mail.message import sanitize_address
from django.core.signing import BadSignature, Signer
from django.db import transaction
from django.shortcuts import get_object_or_404, redirect
@@ -27,7 +32,13 @@ from kombu.exceptions import OperationalError
from .access import customer_for_user, is_tenant, reseller_for_user
from .account_setup import website_records
from .models import Customer, HostingAccount, PanelInvitation, Reseller
from .models import (
Customer,
HostingAccount,
InvitationMailSettings,
PanelInvitation,
Reseller,
)
from .panel_factors import lock_user
from .password_reset import reset_enabled
@@ -170,16 +181,7 @@ def deliver_invitation(invitation_id, revision):
)
context = invitation_message_context(user, setup_url=origin + path)
try:
sent = send_mail(
"Welcome to Coulobre Panel",
render_to_string("hosting/panel_invitation.txt", context),
None,
[user.email],
html_message=render_to_string(
"hosting/panel_invitation.html",
{"invitation_content": context},
),
)
sent = invitation_email(user.email, context).send()
if sent != 1:
raise OSError("The email backend did not accept the invitation.")
except (OSError, ValueError):
@@ -188,6 +190,57 @@ def deliver_invitation(invitation_id, revision):
pending.update(delivery=PanelInvitation.Delivery.SENT)
class InvitationEmail(EmailMultiAlternatives):
def message(self):
message = super().message()
plain, html = message.get_payload()
logo_file = (
Path(__file__).parent / "static/hosting/coulobre-mail-mark.png"
)
logo = MIMEImage(logo_file.read_bytes(), _subtype="png")
logo.add_header("Content-ID", "<coulobre-welcome-logo>")
logo.add_header("Content-Disposition", "inline")
related = MIMEMultipart(
"related", _subparts=[html, logo], type="text/html"
)
message.set_payload([plain, related])
return message
@sensitive_variables("context")
def invitation_email(recipient, context):
mail_settings = (
InvitationMailSettings.objects.filter(pk=1).first()
or InvitationMailSettings()
)
sender = settings.DEFAULT_FROM_EMAIL
if mail_settings.sender_name or mail_settings.sender_address:
name, address = parseaddr(sender)
sender = sanitize_address(
(
mail_settings.sender_name or name,
mail_settings.sender_address or address,
),
settings.DEFAULT_CHARSET,
)
return InvitationEmail(
"Welcome to Coulobre Panel",
render_to_string("hosting/panel_invitation.txt", context),
sender,
[recipient],
reply_to=[mail_settings.reply_to] if mail_settings.reply_to else None,
alternatives=[
(
render_to_string(
"hosting/panel_invitation.html",
{"invitation_content": context},
),
"text/html",
)
],
)
def invitation_message_context(user, *, setup_url=""):
invitation = getattr(user, "panel_invitation", None)
account = (
@@ -249,12 +302,6 @@ def welcome_message_context(
}
def render_welcome_message(**kwargs):
return render_to_string(
"hosting/panel_invitation.txt", welcome_message_context(**kwargs)
)
class AcceptInvitation(PasswordResetConfirmView):
template_name = "hosting/accept_invitation.html"
token_generator = invitation_token
@@ -0,0 +1,45 @@
# Generated by Django 5.2.19 on 2026-11-24 12:32
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("hosting", "0079_onboarding_dismissal"),
]
operations = [
migrations.CreateModel(
name="InvitationMailSettings",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"sender_name",
models.CharField(
blank=True,
max_length=120,
validators=[
django.core.validators.RegexValidator(
"\\A[^\\x00-\\x1f\\x7f]*\\Z",
"Enter a single-line name.",
)
],
),
),
(
"sender_address",
models.EmailField(blank=True, max_length=254),
),
("reply_to", models.EmailField(blank=True, max_length=254)),
],
),
]
+14
View File
@@ -187,6 +187,20 @@ class PanelInvitation(models.Model):
)
class InvitationMailSettings(models.Model):
sender_name = models.CharField(
max_length=120,
blank=True,
validators=[
RegexValidator(
r"\A[^\x00-\x1f\x7f]*\Z", "Enter a single-line name."
)
],
)
sender_address = models.EmailField(blank=True)
reply_to = models.EmailField(blank=True)
class CustomerImpersonation(models.Model):
class EndReason(models.TextChoices):
STOPPED = "stopped", "Ended by administrator"
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

@@ -959,6 +959,11 @@ dd {
accent-color: var(--accent);
}
.welcome-email-preview {
min-width: 0;
overflow-wrap: anywhere;
}
.plan-field-heading {
position: relative;
display: flex;
@@ -9,6 +9,12 @@
{% endif %}
{% endblock %}
{% block page_content %}
{% if selected_section == 'email' %}
<section class="surface section-heading">
<h2>Welcome email sender</h2>
<a class="button secondary" href="{% url 'panel:invitation_mail_settings' %}">Edit sender</a>
</section>
{% endif %}
{% if selected_section == 'general' %}
<section class="surface section-heading">
<h2>Installation</h2>
@@ -0,0 +1,19 @@
{% extends "hosting/workspace_page.html" %}
{% block title %}Welcome email sender · Coulobre Panel{% endblock %}
{% block page_title %}Welcome email sender{% endblock %}
{% block page_context %}
<a class="quiet-link" href="{% url 'panel:operator_settings' 'email' %}">← Email settings</a>
{% endblock %}
{% block page_content %}
<section class="surface editor-surface">
<p>These settings apply to welcome emails. Leave the From address blank to use <strong>{{ installed_address }}</strong>.</p>
<form class="editor" method="post">
{% csrf_token %}
{{ form.as_div }}
<div class="form-actions">
<button class="button primary" type="submit">Save sender</button>
<a class="button secondary" href="{% url 'panel:operator_settings' 'email' %}">Cancel</a>
</div>
</form>
</section>
{% endblock %}
@@ -14,7 +14,7 @@
</div>
</form>
{% if welcome_preview %}
<details class="section-text">
<details class="section-text welcome-email-preview">
<summary>Welcome email preview</summary>
<p class="heading-meta">A password setup link is added when the invitation is sent.</p>
<div class="surface editor-surface">
@@ -5,13 +5,17 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Welcome to Coulobre Panel</title>
</head>
<body style="margin:0; padding:24px 12px; background:#f3f6f3; color:#162b25; font-family:Arial,sans-serif; line-height:1.5;">
<body style="margin:0; background:#f3f6f3; color:#162b25; font-family:Arial,sans-serif; font-size:16px; line-height:1.55;">
<table role="presentation" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<div style="max-width:560px; margin:auto; padding:24px; border:1px solid #d8e4dd; border-radius:12px; background:#ffffff; text-align:left;">
{% include "hosting/panel_invitation_body.html" with message=invitation_content email_format=True %}
</div>
<td align="center" style="padding:24px 12px;">
<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="max-width:600px; border:1px solid #d8e4dd; border-radius:12px; background:#fff;">
<tr>
<td style="padding:24px; text-align:left; overflow-wrap:anywhere;">
{% include "hosting/panel_invitation_body.html" with message=invitation_content email_format=True %}
</td>
</tr>
</table>
</td>
</tr>
</table>
@@ -1,19 +1,30 @@
{% load panel_assets %}
<table class="invitation-brand" role="presentation" cellspacing="0" cellpadding="0" style="width:auto; margin:0 0 16px; border-collapse:collapse;">
<tr>
<td style="padding:0 10px 0 0;"><img src="{% if email_format %}cid:coulobre-welcome-logo{% else %}{% panel_asset 'hosting/coulobre-mail-mark.png' %}{% endif %}" width="36" height="36" alt="" style="display:block;"></td>
<td style="padding:0; font-size:15px; font-weight:bold;">Coulobre Panel</td>
</tr>
</table>
<h2{% if email_format %} style="margin:0 0 12px; font-size:24px; line-height:1.25;"{% endif %}>Welcome to Coulobre Panel</h2>
{% if message.welcome_message %}{{ message.welcome_message|linebreaks }}{% endif %}
<p>Your hosting provider created a panel login for you. Set your password within 48 hours.</p>
<p><strong>Username</strong> {{ message.username }}</p>
<p><strong>Username</strong><br>{{ message.username }}</p>
{% if message.setup_url %}
<p style="margin:20px 0;"><a href="{{ message.setup_url }}" style="display:inline-block; padding:11px 18px; border-radius:6px; background:#1b6049; color:#ffffff; font-weight:bold; text-decoration:none;">Set your password</a></p>
<table role="presentation" cellspacing="0" cellpadding="0" style="margin:20px 0;">
<tr><td bgcolor="#1b6049" style="border-radius:6px;">
<a href="{{ message.setup_url }}" style="display:inline-block; padding:11px 18px; border-radius:6px; background:#1b6049; color:#fff; font-weight:bold;">Set your password</a>
</td></tr>
</table>
{% else %}
<p><strong>Set your password</strong></p>
{% endif %}
{% if message.panel_url %}<p><a href="{{ message.panel_url }}"{% if email_format %} style="color:#1b6049;"{% endif %}>Open Coulobre Panel</a></p>{% endif %}
{% if message.account %}
<h3>Your hosting</h3>
<p><strong>Domain</strong> {{ message.account.primary_domain }}</p>
<p><strong>Domain</strong><br>{{ message.account.primary_domain }}</p>
{% with package=message.account.hosting_plan %}
{% if package %}
<p><strong>Hosting package</strong> {{ package.name }}</p>
<p><strong>Hosting package</strong><br>{{ package.name }}</p>
<ul>
<li>Websites · {{ package.website_limit }}</li>
<li>Scheduled tasks · {{ package.website_job_limit }}</li>
@@ -10,9 +10,12 @@
{% csrf_token %}
{{ form.as_div }}
{% if welcome_preview %}
<details open>
<details class="welcome-email-preview" open>
<summary>Welcome email preview</summary>
<pre>{{ welcome_preview|force_escape }}</pre>
<p class="heading-meta">A password setup link is added when the invitation is sent.</p>
<div class="surface editor-surface">
{% include "hosting/panel_invitation_body.html" with message=welcome_preview %}
</div>
</details>
{% endif %}
{% if moving %}
@@ -140,6 +140,19 @@ class PanelAuthenticationTests(TestCase):
session = self.client.session
session["otp_device_id"] = device.persistent_id
session.save()
settings_url = reverse("panel:invitation_mail_settings")
config = {
"sender_name": "Hosting support",
"sender_address": "welcome@example.test",
"reply_to": "support@example.test",
}
self.assertRedirects(
self.client.post(settings_url, config), settings_url
)
self.assertContains(
self.client.post(settings_url, config | {"reply_to": "invalid"}),
"Enter a valid email address.",
)
recipient = "new@example.test"
def run_delivery(*, args, retry):
@@ -167,6 +180,10 @@ class PanelAuthenticationTests(TestCase):
self.assertEqual(len(mail.outbox), 1)
invitation = mail.outbox[0]
self.assertEqual(invitation.to, [recipient])
self.assertEqual(
invitation.from_email, "Hosting support <welcome@example.test>"
)
self.assertEqual(invitation.reply_to, ["support@example.test"])
self.assertIn("Username: new-user", invitation.body)
self.assertIn("48 hours", invitation.body)
link = self.invitation_path(invitation.body)
@@ -174,6 +191,15 @@ class PanelAuthenticationTests(TestCase):
self.assertEqual(content_type, "text/html")
self.assertIn("Welcome to Coulobre Panel", html)
self.assertIn(f'https://panel.example.test{link}"', html)
self.assertIn('src="cid:coulobre-welcome-logo"', html)
plain, related = invitation.message().get_payload()
self.assertEqual(plain.get_content_type(), "text/plain")
self.assertEqual(related.get_content_type(), "multipart/related")
markup, logo = related.get_payload()
self.assertEqual(markup.get_content_type(), "text/html")
self.assertEqual(logo.get_content_type(), "image/png")
self.assertEqual(logo["Content-ID"], "<coulobre-welcome-logo>")
self.assertTrue(logo.get_payload(decode=True).startswith(b"\x89PNG"))
manage_url = reverse(
"panel:manage_invitation", args=["customer", customer.pk]
@@ -219,6 +245,16 @@ class PanelAuthenticationTests(TestCase):
)
self.assertEqual(invited_browser.get(replacement).status_code, 302)
def test_customer_cannot_edit_the_welcome_email_sender(self):
self.client.force_login(self.customer)
url = reverse("panel:invitation_mail_settings")
self.assertEqual(
self.client.post(
url, {"sender_address": "other@example.test"}
).status_code,
403,
)
def invitation_path(self, body):
return urlsplit(
next(line for line in body.splitlines() if "/welcome/" in line)
+10 -1
View File
@@ -41,7 +41,11 @@ from .independent_website_views import (
IndependentWebsiteOperation,
IndependentWebsitePhpSettings,
)
from .installation_views import FeatureConfigurationView, InstallationView
from .installation_views import (
FeatureConfigurationView,
InstallationView,
InvitationMailSettingsView,
)
from .invitations import AcceptInvitation, ManageInvitation
from .mail_delivery_views import MailDeliveryView
from .mail_dns_views import MailDnsCheckView, RequestMailDnsSetup
@@ -296,6 +300,11 @@ urlpatterns = [
FeatureConfigurationView.as_view(),
name="operator_settings",
),
path(
"settings/email/sender/",
InvitationMailSettingsView.as_view(),
name="invitation_mail_settings",
),
path("account/role/", switch_panel_role, name="switch_panel_role"),
path(
"account/getting-started/",
+1
View File
@@ -70,6 +70,7 @@ WORKSPACE_PARENT_ROUTES = {
"remote_deploy": ("connected_nodes", ()),
"dns_topology": ("dns_defaults", ()),
"operator_settings": ("operator_settings", ("general",)),
"invitation_mail_settings": ("operator_settings", ("general",)),
"http_defaults": ("http_defaults", ("apache",)),
"server_updates": ("updates", ()),
"changelog": ("updates", ()),