From 7b486c491b0775e8aa97f6d848f6b4f1095d8b88 Mon Sep 17 00:00:00 2001 From: Peter van Arkel Date: Fri, 4 Dec 2026 13:09:13 +0100 Subject: [PATCH] Separate current web configurations from provisioning history --- docs/development.md | 9 +- docs/panel-design.md | 5 + .../templates/hosting/account_detail.html | 23 ++-- .../templates/hosting/account_history.html | 45 ++++++++ .../templates/hosting/plan_detail.html | 34 ++++-- .../hosting/templates/hosting/plan_list.html | 49 ++++++-- .../hosting/templates/hosting/plan_table.html | 5 +- src/coulobre/hosting/test_customers.py | 6 +- src/coulobre/hosting/test_panel.py | 64 ++++++++++- src/coulobre/hosting/test_resellers.py | 2 +- src/coulobre/hosting/views.py | 107 ++++++++++++++---- src/coulobre/hosting/web_history.py | 44 +++++++ 12 files changed, 331 insertions(+), 62 deletions(-) create mode 100644 src/coulobre/hosting/templates/hosting/account_history.html create mode 100644 src/coulobre/hosting/web_history.py diff --git a/docs/development.md b/docs/development.md index f230a67..c95806d 100644 --- a/docs/development.md +++ b/docs/development.md @@ -873,10 +873,13 @@ celery -A coulobre worker --pool=solo celery -A coulobre beat ``` -Open an account in **Hosting accounts** and select **Request Apache preview**. +Open an account in **Hosting accounts**, select **History**, and choose +**Request Apache preview**. The preview page shows the request status and the configuration once the worker -finishes. Use **Refresh status** for pending requests or **Web provisioning** to -find earlier previews. Each request captures the primary domain at queue time. +finishes. Use **Refresh status** for pending requests or **Web provisioning → +History** to find earlier previews. **Current configurations** lists the last +successfully applied Apache configuration for each primary website. Each +preview request captures the primary domain at queue time. The preview references the future document root and PHP-FPM socket for the account. Preview generation makes no changes to the hosting services. diff --git a/docs/panel-design.md b/docs/panel-design.md index 7c26ade..f6d8aaa 100644 --- a/docs/panel-design.md +++ b/docs/panel-design.md @@ -27,6 +27,11 @@ only use shared components available in its supported Core versions. each service. Keep metadata compact and link to the relevant workflow for the active role. Distinguish configuration from public reachability or delivery. Use measured usage only when the panel has it. +- Keep current configuration separate from history. Show one current + record per resource in the working view. Use a **History** tab for + time-stamped events and snapshots. Label historical details explicitly + and keep live actions on the current resource or in a dedicated workflow. + Keep history scoped to the viewer’s role, especially internal config. - Use `.surface` for sections, `.section-heading` for ordinary section headers, and `.table-scroll` around tables. Keep horizontal overflow in the table wrapper and give empty or pending states an explicit label. diff --git a/src/coulobre/hosting/templates/hosting/account_detail.html b/src/coulobre/hosting/templates/hosting/account_detail.html index 171bd5b..ae83f2b 100644 --- a/src/coulobre/hosting/templates/hosting/account_detail.html +++ b/src/coulobre/hosting/templates/hosting/account_detail.html @@ -20,6 +20,7 @@ {% if is_tenant or perms.hosting.view_hostingdatabase %}Databases{% endif %} {% if show_account_backups or export_backup_manifest %}Backups{% endif %} {% if can_change_hosting_services or service_change or can_retire_account or is_operator and perms.hosting.change_hostingaccount %}Account management{% endif %} + History {% endblock %} {% block page_content %} @@ -55,6 +56,7 @@
Added
{{ account.created_at|date:"j M Y, H:i" }} UTC
{% include "hosting/account_overview.html" %} + {% include "hosting/account_history.html" %} {% if can_change_hosting_services or service_change or can_retire_account or is_operator and perms.hosting.change_hostingaccount %}
{% if can_retire_account or is_operator and perms.hosting.change_hostingaccount %} @@ -107,18 +109,21 @@ {% if website_aliases or can_add_website_alias %} {% include "hosting/website_aliases.html" %} {% endif %} - {% if show_web_previews %} -
+ {% if website_readiness %} +
-

Recent Apache previews

- {% if is_operator and perms.hosting.change_hostingaccount %} -
- {% csrf_token %} - -
+
+

Primary website

+

{{ account.primary_domain }}

+
+ {% if can_view_apache_plans and current_apache_plan %} + View Apache configuration {% endif %}
- {% include "hosting/plan_table.html" %} +
+
Website setup
{{ website_readiness }}
+
HTTPS
{{ https_status.label }}
+
{% endif %} diff --git a/src/coulobre/hosting/templates/hosting/account_history.html b/src/coulobre/hosting/templates/hosting/account_history.html new file mode 100644 index 0000000..a7f0f51 --- /dev/null +++ b/src/coulobre/hosting/templates/hosting/account_history.html @@ -0,0 +1,45 @@ + diff --git a/src/coulobre/hosting/templates/hosting/plan_detail.html b/src/coulobre/hosting/templates/hosting/plan_detail.html index 0cf765e..910197b 100644 --- a/src/coulobre/hosting/templates/hosting/plan_detail.html +++ b/src/coulobre/hosting/templates/hosting/plan_detail.html @@ -1,34 +1,52 @@ {% extends "hosting/workspace_page.html" %} -{% block title %}Apache preview · Coulobre Panel{% endblock %} +{% block title %}{% if plan_mode == "current" %}Apache configuration{% else %}Apache preview{% endif %} · Coulobre Panel{% endblock %} {% block page_header %}
-

Apache preview

+

{% if plan_mode == "current" %}Apache configuration{% elif plan_mode == "history" %}Apache preview history{% else %}Apache preview{% endif %}

{{ plan.primary_domain }}

- {% if not plan.completed_at or manage_activation and plan.activation and not plan.activation.finished_at or manage_https and plan.https and not plan.https.finished_at %} + {% if continue_apache_setup %} + Continue website setup + {% elif plan_mode == "preview" %} + {% if not plan.completed_at or manage_activation and plan.activation and not plan.activation.finished_at or manage_https and plan.https and not plan.https.finished_at %} Refresh status + {% endif %} {% endif %}
{% endblock %} {% block page_context %} - ← Web provisioning + ← Web provisioning {% endblock %} {% block page_content %}
-
Status
{% include "hosting/plan_status.html" %}
+ {% if plan_mode == "current" %} +
Applied
{{ plan.activation.finished_at|date:"j M Y, H:i" }} UTC
+
HTTPS
{{ https_status.label }}
+ {% else %} +
Preview result
{% include "hosting/plan_status.html" %}
+ {% endif %}
Hosting account
{% if is_reseller or perms.hosting.view_hostingaccount %}{{ plan.account.name }}{% else %}{{ plan.account.name }}{% endif %}
-
Requested
{{ plan.requested_at|date:"j M Y, H:i" }} UTC
+ {% if plan_mode != "current" %}
Requested
{{ plan.requested_at|date:"j M Y, H:i" }} UTC
{% endif %}
+ {% if plan_mode == "history" %} +

This entry records a preview request and does not show the website’s current state. + {% if current_apache_plan %}View current Apache configuration{% endif %} +

+ {% endif %} {% if plan.primary_domain != plan.account.primary_domain %}

This preview captures the original domain. The hosting account now uses {{ plan.account.primary_domain }}.

{% endif %} {% if plan.completed_at %}
-

Virtual host configuration

- {% if not is_reseller and plan.can_export %} +
+

{% if plan_mode == "current" %}Primary HTTP virtual host{% else %}Virtual host configuration{% endif %}

+ {% if plan_mode == "current" %}

Coulobre’s recorded configuration. HTTPS and alias configuration are managed separately.

{% endif %} +
+ {% if plan_mode != "history" and not is_reseller and plan.can_export %}
+ {% if may_manage_https %}Manage HTTPS{% endif %} Download deployment manifest Download test bundle
diff --git a/src/coulobre/hosting/templates/hosting/plan_list.html b/src/coulobre/hosting/templates/hosting/plan_list.html index 0c0d5b5..803aeb3 100644 --- a/src/coulobre/hosting/templates/hosting/plan_list.html +++ b/src/coulobre/hosting/templates/hosting/plan_list.html @@ -1,16 +1,45 @@ {% extends "hosting/workspace_page.html" %} {% block title %}Web provisioning · Coulobre Panel{% endblock %} -{% block page_header %} -
-
-

Web provisioning

-

{{ paginator.count }} Apache preview{{ paginator.count|pluralize }}

-
-
+{% block page_title %}Web provisioning{% endblock %} +{% block page_tabs %} + {% endblock %} {% block page_content %} -
- {% include "hosting/plan_table.html" %} - {% include "hosting/pagination.html" %} +
+
+
+ {% if show_history %} +

Web provisioning history

+

Apache preview requests, including earlier configurations.

+ {% else %} +

Current Apache configurations

+

The latest configuration applied by Coulobre for each primary website.

+ {% endif %} +
+
+ {% if show_history %} + {% include "hosting/plan_table.html" %} + {% elif plans %} +
+ + + + {% for plan in plans %} + + + + + + {% endfor %} + +
Primary domainHosting accountApplied
{{ plan.primary_domain }}{{ plan.account.name }}{{ plan.activation.finished_at|date:"j M Y, H:i" }} UTC
+
+ {% else %} +

No Apache configurations have been applied to current primary websites.

+ {% endif %}
+ {% include "hosting/pagination.html" %} {% endblock %} diff --git a/src/coulobre/hosting/templates/hosting/plan_table.html b/src/coulobre/hosting/templates/hosting/plan_table.html index 381386c..2836e66 100644 --- a/src/coulobre/hosting/templates/hosting/plan_table.html +++ b/src/coulobre/hosting/templates/hosting/plan_table.html @@ -1,11 +1,12 @@ {% if plans %}
- + {% for plan in plans %} - + + diff --git a/src/coulobre/hosting/test_customers.py b/src/coulobre/hosting/test_customers.py index c07cd6a..66868e2 100644 --- a/src/coulobre/hosting/test_customers.py +++ b/src/coulobre/hosting/test_customers.py @@ -123,10 +123,14 @@ class CustomerAccessTests(TestCase): detail = self.client.get(self.account.get_absolute_url()) for label in ( "Edit account", - "Recent Apache previews", + "Apache preview requested", + "Request Apache preview", + "View Apache configuration", "Download manifest", ): self.assertNotContains(detail, label) + self.assertContains(detail, 'href="#history"') + self.assertContains(detail, "Hosting account created") for route, args in ( ("panel:plans", ()), diff --git a/src/coulobre/hosting/test_panel.py b/src/coulobre/hosting/test_panel.py index 7a7501e..1554dfe 100644 --- a/src/coulobre/hosting/test_panel.py +++ b/src/coulobre/hosting/test_panel.py @@ -1,9 +1,10 @@ from django.contrib.auth import get_user_model from django.contrib.auth.models import Permission -from django.test import Client, TestCase +from django.test import Client, TestCase, override_settings from django.urls import reverse +from django.utils import timezone -from .models import HostingAccount, WebProvisioningPlan +from .models import HostingAccount, WebActivation, WebProvisioningPlan from .tasks import render_web_plan @@ -90,7 +91,64 @@ class PanelTests(TestCase): self.assertContains( self.client.get(preview_url), "ServerName example.org" ) - self.assertContains(self.client.get(reverse("panel:plans")), "Ready") + self.assertContains( + self.client.get(reverse("panel:plans"), {"tab": "history"}), + "Ready", + ) + + @override_settings(LOCAL_WEB_ACTIVATION=True, LOCAL_WEB_HTTPS=True) + def test_current_configuration_excludes_older_and_unapplied_previews(self): + self.client.force_login(self.operator) + older, current, draft = [ + WebProvisioningPlan.objects.create( + account=self.account, + primary_domain=self.account.primary_domain, + completed_at=timezone.now(), + apache_config=f"# {label}", + ) + for label in ("older", "current", "draft") + ] + for plan in (older, current): + WebActivation.objects.create(plan=plan, finished_at=timezone.now()) + WebActivation.objects.create( + plan=draft, finished_at=timezone.now(), problem="Failed activation" + ) + listing = reverse("panel:plans") + older_url, current_url, draft_url = [ + reverse("panel:plan", args=[plan.pk]) + for plan in (older, current, draft) + ] + response = self.client.get(listing) + self.assertContains(response, f'{current_url}?view=current"') + self.assertNotContains(response, older_url) + self.assertNotContains(response, draft_url) + response = self.client.get(listing, {"tab": "history"}) + for url in (older_url, current_url, draft_url): + self.assertContains(response, f'{url}?view=history"') + + response = self.client.get(self.account.get_absolute_url()) + self.assertContains(response, 'href="#history"') + self.assertContains(response, f'{current_url}?view=current"') + self.assertNotContains(response, "Recent Apache previews") + self.assertContains( + self.client.get(current_url, {"view": "current"}), "# current" + ) + response = self.client.get(older_url) + self.assertContains(response, "Apache preview history") + self.assertNotContains(response, "Enable HTTPS") + self.assertNotContains(response, "Activate site") + self.assertNotContains(response, "Continue website setup") + for action in ("plan_activate", "plan_https"): + self.assertEqual( + self.client.post( + reverse(f"panel:{action}", args=[older.pk]) + ).status_code, + 409, + ) + response = self.client.get(draft_url, {"view": "history"}) + self.assertContains(response, "Continue website setup") + self.assertNotContains(response, "Retry activation") + self.assertContains(self.client.get(draft_url), "Retry activation") def test_viewer_cannot_mutate_accounts_or_read_previews(self): plan = WebProvisioningPlan.for_account(self.account) diff --git a/src/coulobre/hosting/test_resellers.py b/src/coulobre/hosting/test_resellers.py index 6a0bd23..64a967c 100644 --- a/src/coulobre/hosting/test_resellers.py +++ b/src/coulobre/hosting/test_resellers.py @@ -74,7 +74,7 @@ class ResellerAccessTests(TestCase): self.client.get(account.get_absolute_url()).status_code, 404 ) - previews = self.client.get(reverse("panel:plans")) + previews = self.client.get(reverse("panel:plans"), {"tab": "history"}) self.assertContains(previews, "alice.example") self.assertNotContains(previews, "bob.example") preview = self.client.get( diff --git a/src/coulobre/hosting/views.py b/src/coulobre/hosting/views.py index 238661a..e7c467e 100644 --- a/src/coulobre/hosting/views.py +++ b/src/coulobre/hosting/views.py @@ -182,6 +182,7 @@ from .sftp import ( site_is_active, ) from .smtp_applications import smtp_applications_available +from .web_history import current_web_plan, current_web_plans, is_superseded from .web_node import ( SiteStorageLimitForm, build_web_smoke_bundle, @@ -886,13 +887,17 @@ class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView): and owns_customer_operations(user, self.object) and (site_active or hasattr(self.object, "sftp")) ) - if reseller is not None or ( + context["can_view_apache_plans"] = reseller is not None or ( customer is None and user.has_perm(VIEW_PLANS) - ): - context["show_web_previews"] = True - context["plans"] = self.object.webprovisioningplan_set.order_by( - "-requested_at", "-pk" - )[:10] + ) + context["can_request_apache_plan"] = not tenant and user.has_perms( + (CHANGE_ACCOUNTS, VIEW_PLANS) + ) + if context["can_view_apache_plans"]: + history = self.object.webprovisioningplan_set.defer( + "apache_config" + ).order_by("-requested_at", "-pk") + context["apache_history"] = list(history[:10]) if getattr(self.request, "impersonation", None) is None: context["show_database_credentials"] = show_credential_action( self.request, CredentialKind.DATABASE @@ -1085,14 +1090,16 @@ class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView): or getattr(context.get("website_storage"), "measured_at", None) or getattr(context.get("website_limit"), "applied_at", None) ) - context["show_website"] = any( + applied = current_web_plan(self.object) + context["current_apache_plan"] = applied + context["show_website"] = applied is not None or any( context.get(name) for name in ( "show_website_storage", "website_php_settings", "website_aliases", "can_add_website_alias", - "show_web_previews", + "can_view_apache_plans", "show_website_usage", "primary_file_access", "manage_website_jobs", @@ -1106,20 +1113,9 @@ class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView): plans = self.object.webprovisioningplan_set.filter( primary_domain=self.object.primary_domain ).select_related("activation") - plan = ( - plans.filter( - activation__finished_at__isnull=False, - activation__problem="", - ) - .order_by("-pk") - .first() + plan = applied or ( + plans.filter(activation__isnull=False).order_by("-pk").first() ) - if plan is None: - plan = ( - plans.filter(activation__isnull=False) - .order_by("-pk") - .first() - ) context["website_readiness"] = provisioning_readiness( getattr(plan, "activation", None), "Not set up", "Configured" ) @@ -2992,8 +2988,8 @@ class RequestWebPlan( class PlanList(TenantScopeMixin, PermissionRequiredMixin, ListView): - queryset = WebProvisioningPlan.objects.select_related("account").order_by( - "-requested_at", "-pk" + queryset = WebProvisioningPlan.objects.select_related("account").defer( + "apache_config" ) permission_required = VIEW_PLANS reseller_relation = "account__reseller" @@ -3001,6 +2997,22 @@ class PlanList(TenantScopeMixin, PermissionRequiredMixin, ListView): context_object_name = "plans" paginate_by = 20 + def get_queryset(self): + plans = super().get_queryset() + if self.request.GET.get("tab") == "history": + return plans.order_by("-requested_at", "-pk") + return ( + current_web_plans(plans) + .select_related("activation") + .order_by("primary_domain", "pk") + ) + + def get_context_data(self, **kwargs): + return super().get_context_data( + show_history=self.request.GET.get("tab") == "history", + **kwargs, + ) + class PlanDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView): queryset = WebProvisioningPlan.objects.select_related( @@ -3013,13 +3025,46 @@ class PlanDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView): def get_context_data(self, **kwargs): user = self.request.user + plan = self.object + current = ( + None if plan.account.retired_at else current_web_plan(plan.account) + ) + mode = self.request.GET.get("view") + if mode == "current" and current and current.pk == plan.pk: + mode = "current" + elif ( + mode in {"current", "history"} + or plan.account.retired_at + or is_superseded(plan, current) + ): + mode = "history" + else: + mode = "preview" return super().get_context_data( - manage_activation=not is_tenant(user) + plan_mode=mode, + current_apache_plan=current, + continue_apache_setup=mode == "history" + and not plan.account.retired_at + and plan.primary_domain == plan.account.primary_domain + and (current is None or plan.pk > current.pk) + and not is_tenant(user) + and user.has_perms(ACTIVATE_WEB) + and panel_feature_allowed("LOCAL_WEB_ACTIVATION"), + https_status=( + primary_https_status(plan.account) + if mode == "current" + else None + ), + may_manage_https=mode == "current" + and may_manage_https(self.request, plan.account), + manage_activation=mode == "preview" + and not is_tenant(user) and user.has_perms(ACTIVATE_WEB), local_activation_enabled=panel_feature_allowed( "LOCAL_WEB_ACTIVATION" ), - manage_https=not is_tenant(user) + manage_https=mode == "preview" + and not is_tenant(user) and user.has_perms(ENABLE_WEB_HTTPS), local_https_enabled=panel_feature_allowed("LOCAL_WEB_HTTPS"), **kwargs, @@ -3036,6 +3081,12 @@ class RequestWebActivation( if not panel_feature_allowed("LOCAL_WEB_ACTIVATION"): raise Http404 plan = self.get_object() + if plan.account.retired_at or is_superseded( + plan, current_web_plan(plan.account) + ): + return provisioning_conflict( + ValidationError("This Apache preview is historical.") + ) if not plan.can_export: return HttpResponse( "Request a completed Apache preview for the current " @@ -3065,6 +3116,12 @@ class RequestWebHTTPS( if not panel_feature_allowed("LOCAL_WEB_HTTPS"): raise Http404 plan = self.get_object() + if plan.account.retired_at or is_superseded( + plan, current_web_plan(plan.account) + ): + return provisioning_conflict( + ValidationError("This Apache preview is historical.") + ) if not plan.can_enable_https: return HttpResponse( "Activate the site for the current domain first.", diff --git a/src/coulobre/hosting/web_history.py b/src/coulobre/hosting/web_history.py new file mode 100644 index 0000000..aa50fb6 --- /dev/null +++ b/src/coulobre/hosting/web_history.py @@ -0,0 +1,44 @@ +from django.db.models import F, OuterRef, Subquery + +from .models import WebProvisioningPlan + + +def configured_web_plans(): + return WebProvisioningPlan.objects.filter( + primary_domain=F("account__primary_domain"), + completed_at__isnull=False, + activation__finished_at__isnull=False, + activation__problem="", + ).exclude(apache_config="") + + +def current_web_plan(account): + return ( + configured_web_plans() + .filter(account=account) + .select_related("activation") + .order_by("-activation__finished_at", "-pk") + .first() + ) + + +def current_web_plans(plans): + latest = ( + configured_web_plans() + .filter(account_id=OuterRef("account_id")) + .order_by("-activation__finished_at", "-pk") + .values("pk")[:1] + ) + return plans.filter(account__retired_at__isnull=True, pk=Subquery(latest)) + + +def is_superseded(plan, current): + return ( + current is not None + and current.pk != plan.pk + and ( + current.pk > plan.pk + or getattr(getattr(plan, "activation", None), "state", None) + == "configured" + ) + )
Primary domainRequestedStatus
EventPrimary domainRequestedResult
{{ plan.primary_domain }}Apache preview requested{{ plan.primary_domain }} {{ plan.requested_at|date:"j M Y, H:i" }} UTC {% include "hosting/plan_status.html" %}