diff --git a/src/coulobre/hosting/account_backup_forms.py b/src/coulobre/hosting/account_backup_forms.py index f686036..3ef7155 100644 --- a/src/coulobre/hosting/account_backup_forms.py +++ b/src/coulobre/hosting/account_backup_forms.py @@ -7,6 +7,7 @@ from coulobre.account_restore_request import ( MAX_RESTORE_PATH_BYTES, validate_restore_path, ) +from coulobre.database_node import DatabaseSpec from .models import AccountBackupSchedule @@ -68,8 +69,11 @@ class AccountBackupScheduleForm(forms.Form): return cleaned -class WebsiteRestoreForm(forms.Form): +class BackupRestoreForm(forms.Form): restore_id = forms.UUIDField(initial=uuid4, widget=forms.HiddenInput) + + +class WebsiteRestoreForm(BackupRestoreForm): scope = forms.ChoiceField( choices=(("file", "One file"), ("website", "Entire website")), initial="file", @@ -111,3 +115,22 @@ class WebsiteRestoreForm(forms.Form): "replace", "Replacement is only available for one file." ) return cleaned + + +class ComponentRestoreForm(BackupRestoreForm): + resource = forms.ChoiceField(label="Restore target") + + def __init__(self, *args, targets, **kwargs): + super().__init__(*args, **kwargs) + self.fields["resource"].choices = [ + ("", "Select a target"), + *( + ( + key, + target.name + if isinstance(target, DatabaseSpec) + else target.address, + ) + for key, target in targets.items() + ), + ] diff --git a/src/coulobre/hosting/account_backups.py b/src/coulobre/hosting/account_backups.py index 032df1c..37f9fd7 100644 --- a/src/coulobre/hosting/account_backups.py +++ b/src/coulobre/hosting/account_backups.py @@ -1,6 +1,6 @@ from datetime import UTC, datetime, timedelta -from django.core.exceptions import PermissionDenied, ValidationError +from django.core.exceptions import PermissionDenied from django.db import transaction from django.utils import timezone @@ -11,7 +11,6 @@ from .models import ( AccountBackupSchedule, HostingAccount, HostingMailbox, - WebsiteRestoreJob, ) from .resource_requests import lock_hosting_account @@ -115,37 +114,3 @@ def _queue_scheduled_backup(account_id, now): ) schedule.next_run_at = _next_backup_run(schedule, now) schedule.save(update_fields=["next_run_at"]) - - -@transaction.atomic -def queue_website_restore( - backup, *, restore_id, filename, replace, operator_username -): - account = lock_hosting_account(backup.account_id, customer_id=None) - if not backup.can_restore_website( - WebSite(account.pk, account.primary_domain) - ): - raise ValidationError( - "Choose a completed backup of the current website." - ) - - jobs = WebsiteRestoreJob.objects - details = { - "backup_id": backup.pk, - "filename": filename, - "replace": replace, - "operator_username": operator_username, - } - job = jobs.filter(restore_id=restore_id).first() - if job is None: - if jobs.filter( - backup__account=account, finished_at__isnull=True - ).exists(): - raise ValidationError( - "Wait for the current website restore to finish." - ) - job, _ = jobs.get_or_create(restore_id=restore_id, defaults=details) - if any(getattr(job, field) != value for field, value in details.items()): - raise ValidationError( - "Reopen the restore form to submit a new request." - ) diff --git a/src/coulobre/hosting/templates/hosting/account_backups.html b/src/coulobre/hosting/templates/hosting/account_backups.html index ec1f7ab..b6b3269 100644 --- a/src/coulobre/hosting/templates/hosting/account_backups.html +++ b/src/coulobre/hosting/templates/hosting/account_backups.html @@ -62,8 +62,18 @@
{{ job.archive }}
- {% if job.pk in website_restore_sources %}
-
+ {% if job.pk in website_restore_sources or job.pk in database_restore_sources or job.pk in mailbox_restore_sources %}
+ | Requested | Operator | Backup requested | Restore target | Status |
|---|---|---|---|---|
| {{ restore.requested_at|date:"j M Y, H:i" }} UTC | {{ restore.operator_username }} | {{ restore.backup.requested_at|date:"j M Y, H:i" }} UTC |
- {% if restore.filename %}
+ {% if restore.kind %}
+ {{ restore.get_kind_display }} {{ restore.target_name }}
+ {% elif restore.filename %}
{{ restore.filename }}
{% if restore.replace %}(replacement allowed){% endif %}
{% else %}
diff --git a/src/coulobre/hosting/templates/hosting/component_restore.html b/src/coulobre/hosting/templates/hosting/component_restore.html
new file mode 100644
index 0000000..10993c5
--- /dev/null
+++ b/src/coulobre/hosting/templates/hosting/component_restore.html
@@ -0,0 +1,26 @@
+{% extends "hosting/base.html" %}
+{% block title %}Restore {{ restore_kind }} · Coulobre Panel{% endblock %}
+{% block content %}
+ ← {{ account.name }}
+
+
+ Restore {{ restore_kind }}+ +Choose an empty managed database. Keep the application disconnected until the restore completes. + {% else %} +Choose a newly provisioned mailbox with no Maildir. Keep delivery and client access to that mailbox paused until the restore completes. + {% endif %} + + |