(feature) Add read-only retention plan view
Add a staff-only retention plan page for each host using the SQL-backed retention service. Link it from the host detail page and show policy settings, keep reasons, and snapshots that would be deleted for scheduled, manual, or all snapshot kinds. Keep the flow non-destructive for now, validate query parameters, and cover the view with tests for rendering, base protection, and invalid kind handling.
This commit is contained in:
@@ -6,7 +6,10 @@ from django.db.models import Count
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
from pobsync.errors import ConfigError
|
||||
|
||||
from .models import BackupRun, HostConfig, ScheduleConfig, SnapshotRecord
|
||||
from .retention import run_sql_retention_plan
|
||||
from .snapshot_discovery import discover_snapshots
|
||||
|
||||
|
||||
@@ -70,6 +73,28 @@ def discover_host_snapshots(request, host: str):
|
||||
return redirect("host_detail", host=host_config.host)
|
||||
|
||||
|
||||
@staff_member_required
|
||||
def host_retention_plan(request, host: str):
|
||||
host_config = get_object_or_404(HostConfig, host=host)
|
||||
kind = request.GET.get("kind", "scheduled")
|
||||
if kind not in {"scheduled", "manual", "all"}:
|
||||
messages.error(request, "Retention kind must be scheduled, manual, or all.")
|
||||
return redirect("host_detail", host=host_config.host)
|
||||
protect_bases = request.GET.get("protect_bases") in {"1", "true", "on", "yes"}
|
||||
try:
|
||||
plan = run_sql_retention_plan(host=host_config.host, kind=kind, protect_bases=protect_bases)
|
||||
except ConfigError as exc:
|
||||
messages.error(request, str(exc))
|
||||
return redirect("host_detail", host=host_config.host)
|
||||
context = {
|
||||
"host": host_config,
|
||||
"kind": kind,
|
||||
"protect_bases": protect_bases,
|
||||
"plan": plan,
|
||||
}
|
||||
return render(request, "pobsync_backend/retention_plan.html", context)
|
||||
|
||||
|
||||
def _schedule_for_host(host_config: HostConfig) -> ScheduleConfig | None:
|
||||
try:
|
||||
return host_config.schedule
|
||||
|
||||
Reference in New Issue
Block a user