Separate current web configurations from provisioning history #298
No files matched your search
+6
-3
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
{% if is_tenant or perms.hosting.view_hostingdatabase %}<a href="#databases">Databases</a>{% endif %}
|
||||
{% if show_account_backups or export_backup_manifest %}<a href="#backups">Backups</a>{% endif %}
|
||||
{% if can_change_hosting_services or service_change or can_retire_account or is_operator and perms.hosting.change_hostingaccount %}<a href="#account-management">Account management</a>{% endif %}
|
||||
<a href="#history">History</a>
|
||||
</nav>
|
||||
{% endblock %}
|
||||
{% block page_content %}
|
||||
@@ -55,6 +56,7 @@
|
||||
<div><dt>Added</dt><dd>{{ account.created_at|date:"j M Y, H:i" }} UTC</dd></div>
|
||||
</dl>
|
||||
{% 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 %}
|
||||
<section class="account-content" id="account-management" data-account-section tabindex="-1" aria-label="Account management">
|
||||
{% 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 %}
|
||||
<section class="surface" aria-labelledby="previews-heading">
|
||||
{% if website_readiness %}
|
||||
<section class="surface" aria-labelledby="apache-heading">
|
||||
<header class="section-heading">
|
||||
<h2 id="previews-heading">Recent Apache previews</h2>
|
||||
{% if is_operator and perms.hosting.change_hostingaccount %}
|
||||
<form method="post" action="{% url 'panel:request_plan' account.pk %}">
|
||||
{% csrf_token %}
|
||||
<button class="button primary" type="submit">Request Apache preview</button>
|
||||
</form>
|
||||
<div>
|
||||
<h2 id="apache-heading">Primary website</h2>
|
||||
<p class="heading-meta domain">{{ account.primary_domain }}</p>
|
||||
</div>
|
||||
{% if can_view_apache_plans and current_apache_plan %}
|
||||
<a class="button secondary" href="{% url 'panel:plan' current_apache_plan.pk %}?view=current">View Apache configuration</a>
|
||||
{% endif %}
|
||||
</header>
|
||||
{% include "hosting/plan_table.html" %}
|
||||
<dl class="details">
|
||||
<div><dt>Website setup</dt><dd>{{ website_readiness }}</dd></div>
|
||||
<div><dt>HTTPS</dt><dd>{{ https_status.label }}</dd></div>
|
||||
</dl>
|
||||
</section>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<section class="account-content" id="history" data-account-section tabindex="-1" aria-label="History">
|
||||
<section class="surface" aria-labelledby="account-history-heading">
|
||||
<header class="section-heading">
|
||||
<div>
|
||||
<h2 id="account-history-heading">Account history</h2>
|
||||
{% if can_view_apache_plans %}<p class="heading-meta">Account creation and up to 10 recent Apache previews.</p>{% endif %}
|
||||
</div>
|
||||
{% if can_request_apache_plan %}
|
||||
<form method="post" action="{% url 'panel:request_plan' account.pk %}">
|
||||
{% csrf_token %}
|
||||
<button class="button secondary" type="submit">Request Apache preview</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</header>
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead><tr><th scope="col">Event</th><th scope="col">Domain</th><th scope="col" class="cell-date">Time</th><th scope="col">Result</th></tr></thead>
|
||||
<tbody>
|
||||
{% for plan in apache_history %}
|
||||
<tr>
|
||||
<th scope="row"><a class="record-link" href="{% url 'panel:plan' plan.pk %}?view=history">Apache preview requested</a></th>
|
||||
<td class="domain">{{ plan.primary_domain }}</td>
|
||||
<td class="cell-date muted">{{ plan.requested_at|date:"j M Y, H:i" }} UTC</td>
|
||||
<td>{% include "hosting/plan_status.html" %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% if not can_view_apache_plans and current_apache_plan %}
|
||||
<tr>
|
||||
<th scope="row">Primary website configured</th>
|
||||
<td class="domain">{{ current_apache_plan.primary_domain }}</td>
|
||||
<td class="cell-date muted">{{ current_apache_plan.activation.finished_at|date:"j M Y, H:i" }} UTC</td>
|
||||
<td>Configured</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th scope="row">Hosting account created</th>
|
||||
<td>—</td>
|
||||
<td class="cell-date muted">{{ account.created_at|date:"j M Y, H:i" }} UTC</td>
|
||||
<td>Created</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
@@ -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 %}
|
||||
<header class="page-heading">
|
||||
<div>
|
||||
<h1>Apache preview</h1>
|
||||
<h1>{% if plan_mode == "current" %}Apache configuration{% elif plan_mode == "history" %}Apache preview history{% else %}Apache preview{% endif %}</h1>
|
||||
<p class="heading-meta domain">{{ plan.primary_domain }}</p>
|
||||
</div>
|
||||
{% 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 %}
|
||||
<a class="button secondary" href="{% url 'panel:plan' plan.pk %}">Continue website setup</a>
|
||||
{% 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 %}
|
||||
<a class="button secondary" href="{% url 'panel:plan' plan.pk %}">Refresh status</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</header>
|
||||
{% endblock %}
|
||||
{% block page_context %}
|
||||
<a class="quiet-link" href="{% url 'panel:plans' %}">← Web provisioning</a>
|
||||
<a class="quiet-link" href="{% url 'panel:plans' %}{% if plan_mode != 'current' %}?tab=history{% endif %}">← Web provisioning</a>
|
||||
{% endblock %}
|
||||
{% block page_content %}
|
||||
<dl class="details surface">
|
||||
<div><dt>Status</dt><dd>{% include "hosting/plan_status.html" %}</dd></div>
|
||||
{% if plan_mode == "current" %}
|
||||
<div><dt>Applied</dt><dd>{{ plan.activation.finished_at|date:"j M Y, H:i" }} UTC</dd></div>
|
||||
<div><dt>HTTPS</dt><dd>{{ https_status.label }}</dd></div>
|
||||
{% else %}
|
||||
<div><dt>Preview result</dt><dd>{% include "hosting/plan_status.html" %}</dd></div>
|
||||
{% endif %}
|
||||
<div><dt>Hosting account</dt><dd>{% if is_reseller or perms.hosting.view_hostingaccount %}<a class="record-link" href="{{ plan.account.get_absolute_url }}">{{ plan.account.name }}</a>{% else %}{{ plan.account.name }}{% endif %}</dd></div>
|
||||
<div><dt>Requested</dt><dd>{{ plan.requested_at|date:"j M Y, H:i" }} UTC</dd></div>
|
||||
{% if plan_mode != "current" %}<div><dt>Requested</dt><dd>{{ plan.requested_at|date:"j M Y, H:i" }} UTC</dd></div>{% endif %}
|
||||
</dl>
|
||||
{% if plan_mode == "history" %}
|
||||
<p class="notice">This entry records a preview request and does not show the website’s current state.
|
||||
{% if current_apache_plan %}<a href="{% url 'panel:plan' current_apache_plan.pk %}?view=current">View current Apache configuration</a>{% endif %}
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if plan.primary_domain != plan.account.primary_domain %}
|
||||
<p class="notice">This preview captures the original domain. The hosting account now uses <strong>{{ plan.account.primary_domain }}</strong>.</p>
|
||||
{% endif %}
|
||||
{% if plan.completed_at %}
|
||||
<section class="surface" aria-labelledby="configuration-heading">
|
||||
<header class="section-heading">
|
||||
<h2 id="configuration-heading">Virtual host configuration</h2>
|
||||
{% if not is_reseller and plan.can_export %}
|
||||
<div>
|
||||
<h2 id="configuration-heading">{% if plan_mode == "current" %}Primary HTTP virtual host{% else %}Virtual host configuration{% endif %}</h2>
|
||||
{% if plan_mode == "current" %}<p class="heading-meta">Coulobre’s recorded configuration. HTTPS and alias configuration are managed separately.</p>{% endif %}
|
||||
</div>
|
||||
{% if plan_mode != "history" and not is_reseller and plan.can_export %}
|
||||
<div class="form-actions">
|
||||
{% if may_manage_https %}<a class="button secondary" href="{% url 'panel:website_https' plan.account_id %}">Manage HTTPS</a>{% endif %}
|
||||
<a class="button secondary" href="{% url 'panel:download_deployment_manifest' plan.pk %}">Download deployment manifest</a>
|
||||
<a class="button secondary" href="{% url 'panel:download_smoke_bundle' plan.pk %}">Download test bundle</a>
|
||||
</div>
|
||||
|
||||
@@ -1,16 +1,45 @@
|
||||
{% extends "hosting/workspace_page.html" %}
|
||||
{% block title %}Web provisioning · Coulobre Panel{% endblock %}
|
||||
{% block page_header %}
|
||||
<header class="page-heading">
|
||||
<div>
|
||||
<h1>Web provisioning</h1>
|
||||
<p class="heading-meta">{{ paginator.count }} Apache preview{{ paginator.count|pluralize }}</p>
|
||||
</div>
|
||||
</header>
|
||||
{% block page_title %}Web provisioning{% endblock %}
|
||||
{% block page_tabs %}
|
||||
<nav class="account-navigation" aria-label="Web provisioning">
|
||||
<a href="{% url 'panel:plans' %}"{% if not show_history %} aria-current="page"{% endif %}>Current configurations</a>
|
||||
<a href="{% url 'panel:plans' %}?tab=history"{% if show_history %} aria-current="page"{% endif %}>History</a>
|
||||
</nav>
|
||||
{% endblock %}
|
||||
{% block page_content %}
|
||||
<section class="surface" aria-label="Apache previews">
|
||||
{% include "hosting/plan_table.html" %}
|
||||
{% include "hosting/pagination.html" %}
|
||||
<section class="surface" aria-labelledby="web-configurations-heading">
|
||||
<header class="section-heading">
|
||||
<div>
|
||||
{% if show_history %}
|
||||
<h2 id="web-configurations-heading">Web provisioning history</h2>
|
||||
<p class="heading-meta">Apache preview requests, including earlier configurations.</p>
|
||||
{% else %}
|
||||
<h2 id="web-configurations-heading">Current Apache configurations</h2>
|
||||
<p class="heading-meta">The latest configuration applied by Coulobre for each primary website.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</header>
|
||||
{% if show_history %}
|
||||
{% include "hosting/plan_table.html" %}
|
||||
{% elif plans %}
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead><tr><th scope="col">Primary domain</th><th scope="col">Hosting account</th><th scope="col" class="cell-date">Applied</th></tr></thead>
|
||||
<tbody>
|
||||
{% for plan in plans %}
|
||||
<tr>
|
||||
<th scope="row"><a class="record-link domain" href="{% url 'panel:plan' plan.pk %}?view=current">{{ plan.primary_domain }}</a></th>
|
||||
<td>{{ plan.account.name }}</td>
|
||||
<td class="cell-date muted">{{ plan.activation.finished_at|date:"j M Y, H:i" }} UTC</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="empty">No Apache configurations have been applied to current primary websites.</p>
|
||||
{% endif %}
|
||||
</section>
|
||||
{% include "hosting/pagination.html" %}
|
||||
{% endblock %}
|
||||
@@ -1,11 +1,12 @@
|
||||
{% if plans %}
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead><tr><th scope="col">Primary domain</th><th scope="col" class="cell-date">Requested</th><th scope="col">Status</th></tr></thead>
|
||||
<thead><tr><th scope="col">Event</th><th scope="col">Primary domain</th><th scope="col" class="cell-date">Requested</th><th scope="col">Result</th></tr></thead>
|
||||
<tbody>
|
||||
{% for plan in plans %}
|
||||
<tr>
|
||||
<td><a class="record-link domain" href="{% url 'panel:plan' plan.pk %}">{{ plan.primary_domain }}</a></td>
|
||||
<th scope="row"><a class="record-link" href="{% url 'panel:plan' plan.pk %}?view=history">Apache preview requested</a></th>
|
||||
<td class="domain">{{ plan.primary_domain }}</td>
|
||||
<td class="cell-date muted">{{ plan.requested_at|date:"j M Y, H:i" }} UTC</td>
|
||||
<td>{% include "hosting/plan_status.html" %}</td>
|
||||
</tr>
|
||||
|
||||
@@ -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", ()),
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
)
|
||||
Reference in new issue
Block a user