diff --git a/docs/deployment.md b/docs/deployment.md
index 228dfef..eb04269 100644
--- a/docs/deployment.md
+++ b/docs/deployment.md
@@ -2709,6 +2709,10 @@ password. Preview the email before creating the account. To add a login
for an existing unassigned hosting account, open the account and choose
**Add customer login** or **Link existing customer**.
+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.
+
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
diff --git a/src/coulobre/hosting/account_administration.py b/src/coulobre/hosting/account_administration.py
index c0bdf22..11097a5 100644
--- a/src/coulobre/hosting/account_administration.py
+++ b/src/coulobre/hosting/account_administration.py
@@ -277,6 +277,10 @@ class AllUsersView(OperatorOnlyMixin, PermissionRequiredMixin, ListView):
(login, measurements.get(profile.pk) if profile else None)
for login, profile in zip(context["logins"], profiles, strict=True)
]
+ actor = self.request.user
+ context["may_manage_invitations"] = actor.has_perm(
+ "hosting.change_customer"
+ ) or actor.has_perm("hosting.change_reseller")
return context
diff --git a/src/coulobre/hosting/invitations.py b/src/coulobre/hosting/invitations.py
index 5d35ba0..cedb495 100644
--- a/src/coulobre/hosting/invitations.py
+++ b/src/coulobre/hosting/invitations.py
@@ -17,8 +17,10 @@ from django.shortcuts import get_object_or_404, redirect
from django.template.loader import render_to_string
from django.urls import reverse, reverse_lazy
from django.utils import timezone
+from django.utils.decorators import method_decorator
from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode
+from django.views.decorators.cache import never_cache
from django.views.decorators.debug import sensitive_variables
from django.views.generic import FormView
from kombu.exceptions import OperationalError
@@ -143,7 +145,7 @@ def enqueue_delivery(invitation_id, revision):
).update(delivery=PanelInvitation.Delivery.FAILED)
-@sensitive_variables("path", "message")
+@sensitive_variables("path", "context")
def deliver_invitation(invitation_id, revision):
pending = PanelInvitation.objects.filter(
pk=invitation_id,
@@ -166,6 +168,28 @@ def deliver_invitation(invitation_id, revision):
"token": invitation_token.make_token(user),
},
)
+ 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},
+ ),
+ )
+ if sent != 1:
+ raise OSError("The email backend did not accept the invitation.")
+ except (OSError, ValueError):
+ pending.update(delivery=PanelInvitation.Delivery.FAILED)
+ else:
+ pending.update(delivery=PanelInvitation.Delivery.SENT)
+
+
+def invitation_message_context(user, *, setup_url=""):
+ invitation = getattr(user, "panel_invitation", None)
account = (
HostingAccount.objects.filter(
customer__user=user, retired_at__isnull=True
@@ -179,10 +203,10 @@ def deliver_invitation(invitation_id, revision):
if account
else None
)
- message = render_welcome_message(
+ return welcome_message_context(
username=user.get_username(),
- welcome_message=invitation.welcome_message,
- setup_url=origin + path,
+ welcome_message=invitation.welcome_message if invitation else "",
+ setup_url=setup_url,
account=account,
nameservers=zone.nameservers if zone else (),
mail_configured=bool(
@@ -192,19 +216,9 @@ def deliver_invitation(invitation_id, revision):
).exists()
),
)
- try:
- sent = send_mail(
- "Your Coulobre Panel invitation", message, None, [user.email]
- )
- if sent != 1:
- raise OSError("The email backend did not accept the invitation.")
- except (OSError, ValueError):
- pending.update(delivery=PanelInvitation.Delivery.FAILED)
- else:
- pending.update(delivery=PanelInvitation.Delivery.SENT)
-def render_welcome_message(
+def welcome_message_context(
*,
username,
welcome_message,
@@ -213,24 +227,31 @@ def render_welcome_message(
nameservers,
mail_configured,
):
+ return {
+ "username": username,
+ "welcome_message": welcome_message,
+ "setup_url": setup_url,
+ "panel_url": (
+ settings.PASSWORD_RESET_ORIGIN.rstrip("/") + "/"
+ if settings.PASSWORD_RESET_ORIGIN
+ else ""
+ ),
+ "account": account,
+ "nameservers": nameservers,
+ "website_records": (
+ website_records(account.primary_domain, wildcard=False)
+ if account and not nameservers
+ else ()
+ ),
+ "imap_host": settings.MAIL_IMAP_HOST,
+ "submission_host": settings.MAIL_SUBMISSION_HOST,
+ "mail_configured": mail_configured,
+ }
+
+
+def render_welcome_message(**kwargs):
return render_to_string(
- "hosting/panel_invitation.txt",
- {
- "username": username,
- "welcome_message": welcome_message,
- "setup_url": setup_url,
- "panel_url": settings.PASSWORD_RESET_ORIGIN.rstrip("/") + "/",
- "account": account,
- "nameservers": nameservers,
- "website_records": (
- website_records(account.primary_domain, wildcard=False)
- if account and not nameservers
- else ()
- ),
- "imap_host": settings.MAIL_IMAP_HOST,
- "submission_host": settings.MAIL_SUBMISSION_HOST,
- "mail_configured": mail_configured,
- },
+ "hosting/panel_invitation.txt", welcome_message_context(**kwargs)
)
@@ -259,6 +280,7 @@ class InvitationEmailForm(forms.Form):
email = forms.EmailField(label="Contact email")
+@method_decorator(never_cache, name="dispatch")
class ManageInvitation(AccessMixin, FormView):
form_class = InvitationEmailForm
template_name = "hosting/manage_invitation.html"
@@ -292,10 +314,14 @@ class ManageInvitation(AccessMixin, FormView):
def get_context_data(self, **kwargs):
user = self.record.user
+ can_send = user.is_active and not user.has_usable_password()
return super().get_context_data(
login_user=user,
invitation=getattr(user, "panel_invitation", None),
- can_send=user.is_active and not user.has_usable_password(),
+ can_send=can_send,
+ welcome_preview=(
+ invitation_message_context(user) if can_send else None
+ ),
**kwargs,
)
diff --git a/src/coulobre/hosting/templates/hosting/all_users.html b/src/coulobre/hosting/templates/hosting/all_users.html
index 16c91bf..3303601 100644
--- a/src/coulobre/hosting/templates/hosting/all_users.html
+++ b/src/coulobre/hosting/templates/hosting/all_users.html
@@ -18,11 +18,29 @@
-
+ User Workspace Manager Hosting accounts Disk Monthly traffic Domains Databases Mailboxes Added
{% for login, usage in login_rows %}
- User Workspace Manager Hosting accounts Disk Monthly traffic Domains Databases Mailboxes Added {% if may_manage_invitations %}Actions {% endif %}
- {% empty %}{{ login.get_username }} {% if login.is_superuser %}Operator{% elif login.hosting_reseller %}Manager{% else %}Customer{% endif %} {{ login.hosting_customer.reseller|default:"Unassigned" }} {{ login.account_count }} {% include "hosting/account_metrics_cells.html" %}{{ login.date_joined|date:"j M Y" }} {% endfor %}
+ No logins found.
+
+ {% empty %}{{ login.get_username }}
+ {% if login.is_superuser %}Operator{% elif login.hosting_reseller %}Manager{% else %}Customer{% endif %}
+ {{ login.hosting_customer.reseller|default:"Unassigned" }}
+ {{ login.account_count }}
+ {% include "hosting/account_metrics_cells.html" %}
+ {{ login.date_joined|date:"j M Y" }}
+ {% if may_manage_invitations %}
+
+ {% if not login.is_staff and not login.is_superuser %}
+ {% if login.hosting_reseller and perms.hosting.change_reseller %}
+ Contact and invitation
+ {% elif not login.hosting_reseller and login.hosting_customer and perms.hosting.change_customer %}
+ Contact and invitation
+ {% endif %}
+ {% endif %}
+
+ {% endif %}
+ {% endfor %}
No logins found. Welcome email preview
+
+
|
+
+ {% include "hosting/panel_invitation_body.html" with message=invitation_content email_format=True %}
+
+ |
+
Your hosting provider created a panel login for you. Set your password within 48 hours.
+Username {{ message.username }}
+{% if message.setup_url %} + +{% else %} +Set your password
+{% endif %} +{% if message.panel_url %}{% endif %} +{% if message.account %} +Domain {{ message.account.primary_domain }}
+ {% with package=message.account.hosting_plan %} + {% if package %} +Hosting package {{ package.name }}
+To use Coulobre DNS, set these nameservers at your registrar.
+If your DNS is hosted elsewhere, add these records at your DNS provider.
+{{ record.name }} {{ record.record_type }} {{ record.address }}Use your full mailbox address as the username.
+{{ welcome_preview }}
+ {{ welcome_preview|force_escape }}