Separate current web configurations from provisioning history #298

Merged
parkel merged 2 commits from feature/website-provisioning-history into main 2026-12-04 13:19:36 +01:00
21 changed files with 594 additions and 133 deletions

No files matched your search

+4 -4
View File
@@ -1421,7 +1421,7 @@ confirm its domain using **Retire website**. The web node archives its data
and disables its Apache and PHP configuration. Retiring a failed provisioning request also frees its place in the plan. and disables its Apache and PHP configuration. Retiring a failed provisioning request also frees its place in the plan.
Its domain remains reserved until released with the account's names. Its domain remains reserved until released with the account's names.
Operators can download the website's version 2 manifest. Use the existing Export the website's version 2 manifest with `export_manifest website`. Use the existing
[website SFTP setup](development.md#install-sftp-keys-on-a-web-node) on the web node [website SFTP setup](development.md#install-sftp-keys-on-a-web-node) on the web node
with that manifest to authorize a key for the site's own user. The web with that manifest to authorize a key for the site's own user. The web
node suspends new SFTP logins for a suspended independent website when node suspends new SFTP logins for a suspended independent website when
@@ -1936,9 +1936,9 @@ managed database and restore it to an empty database with the same identity.
## Back up an account's website and databases ## Back up an account's website and databases
Download an account backup manifest from the panel. Use it to create one ZIP Export an account backup manifest from the CLI. Use it to create one ZIP
on a single server or bundle native archives from separate nodes. The CLI can on a single server or bundle native archives from separate nodes. The CLI can
also include mailbox archives when the downloaded manifest lists mailboxes. also include mailbox archives when the manifest lists mailboxes.
[Account backup and recovery](development.md#back-up-a-hosting-account) [Account backup and recovery](development.md#back-up-a-hosting-account)
### Start local account backups from the panel ### Start local account backups from the panel
@@ -2787,7 +2787,7 @@ reported failure. Operators need permission to view hosting accounts and
mailbox requests and the **Can add mailbox provisioning** permission. mailbox requests and the **Can add mailbox provisioning** permission.
The initial password is kept in the root-only credentials file on the mail node. The initial password is kept in the root-only credentials file on the mail node.
To locate that file, download the manifest and use the node's `apply` command. To locate that file, export the mailbox manifest and use the node's `apply` command.
Reapplying the manifest preserves the password and prints the file path. Reapplying the manifest preserves the password and prints the file path.
[Show mailbox connection details in the panel](#show-local-database-and-mailbox-connection-details) [Show mailbox connection details in the panel](#show-local-database-and-mailbox-connection-details)
+56 -28
View File
@@ -146,14 +146,35 @@ ID, operation, resource, and time. SSH key changes record fingerprints of
the keys added or removed. Queued changes still report their execution the keys added or removed. Queued changes still report their execution
status in the hosting account. status in the hosting account.
## Export manifests from the command line
Routine provisioning and backups in the panel do not require a separate
manifest. For manual node operations or local testing, export the matching
resource using the panel's Django management environment.
```sh
panel_manage export_manifest database 1 > coulobre-database-1.json
panel_manage export_manifest dns-zone 1 > coulobre-zone.json
panel_manage export_manifest mailbox 1 > coulobre-mailbox-1.json
panel_manage export_manifest website 1 > coulobre-website-1.json
panel_manage export_manifest apache-preview 1 > coulobre-web-plan-1.json
panel_manage export_manifest account-backup 1 --include-mail > account.json
```
Replace `1` with the ID of the matching database, DNS zone, mailbox,
independent website, Apache preview, or hosting account. Use the
[`panel_manage` helper](deployment.md#prepare-the-panel) on an installed
server, or `python manage.py` in a development checkout. The command only
exports metadata and does not apply changes or create a backup.
## Request a MariaDB database ## Request a MariaDB database
Open a hosting account and select **Request database**. Choose a short suffix Open a hosting account and select **Request database**. Choose a short suffix
such as `wordpress`. The panel derives the full database name from the account such as `wordpress`. The panel derives the full database name from the account
ID and suffix, so two accounts can each request a database named `wordpress`. ID and suffix, so two accounts can each request a database named `wordpress`.
The account page shows the requested databases. Operators can download a The account page shows the requested databases. The CLI manifest contains the
versioned deployment manifest containing the account ID and suffix. Managers account ID and suffix. Managers
can view the requested database names on their own assigned accounts. The can view the requested database names on their own assigned accounts. The
manifest describes the database to provision on a MariaDB node. manifest describes the database to provision on a MariaDB node.
@@ -168,7 +189,7 @@ coulobre-database-node inspect coulobre-database-1.json
Use a local MariaDB server with Unix socket authentication for Use a local MariaDB server with Unix socket authentication for
`root@localhost`. Install Coulobre with the `mariadb` extra in a root-owned `root@localhost`. Install Coulobre with the `mariadb` extra in a root-owned
virtual environment and apply the downloaded manifest on that server. virtual environment and apply the exported manifest on that server.
```sh ```sh
sudo /opt/coulobre/bin/coulobre-database-node apply coulobre-database-1.json sudo /opt/coulobre/bin/coulobre-database-node apply coulobre-database-1.json
@@ -286,11 +307,11 @@ Use `@` for the zone domain in either field. Use fully qualified names
for other records. The panel increments the SOA serial when the zone data for other records. The panel increments the SOA serial when the zone data
changes. Changing the account's primary domain preserves its existing DNS zones. changes. Changing the account's primary domain preserves its existing DNS zones.
Select **Download manifest** in the DNS table and copy the file to the Export the zone using the CLI and copy the file to the hosting server or a
hosting server or a separate DNS node. Managers can see the configured separate DNS node. Managers can see the configured domains and serials for
domains and serials for their assigned accounts. Operators with the their assigned accounts. Operators with the appropriate permissions can add
appropriate permissions can add and edit zones and download manifests. and edit zones in the panel.
The panel exports version 2 for zones containing MX or TXT records and Coulobre exports version 2 for zones containing MX or TXT records and
version 1 for other zones. version 1 for other zones.
A manifest can also be written directly for local testing. Save the A manifest can also be written directly for local testing. Save the
@@ -391,7 +412,7 @@ sudo /opt/coulobre/bin/coulobre-dns-node apply coulobre-zone.json
Coulobre validates the zone with `named-checkzone` and installs it under Coulobre validates the zone with `named-checkzone` and installs it under
`/etc/bind/coulobre/`. BIND9 persists the primary zone registration through `/etc/bind/coulobre/`. BIND9 persists the primary zone registration through
`rndc addzone`. To publish an edit, download the updated manifest and apply `rndc addzone`. To publish an edit manually, export the updated manifest and apply
it again. Coulobre checks the SOA serial, reloads the individual zone, and it again. Coulobre checks the SOA serial, reloads the individual zone, and
waits for BIND9 to report the requested serial. Reapply the same manifest to waits for BIND9 to report the requested serial. Reapply the same manifest to
resume after an interrupted reload. See the [BIND9 command reference](https://bind9.readthedocs.io/en/v9.18.39/manpages.html#rndc) and [RFC 1982](https://www.rfc-editor.org/rfc/rfc1982.html). resume after an interrupted reload. See the [BIND9 command reference](https://bind9.readthedocs.io/en/v9.18.39/manpages.html#rndc) and [RFC 1982](https://www.rfc-editor.org/rfc/rfc1982.html).
@@ -425,8 +446,8 @@ the `@`, such as `support`. The panel uses the account's primary domain,
lowercases the local part, and converts the domain to its ASCII DNS form. lowercases the local part, and converts the domain to its ASCII DNS form.
Existing mailbox requests keep their addresses when the primary domain changes. Existing mailbox requests keep their addresses when the primary domain changes.
The **Mailbox requests** table shows the email addresses. Operators can The **Mailbox requests** table shows the email addresses. The CLI export
download a versioned manifest that contains the domain and local part. contains the domain and local part.
Managers can see mailbox requests on their assigned accounts. Managers can see mailbox requests on their assigned accounts.
Version 2 adds `quota_mib` for mailboxes with a storage limit. Version 1 Version 2 adds `quota_mib` for mailboxes with a storage limit. Version 1
manifests continue to apply with no Coulobre storage limit. manifests continue to apply with no Coulobre storage limit.
@@ -571,7 +592,7 @@ mailbox already provisioned through the panel, saving queues an update on
the local mail node. Use **Retry provisioning** to retry a failed update the local mail node. Use **Retry provisioning** to retry a failed update
before setting another limit. before setting another limit.
For a mailbox provisioned manually, download its updated manifest and run For a mailbox provisioned manually, export its updated manifest and run
the following command on the mail node. the following command on the mail node.
```sh ```sh
@@ -609,7 +630,7 @@ running the check without root privileges.
### Back up and restore a mailbox ### Back up and restore a mailbox
Download the mailbox manifest from the panel and run the backup on the node Export the mailbox manifest and run the backup on the node
that hosts the mailbox. Use a new archive name in a root-controlled directory. that hosts the mailbox. Use a new archive name in a root-controlled directory.
```sh ```sh
@@ -734,8 +755,8 @@ python manage.py import_directadmin user.admin.customer.tar.zst
The import checks domain ownership again and creates the new hosting account, The import checks domain ownership again and creates the new hosting account,
supported database requests and selected domain's mailbox requests in one supported database requests and selected domain's mailbox requests in one
transaction. The JSON report includes the new account ID and the MariaDB transaction. The JSON report includes the new account ID and the MariaDB
names derived from the database requests. Use the account page to download names derived from the database requests. Use the CLI to export deployment
deployment manifests for the nodes. The `manual_review` list records the manifests for the nodes. The `manual_review` list records the
website, DNS, mail and SQL data to review before completing the separate website, DNS, mail and SQL data to review before completing the separate
restore steps below. restore steps below.
@@ -873,10 +894,13 @@ celery -A coulobre worker --pool=solo
celery -A coulobre beat 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 The preview page shows the request status and the configuration once the worker
finishes. Use **Refresh status** for pending requests or **Web provisioning** to finishes. Use **Refresh status** for pending requests or **Web provisioning →
find earlier previews. Each request captures the primary domain at queue time. 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 The preview references the future document root and PHP-FPM socket for the
account. Preview generation makes no changes to the hosting services. account. Preview generation makes no changes to the hosting services.
@@ -887,8 +911,8 @@ are eligible for delivery again.
## Render configuration on a web node ## Render configuration on a web node
Open a completed preview for the account's current domain and select **Download Export a completed preview for the account's current domain with
deployment manifest**. The versioned JSON file contains the account ID and `export_manifest apache-preview`. The versioned JSON file contains the account ID and
primary domain. The web node command validates those values and derives the primary domain. The web node command validates those values and derives the
system user, document root, and PHP-FPM socket from the account ID. system user, document root, and PHP-FPM socket from the account ID.
@@ -1185,11 +1209,10 @@ backup. The website can be recovered while its web services are stopped.
## Back up a hosting account ## Back up a hosting account
Open the account as an operator and select **Download backup manifest**. The Export the backup manifest with `export_manifest account-backup`. It lists the
manifest lists the primary website and all database requests for the account. website and database resources for the account. Pass `--include-mail` to also
Select **Download backup manifest with mail** to also include mailbox requests include mailbox requests from every mail domain assigned to the account.
from every mail domain assigned to the account. This option requires permission Provision all listed resources before running the
to view mailbox requests. Provision all listed resources before running the
backup. The ZIP contains the native website archive, a compressed SQL dump for backup. The ZIP contains the native website archive, a compressed SQL dump for
each listed database, and the requested mailbox archives. Back up DNS and panel each listed database, and the requested mailbox archives. Back up DNS and panel
settings separately. settings separately.
@@ -1269,13 +1292,18 @@ continue to unpack with the same filenames.
## Run an isolated PHP test site ## Run an isolated PHP test site
Open a completed preview for the account's current domain and select **Download Export a completed preview for the account's current domain to a new tar file.
test bundle**. The archive contains the exact Apache preview, a matching PHP-FPM
```sh
python manage.py export_manifest apache-preview 1 --smoke-bundle coulobre-web-plan-1.tar
```
The archive contains the exact Apache preview, a matching PHP-FPM
pool, site metadata, and a small PHP test page. It is intended for the isolated pool, site metadata, and a small PHP test page. It is intended for the isolated
Ubuntu check below. Ubuntu check below.
Run the test with Docker from the repository root. Set the bundle path to the Run the test with Docker from the repository root. Set the bundle path to the
downloaded tar archive. exported tar archive.
```sh ```sh
docker build -t coulobre-web-smoke tests/web-node docker build -t coulobre-web-smoke tests/web-node
+8
View File
@@ -27,6 +27,14 @@ only use shared components available in its supported Core versions.
each service. Keep metadata compact and link to the relevant workflow each service. Keep metadata compact and link to the relevant workflow
for the active role. Distinguish configuration from public reachability for the active role. Distinguish configuration from public reachability
or delivery. Use measured usage only when the panel has it. 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.
- Keep low-level provisioning manifests and developer test bundles out of
routine panel actions. Document their CLI export instead. Keep meaningful
user downloads, such as backup archives, in the relevant workflow.
- Use `.surface` for sections, `.section-heading` for ordinary section - Use `.surface` for sections, `.section-heading` for ordinary section
headers, and `.table-scroll` around tables. Keep horizontal overflow in headers, and `.table-scroll` around tables. Keep horizontal overflow in
the table wrapper and give empty or pending states an explicit label. the table wrapper and give empty or pending states an explicit label.
@@ -0,0 +1,83 @@
import json
from pathlib import Path
from django.core.management.base import BaseCommand, CommandError
from ...account_backups import account_backup_manifest
from ...models import (
HostingAccount,
HostingDatabase,
HostingDnsZone,
HostingMailbox,
IndependentWebsite,
WebProvisioningPlan,
)
from ...web_node import build_web_smoke_bundle, serialize_deployment_manifest
RESOURCE_MODELS = {
"account-backup": HostingAccount,
"database": HostingDatabase,
"dns-zone": HostingDnsZone,
"mailbox": HostingMailbox,
"website": IndependentWebsite,
"apache-preview": WebProvisioningPlan,
}
class Command(BaseCommand):
help = "Export a Coulobre provisioning or backup manifest as JSON."
def add_arguments(self, parser):
parser.add_argument("resource", choices=RESOURCE_MODELS)
parser.add_argument("id", type=int)
parser.add_argument("--include-mail", action="store_true")
parser.add_argument("--smoke-bundle", type=Path, metavar="TAR")
def handle(self, *args, **options):
resource = options["resource"]
record_id = options["id"]
include_mail = options["include_mail"]
bundle = options["smoke_bundle"]
if include_mail and resource != "account-backup":
raise CommandError("--include-mail requires account-backup.")
if bundle and resource != "apache-preview":
raise CommandError("--smoke-bundle requires apache-preview.")
if not 0 < record_id < 2**63:
raise CommandError("Enter a positive 64-bit resource ID.")
model = RESOURCE_MODELS[resource]
try:
record = model.objects.get(pk=record_id)
except model.DoesNotExist as error:
raise CommandError(
f"No {resource} with ID {record_id}."
) from error
if resource == "apache-preview":
if not record.can_export:
raise CommandError(
"Select a completed preview for the current domain."
)
if bundle:
self.write_bundle(record, bundle)
return
return serialize_deployment_manifest(record)
if resource == "account-backup":
if record.retired_at:
raise CommandError("Select an active hosting account.")
manifest = account_backup_manifest(
record, include_mailboxes=include_mail
)
else:
manifest = record.spec.manifest()
return json.dumps(manifest, indent=2)
def write_bundle(self, plan, path):
data = build_web_smoke_bundle(plan)
try:
with path.open("xb") as output:
output.write(data)
except OSError as error:
raise CommandError(
f"Could not write the bundle: {error}"
) from error
@@ -18,8 +18,9 @@
{% if is_tenant or perms.hosting.view_hostingdnszone %}<a href="#domains-dns">Domains and DNS</a>{% endif %} {% if is_tenant or perms.hosting.view_hostingdnszone %}<a href="#domains-dns">Domains and DNS</a>{% endif %}
{% if is_tenant or perms.hosting.view_hostingmailbox %}<a href="#email">Email</a>{% endif %} {% if is_tenant or perms.hosting.view_hostingmailbox %}<a href="#email">Email</a>{% endif %}
{% if is_tenant or perms.hosting.view_hostingdatabase %}<a href="#databases">Databases</a>{% endif %} {% 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 show_account_backups %}<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 %} {% 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> </nav>
{% endblock %} {% endblock %}
{% block page_content %} {% block page_content %}
@@ -55,6 +56,7 @@
<div><dt>Added</dt><dd>{{ account.created_at|date:"j M Y, H:i" }} UTC</dd></div> <div><dt>Added</dt><dd>{{ account.created_at|date:"j M Y, H:i" }} UTC</dd></div>
</dl> </dl>
{% include "hosting/account_overview.html" %} {% 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_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"> <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 %} {% if can_retire_account or is_operator and perms.hosting.change_hostingaccount %}
@@ -107,18 +109,21 @@
{% if website_aliases or can_add_website_alias %} {% if website_aliases or can_add_website_alias %}
{% include "hosting/website_aliases.html" %} {% include "hosting/website_aliases.html" %}
{% endif %} {% endif %}
{% if show_web_previews %} {% if website_readiness %}
<section class="surface" aria-labelledby="previews-heading"> <section class="surface" aria-labelledby="apache-heading">
<header class="section-heading"> <header class="section-heading">
<h2 id="previews-heading">Recent Apache previews</h2> <div>
{% if is_operator and perms.hosting.change_hostingaccount %} <h2 id="apache-heading">Primary website</h2>
<form method="post" action="{% url 'panel:request_plan' account.pk %}"> <p class="heading-meta domain">{{ account.primary_domain }}</p>
{% csrf_token %} </div>
<button class="button primary" type="submit">Request Apache preview</button> {% if can_view_apache_plans and current_apache_plan %}
</form> <a class="button secondary" href="{% url 'panel:plan' current_apache_plan.pk %}?view=current">View Apache configuration</a>
{% endif %} {% endif %}
</header> </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> </section>
{% endif %} {% endif %}
</div> </div>
@@ -169,9 +174,6 @@
<button class="button secondary compact" type="submit">Open phpMyAdmin</button> <button class="button secondary compact" type="submit">Open phpMyAdmin</button>
</form> </form>
{% endif %} {% endif %}
{% if is_operator %}
<a class="button secondary compact" href="{% url 'panel:database_manifest' database.pk %}" aria-label="Download manifest for {{ database }}">Download manifest</a>
{% endif %}
</div> </div>
{% if is_operator and manage_database_provisioning and database.provisioning.problem %} {% if is_operator and manage_database_provisioning and database.provisioning.problem %}
<p class="heading-meta">{{ database.provisioning.problem }}</p> <p class="heading-meta">{{ database.provisioning.problem }}</p>
@@ -219,7 +221,6 @@
{% if is_operator %} {% if is_operator %}
<td> <td>
<div class="form-actions"> <div class="form-actions">
<a class="button secondary compact" href="{% url 'panel:dns_zone_manifest' zone.pk %}" aria-label="Download DNS manifest for {{ zone.domain }}">Download manifest</a>
{% if show_dns_replication %} {% if show_dns_replication %}
<a class="button secondary compact" href="{% url 'panel:dns_replication' zone.pk %}">Check replication</a> <a class="button secondary compact" href="{% url 'panel:dns_replication' zone.pk %}">Check replication</a>
{% endif %} {% endif %}
@@ -361,9 +362,6 @@
{% if show_mailbox_credentials %} {% if show_mailbox_credentials %}
<a class="button secondary compact" href="{% url 'panel:mailbox_credentials' mailbox.pk %}" aria-label="Connection details for {{ mailbox }}">Connection details</a> <a class="button secondary compact" href="{% url 'panel:mailbox_credentials' mailbox.pk %}" aria-label="Connection details for {{ mailbox }}">Connection details</a>
{% endif %} {% endif %}
{% if is_operator %}
<a class="button secondary compact" href="{% url 'panel:mailbox_manifest' mailbox.pk %}" aria-label="Download mailbox manifest for {{ mailbox }}">Download manifest</a>
{% endif %}
{% endif %} {% endif %}
{% include "hosting/mailbox_management_links.html" %} {% include "hosting/mailbox_management_links.html" %}
</div> </div>
@@ -397,19 +395,9 @@
{% endif %} {% endif %}
</section> </section>
{% endif %} {% endif %}
{% if show_account_backups or export_backup_manifest %} {% if show_account_backups %}
<section class="account-content" id="backups" data-account-section tabindex="-1" aria-label="Backups"> <section class="account-content" id="backups" data-account-section tabindex="-1" aria-label="Backups">
{% if export_backup_manifest %} {% include "hosting/account_backups.html" %}
<div class="form-actions account-actions">
{% if export_backup_manifest %}
<a class="button secondary" href="{% url 'panel:account_backup_manifest' account.pk %}">Download backup manifest</a>
{% endif %}
{% if export_mail_backup_manifest %}
<a class="button secondary" href="{% url 'panel:account_backup_manifest' account.pk %}?include_mail=1">Download backup manifest with mail</a>
{% endif %}
</div>
{% endif %}
{% if show_account_backups %}{% include "hosting/account_backups.html" %}{% endif %}
</section> </section>
{% endif %} {% endif %}
{% endblock %} {% endblock %}
@@ -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>
@@ -33,9 +33,6 @@
{% if action.value == 'settings' %}<a class="button secondary compact" href="{% url 'panel:independent_php_settings' account.pk website.pk %}">{{ action.label }}</a> {% if action.value == 'settings' %}<a class="button secondary compact" href="{% url 'panel:independent_php_settings' account.pk website.pk %}">{{ action.label }}</a>
{% else %}<a class="button {% if action.value == 'retire' %}danger{% else %}secondary{% endif %} compact" href="{% url 'panel:independent_website_operation' account.pk website.pk action.value %}">{{ action.label }}</a>{% endif %} {% else %}<a class="button {% if action.value == 'retire' %}danger{% else %}secondary{% endif %} compact" href="{% url 'panel:independent_website_operation' account.pk website.pk action.value %}">{{ action.label }}</a>{% endif %}
{% endfor %} {% endfor %}
{% if is_operator and perms.hosting.view_hostingaccount %}
<a class="button secondary compact" href="{% url 'panel:independent_website_manifest' account.pk website.pk %}">Download manifest</a>
{% endif %}
</div></td> </div></td>
</tr> </tr>
{% endfor %} {% endfor %}
@@ -1,37 +1,51 @@
{% extends "hosting/workspace_page.html" %} {% 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 %} {% block page_header %}
<header class="page-heading"> <header class="page-heading">
<div> <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> <p class="heading-meta domain">{{ plan.primary_domain }}</p>
</div> </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> <a class="button secondary" href="{% url 'panel:plan' plan.pk %}">Refresh status</a>
{% endif %}
{% endif %} {% endif %}
</header> </header>
{% endblock %} {% endblock %}
{% block page_context %} {% 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 %} {% endblock %}
{% block page_content %} {% block page_content %}
<dl class="details surface"> <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>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> </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 %} {% 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> <p class="notice">This preview captures the original domain. The hosting account now uses <strong>{{ plan.account.primary_domain }}</strong>.</p>
{% endif %} {% endif %}
{% if plan.completed_at %} {% if plan.completed_at %}
<section class="surface" aria-labelledby="configuration-heading"> <section class="surface" aria-labelledby="configuration-heading">
<header class="section-heading"> <header class="section-heading">
<h2 id="configuration-heading">Virtual host configuration</h2> <div>
{% if not is_reseller and plan.can_export %} <h2 id="configuration-heading">{% if plan_mode == "current" %}Primary HTTP virtual host{% else %}Virtual host configuration{% endif %}</h2>
<div class="form-actions"> {% if plan_mode == "current" %}<p class="heading-meta">Coulobre’s recorded configuration. HTTPS and alias configuration are managed separately.</p>{% endif %}
<a class="button secondary" href="{% url 'panel:download_deployment_manifest' plan.pk %}">Download deployment manifest</a> </div>
<a class="button secondary" href="{% url 'panel:download_smoke_bundle' plan.pk %}">Download test bundle</a> {% if may_manage_https %}
</div> <a class="button secondary" href="{% url 'panel:website_https' plan.account_id %}">Manage HTTPS</a>
{% endif %} {% endif %}
</header> </header>
<pre class="configuration"><code>{{ plan.apache_config }}</code></pre> <pre class="configuration"><code>{{ plan.apache_config }}</code></pre>
@@ -1,16 +1,45 @@
{% extends "hosting/workspace_page.html" %} {% extends "hosting/workspace_page.html" %}
{% block title %}Web provisioning · Coulobre Panel{% endblock %} {% block title %}Web provisioning · Coulobre Panel{% endblock %}
{% block page_header %} {% block page_title %}Web provisioning{% endblock %}
<header class="page-heading"> {% block page_tabs %}
<div> <nav class="account-navigation" aria-label="Web provisioning">
<h1>Web provisioning</h1> <a href="{% url 'panel:plans' %}"{% if not show_history %} aria-current="page"{% endif %}>Current configurations</a>
<p class="heading-meta">{{ paginator.count }} Apache preview{{ paginator.count|pluralize }}</p> <a href="{% url 'panel:plans' %}?tab=history"{% if show_history %} aria-current="page"{% endif %}>History</a>
</div> </nav>
</header>
{% endblock %} {% endblock %}
{% block page_content %} {% block page_content %}
<section class="surface" aria-label="Apache previews"> <section class="surface" aria-labelledby="web-configurations-heading">
{% include "hosting/plan_table.html" %} <header class="section-heading">
{% include "hosting/pagination.html" %} <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> </section>
{% include "hosting/pagination.html" %}
{% endblock %} {% endblock %}
@@ -1,11 +1,12 @@
{% if plans %} {% if plans %}
<div class="table-scroll"> <div class="table-scroll">
<table> <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> <tbody>
{% for plan in plans %} {% for plan in plans %}
<tr> <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 class="cell-date muted">{{ plan.requested_at|date:"j M Y, H:i" }} UTC</td>
<td>{% include "hosting/plan_status.html" %}</td> <td>{% include "hosting/plan_status.html" %}</td>
</tr> </tr>
+2 -2
View File
@@ -83,7 +83,7 @@ class AccountBackupManifestTests(TestCase):
(self.cms.spec, self.shop.spec), (self.cms.spec, self.shop.spec),
), ),
) )
self.assertContains( self.assertNotContains(
self.client.get(self.account.get_absolute_url()), self.url self.client.get(self.account.get_absolute_url()), self.url
) )
@@ -141,7 +141,7 @@ class AccountBackupManifestTests(TestCase):
AccountBackup.from_manifest(response.json()).mailboxes, AccountBackup.from_manifest(response.json()).mailboxes,
(old_mailbox.spec, current_mailbox.spec), (old_mailbox.spec, current_mailbox.spec),
) )
self.assertContains( self.assertNotContains(
self.client.get(self.account.get_absolute_url()), self.client.get(self.account.get_absolute_url()),
"Download backup manifest with mail", "Download backup manifest with mail",
) )
+5 -1
View File
@@ -123,10 +123,14 @@ class CustomerAccessTests(TestCase):
detail = self.client.get(self.account.get_absolute_url()) detail = self.client.get(self.account.get_absolute_url())
for label in ( for label in (
"Edit account", "Edit account",
"Recent Apache previews", "Apache preview requested",
"Request Apache preview",
"View Apache configuration",
"Download manifest", "Download manifest",
): ):
self.assertNotContains(detail, label) self.assertNotContains(detail, label)
self.assertContains(detail, 'href="#history"')
self.assertContains(detail, "Hosting account created")
for route, args in ( for route, args in (
("panel:plans", ()), ("panel:plans", ()),
@@ -121,7 +121,7 @@ class DatabaseProvisioningTests(TestCase):
def test_disabled_provisioning_preserves_existing_manifest_download(self): def test_disabled_provisioning_preserves_existing_manifest_download(self):
detail = self.client.get(self.detail) detail = self.client.get(self.detail)
self.assertNotContains(detail, "Provision database") self.assertNotContains(detail, "Provision database")
self.assertContains(detail, "Download manifest") self.assertNotContains(detail, "Download manifest")
self.assertEqual(self.client.post(self.url).status_code, 404) self.assertEqual(self.client.post(self.url).status_code, 404)
def test_operator_can_retry_a_failed_request(self): def test_operator_can_retry_a_failed_request(self):
+1 -1
View File
@@ -391,7 +391,7 @@ class DnsZonePanelTests(TestCase):
zone = self.create_zone() zone = self.create_zone()
self.client.force_login(self.reader) self.client.force_login(self.reader)
account = self.client.get(self.account.get_absolute_url()) account = self.client.get(self.account.get_absolute_url())
self.assertContains(account, "Download DNS manifest") self.assertNotContains(account, "Download DNS manifest")
self.assertNotContains(account, "Edit DNS zone") self.assertNotContains(account, "Edit DNS zone")
self.assertContains( self.assertContains(
self.client.get( self.client.get(
@@ -0,0 +1,102 @@
import json
import tarfile
from io import StringIO
from pathlib import Path
from tempfile import TemporaryDirectory
from django.core.management import CommandError, call_command
from django.test import TestCase
from .models import (
HostingAccount,
HostingDatabase,
HostingDnsZone,
HostingMailbox,
HostingMailDomain,
IndependentWebsite,
WebProvisioningPlan,
WebsiteDomain,
)
from .tasks import render_web_plan
class ExportManifestTests(TestCase):
@classmethod
def setUpTestData(cls):
cls.account = HostingAccount.objects.create(
name="Example", primary_domain="example.net"
)
cls.database = HostingDatabase.objects.create(
account=cls.account, suffix="cms"
)
domain = HostingMailDomain.objects.create(
account=cls.account, domain=cls.account.primary_domain
)
cls.mailbox = HostingMailbox.objects.create(
mail_domain=domain, local_part="contact"
)
cls.zone = HostingDnsZone.objects.create(
account=cls.account,
domain=cls.account.primary_domain,
responsible_name="hostmaster.example.net",
nameservers=["ns1.provider.example", "ns2.provider.example"],
)
cls.website = IndependentWebsite.objects.create(
reservation=WebsiteDomain.objects.create(
account=cls.account, domain="blog.example.net"
)
)
cls.preview = WebProvisioningPlan.for_account(cls.account)
cls.preview.save()
def export(self, resource, pk, *args):
result = StringIO()
call_command(
"export_manifest", resource, str(pk), *args, stdout=result
)
return json.loads(result.getvalue())
def test_provisioning_exports_match_their_manifest_format(self):
for resource, model in (
("database", self.database),
("dns-zone", self.zone),
("mailbox", self.mailbox),
("website", self.website),
):
with self.subTest(resource=resource):
self.assertEqual(
self.export(resource, model.pk), model.spec.manifest()
)
def test_backup_manifest_can_include_requested_mailboxes(self):
self.assertNotIn(
"mailboxes", self.export("account-backup", self.account.pk)
)
self.assertEqual(
self.export("account-backup", self.account.pk, "--include-mail")[
"mailboxes"
],
[self.mailbox.spec.manifest()],
)
def test_preview_must_be_ready_and_bundle_cannot_replace_a_file(self):
with self.assertRaisesMessage(CommandError, "completed preview"):
self.export("apache-preview", self.preview.pk)
render_web_plan.run(self.preview.pk)
self.assertEqual(
self.export("apache-preview", self.preview.pk)["domain"],
"example.net",
)
with TemporaryDirectory() as directory:
path = Path(directory, "test.tar")
args = (
"apache-preview",
str(self.preview.pk),
"--smoke-bundle",
str(path),
)
call_command("export_manifest", *args)
with tarfile.open(path) as archive:
self.assertIn("apache.conf", archive.getnames())
with self.assertRaisesMessage(CommandError, "Could not write"):
call_command("export_manifest", *args)
+12 -3
View File
@@ -82,6 +82,7 @@ class MailboxImportTests(TestCase):
email = reverse("panel:domain_workspace", args=[account.pk, "email"]) email = reverse("panel:domain_workspace", args=[account.pk, "email"])
for path in (email, account.get_absolute_url()): for path in (email, account.get_absolute_url()):
response = self.client.get(path, secure=True) response = self.client.get(path, secure=True)
self.assertNotContains(response, "View import result")
for name, label, variant in ( for name, label, variant in (
("mailbox_import", "Import mail", "secondary"), ("mailbox_import", "Import mail", "secondary"),
( (
@@ -126,11 +127,19 @@ class MailboxImportTests(TestCase):
job.finished_at = timezone.now() job.finished_at = timezone.now()
job.problem = "Check your source password." job.problem = "Check your source password."
job.save(update_fields=["finished_at", "problem"]) job.save(update_fields=["finished_at", "problem"])
self.assertContains(self.client.get(email), "Import needs attention") for path in (email, account.get_absolute_url()):
response = self.client.get(path)
self.assertContains(response, "Import needs attention")
self.assertContains(response, ">Review import</a>")
self.assertNotContains(response, "View import result")
job.problem = "" job.problem = ""
job.save(update_fields=["problem"]) job.save(update_fields=["problem"])
self.assertContains(self.client.get(email), "Import complete") for path in (email, account.get_absolute_url()):
self.assertNotContains(self.client.get(email), "Import in progress") response = self.client.get(path)
self.assertContains(response, "Import complete")
self.assertContains(response, ">View import result</a>", count=1)
self.assertContains(response, ">Import mail</a>", count=1)
self.assertNotContains(response, "Import in progress")
def test_only_the_owner_and_authorized_operator_can_start_import(self): def test_only_the_owner_and_authorized_operator_can_start_import(self):
self.sign_in(self.stranger) self.sign_in(self.stranger)
+61 -3
View File
@@ -1,9 +1,10 @@
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission 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.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 from .tasks import render_web_plan
@@ -90,7 +91,64 @@ class PanelTests(TestCase):
self.assertContains( self.assertContains(
self.client.get(preview_url), "ServerName example.org" 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): def test_viewer_cannot_mutate_accounts_or_read_previews(self):
plan = WebProvisioningPlan.for_account(self.account) plan = WebProvisioningPlan.for_account(self.account)
+1 -1
View File
@@ -74,7 +74,7 @@ class ResellerAccessTests(TestCase):
self.client.get(account.get_absolute_url()).status_code, 404 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.assertContains(previews, "alice.example")
self.assertNotContains(previews, "bob.example") self.assertNotContains(previews, "bob.example")
preview = self.client.get( preview = self.client.get(
+2 -2
View File
@@ -39,7 +39,7 @@ class WebSmokeBundleTests(TestCase):
render_web_plan.run(self.plan.pk) render_web_plan.run(self.plan.pk)
detail = self.client.get(reverse("panel:plan", args=[self.plan.pk])) detail = self.client.get(reverse("panel:plan", args=[self.plan.pk]))
self.assertContains(detail, "Download test bundle") self.assertNotContains(detail, "Download test bundle")
response = self.client.get(self.download) response = self.client.get(self.download)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response["Content-Type"], "application/x-tar") self.assertEqual(response["Content-Type"], "application/x-tar")
@@ -96,7 +96,7 @@ class WebSmokeBundleTests(TestCase):
render_web_plan.run(self.plan.pk) render_web_plan.run(self.plan.pk)
detail = self.client.get(reverse("panel:plan", args=[self.plan.pk])) detail = self.client.get(reverse("panel:plan", args=[self.plan.pk]))
self.assertContains(detail, "Download deployment manifest") self.assertNotContains(detail, "Download deployment manifest")
response = self.client.get(self.manifest) response = self.client.get(self.manifest)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertIn(".json", response["Content-Disposition"]) self.assertIn(".json", response["Content-Disposition"])
+82 -31
View File
@@ -182,6 +182,7 @@ from .sftp import (
site_is_active, site_is_active,
) )
from .smtp_applications import smtp_applications_available from .smtp_applications import smtp_applications_available
from .web_history import current_web_plan, current_web_plans, is_superseded
from .web_node import ( from .web_node import (
SiteStorageLimitForm, SiteStorageLimitForm,
build_web_smoke_bundle, build_web_smoke_bundle,
@@ -823,12 +824,6 @@ class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView):
context["can_enable_alias_https"] = panel_feature_allowed( context["can_enable_alias_https"] = panel_feature_allowed(
"LOCAL_WEB_HTTPS" "LOCAL_WEB_HTTPS"
) and user.has_perms(ENABLE_WEB_HTTPS) ) and user.has_perms(ENABLE_WEB_HTTPS)
context["export_backup_manifest"] = not tenant and user.has_perms(
EXPORT_BACKUP_MANIFEST
)
context["export_mail_backup_manifest"] = context[
"export_backup_manifest"
] and user.has_perm(VIEW_MAILBOXES)
if ( if (
settings.LOCAL_ACCOUNT_BACKUPS settings.LOCAL_ACCOUNT_BACKUPS
and not tenant and not tenant
@@ -886,13 +881,17 @@ class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView):
and owns_customer_operations(user, self.object) and owns_customer_operations(user, self.object)
and (site_active or hasattr(self.object, "sftp")) 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) customer is None and user.has_perm(VIEW_PLANS)
): )
context["show_web_previews"] = True context["can_request_apache_plan"] = not tenant and user.has_perms(
context["plans"] = self.object.webprovisioningplan_set.order_by( (CHANGE_ACCOUNTS, VIEW_PLANS)
"-requested_at", "-pk" )
)[:10] 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: if getattr(self.request, "impersonation", None) is None:
context["show_database_credentials"] = show_credential_action( context["show_database_credentials"] = show_credential_action(
self.request, CredentialKind.DATABASE self.request, CredentialKind.DATABASE
@@ -1085,14 +1084,16 @@ class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView):
or getattr(context.get("website_storage"), "measured_at", None) or getattr(context.get("website_storage"), "measured_at", None)
or getattr(context.get("website_limit"), "applied_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) context.get(name)
for name in ( for name in (
"show_website_storage", "show_website_storage",
"website_php_settings", "website_php_settings",
"website_aliases", "website_aliases",
"can_add_website_alias", "can_add_website_alias",
"show_web_previews", "can_view_apache_plans",
"show_website_usage", "show_website_usage",
"primary_file_access", "primary_file_access",
"manage_website_jobs", "manage_website_jobs",
@@ -1106,20 +1107,9 @@ class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView):
plans = self.object.webprovisioningplan_set.filter( plans = self.object.webprovisioningplan_set.filter(
primary_domain=self.object.primary_domain primary_domain=self.object.primary_domain
).select_related("activation") ).select_related("activation")
plan = ( plan = applied or (
plans.filter( plans.filter(activation__isnull=False).order_by("-pk").first()
activation__finished_at__isnull=False,
activation__problem="",
)
.order_by("-pk")
.first()
) )
if plan is None:
plan = (
plans.filter(activation__isnull=False)
.order_by("-pk")
.first()
)
context["website_readiness"] = provisioning_readiness( context["website_readiness"] = provisioning_readiness(
getattr(plan, "activation", None), "Not set up", "Configured" getattr(plan, "activation", None), "Not set up", "Configured"
) )
@@ -2992,8 +2982,8 @@ class RequestWebPlan(
class PlanList(TenantScopeMixin, PermissionRequiredMixin, ListView): class PlanList(TenantScopeMixin, PermissionRequiredMixin, ListView):
queryset = WebProvisioningPlan.objects.select_related("account").order_by( queryset = WebProvisioningPlan.objects.select_related("account").defer(
"-requested_at", "-pk" "apache_config"
) )
permission_required = VIEW_PLANS permission_required = VIEW_PLANS
reseller_relation = "account__reseller" reseller_relation = "account__reseller"
@@ -3001,6 +2991,22 @@ class PlanList(TenantScopeMixin, PermissionRequiredMixin, ListView):
context_object_name = "plans" context_object_name = "plans"
paginate_by = 20 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): class PlanDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView):
queryset = WebProvisioningPlan.objects.select_related( queryset = WebProvisioningPlan.objects.select_related(
@@ -3013,13 +3019,46 @@ class PlanDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
user = self.request.user 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( 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), and user.has_perms(ACTIVATE_WEB),
local_activation_enabled=panel_feature_allowed( local_activation_enabled=panel_feature_allowed(
"LOCAL_WEB_ACTIVATION" "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), and user.has_perms(ENABLE_WEB_HTTPS),
local_https_enabled=panel_feature_allowed("LOCAL_WEB_HTTPS"), local_https_enabled=panel_feature_allowed("LOCAL_WEB_HTTPS"),
**kwargs, **kwargs,
@@ -3036,6 +3075,12 @@ class RequestWebActivation(
if not panel_feature_allowed("LOCAL_WEB_ACTIVATION"): if not panel_feature_allowed("LOCAL_WEB_ACTIVATION"):
raise Http404 raise Http404
plan = self.get_object() 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: if not plan.can_export:
return HttpResponse( return HttpResponse(
"Request a completed Apache preview for the current " "Request a completed Apache preview for the current "
@@ -3065,6 +3110,12 @@ class RequestWebHTTPS(
if not panel_feature_allowed("LOCAL_WEB_HTTPS"): if not panel_feature_allowed("LOCAL_WEB_HTTPS"):
raise Http404 raise Http404
plan = self.get_object() 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: if not plan.can_enable_https:
return HttpResponse( return HttpResponse(
"Activate the site for the current domain first.", "Activate the site for the current domain first.",
+44
View File
@@ -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"
)
)