The off-site copies of a removed app end 30 days after „delete backup data” — the box's half (felhom.eu R-1374 part 1; D72, D84)
gates / gates (push) Successful in 41s

Built, not released; no box has run it. felhom.eu `07-backup-architecture.md` §8.2f.
It does nothing without a hub that knows it: an older hub agrees to no id.

- The record: settings `offsite_ends` {app, removed_at, ends_at}. One writer
  (backup.StartOffsiteEnd), called by a removal only with „delete backup data”
  and by „Törlés 30 nap múlva” on the restore page. A second press changes
  nothing. No record, no deletion. Only on the hub-provisioned tier.
- The date is on the remove dialog before the press; the restore page shows
  „Törlésre kijelölve …” with „Mégis megtartom”, and one history line per
  carried-out end. An install of the same app deletes the record.
- The weekly window: after the guard has passed the policy's plan under the cap
  as before, it adds the snapshots whose app tags are ALL due records, that the
  hub agreed to and the box named in the same request; the result names them
  apart (removed_for_ended_apps). `_shares`, the box's own stacks and an
  installed app are never due.
- The report carries the pending records; the household gets one mail per
  press (offsite_end_scheduled), in both languages.

MinAgent unchanged (0.158.1). 143 parity fixtures gained the dialog's one new
script line (patched, not regenerated); one new parity case.
Tests TestD72_*, TestD84_*; 56 mutations seen red
(felhom.eu documentation/audits/build-release-4-2026-11-15/A/redproof-ctrl-*.txt).

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
admin committed 2026-11-15 14:09:47 +01:00
1 parent 591195fadd
commit f628cb5082
177 files changed
+3705 -164

No files matched your search

+128
View File
@@ -0,0 +1,128 @@
package web
import (
"errors"
"net/http"
"sort"
"strings"
"time"
"gitea.dooplex.hu/admin/felhom-controller/internal/backup"
"gitea.dooplex.hu/admin/felhom-controller/internal/i18n"
"gitea.dooplex.hu/admin/felhom-controller/internal/settings"
)
// D72 / D84 (`09` §3 decisions 292 and 309; `07-backup-architecture.md` §8.2f, part 2) — THE HOUSEHOLD SEES THE DATE
// AND CAN TAKE IT BACK. The off-site list on the restore page is keyed on the store, not on what is installed
// (R-237), so a removed app stays on it while its copies exist:
//
// - an app with an end record reads „marked for deletion: <date>” and has ONE button, „keep it after all”;
// - a removed app with copies and NO record (its backups were kept, or it was removed before this existed) reads
// „the off-site copies of this app were kept” and has „delete in 30 days” — the household starts the clock itself;
// - an end a clean-up window has carried out is one line of history.
//
// Nothing here deletes anything: both buttons only write or delete the end record (backup.StartOffsiteEnd,
// backup.KeepOffsiteCopies). The deletion is the weekly window's, after the hub agreed.
// offsiteEndDoneRow is one history line: „<app>: the off-site copies were deleted on <date>”.
type offsiteEndDoneRow struct {
App string
Line string
}
// applyOffsiteEnds puts the end records on the rows. offered = this box has the hub-provisioned tier.
//
// A record whose app has no row (the store could not be read, or its listing is cut) still gets a row: the
// take-back button must not depend on a network read succeeding.
func applyOffsiteEnds(rows []OffsiteRestoreRow, ends []settings.OffsiteEnd, offered bool, date func(e settings.OffsiteEnd) string) []OffsiteRestoreRow {
byApp := make(map[string]settings.OffsiteEnd, len(ends))
for _, e := range ends {
byApp[e.App] = e
}
seen := map[string]bool{}
for i := range rows {
r := &rows[i]
seen[r.App] = true
if e, ok := byApp[r.App]; ok && !r.Installed {
r.EndDate = date(e)
continue
}
// „delete in 30 days”: only for a removed app whose copies are really there, on a box where a press can
// start the clock. Never for an installed app, never for a row we could not verify.
r.EndOffered = offered && r.InStore && !r.Installed && !r.StoreUnknown
}
var extra []OffsiteRestoreRow
for _, e := range ends {
if !seen[e.App] {
extra = append(extra, OffsiteRestoreRow{App: e.App, DisplayName: e.App, EndDate: date(e)})
}
}
sort.Slice(extra, func(i, j int) bool { return extra[i].App < extra[j].App })
return append(rows, extra...)
}
// offsiteEndData adds the end records to the restore page's data.
func (s *Server) offsiteEndData(r *http.Request, data map[string]interface{}, rows []OffsiteRestoreRow) []OffsiteRestoreRow {
if s.backupMgr == nil {
return rows
}
lang := s.langFor(r)
rows = applyOffsiteEnds(rows, s.backupMgr.PendingOffsiteEnds(), s.backupMgr.OffsiteEndOffered(), func(e settings.OffsiteEnd) string {
return s.msgLang(lang, "offsite_end.marked", i18n.FormatDate(lang, e.Ends().Local()))
})
var done []offsiteEndDoneRow
for _, d := range s.backupMgr.OffsiteEndsHistory() {
at, perr := time.Parse(time.RFC3339, d.DeletedAt)
if perr != nil {
continue
}
done = append(done, offsiteEndDoneRow{App: d.App, Line: s.msgLang(lang, "offsite_end.done", i18n.FormatDate(lang, at.Local()))})
}
data["OffsiteEndsDone"] = done
return rows
}
// offsiteEndKeepHandler is „keep it after all”: POST /backup/offsite-end/keep (app). It deletes the end record.
// After the window has run there is no record, and the page says so.
func (s *Server) offsiteEndKeepHandler(w http.ResponseWriter, r *http.Request) {
if s.backupMgr == nil {
offboxRedirectTo(w, r, "/backups/restore", "flash.offbox.mgr_unreachable", true)
return
}
_ = r.ParseForm()
app := strings.TrimSpace(r.FormValue("app"))
kept, err := s.backupMgr.KeepOffsiteCopies(app)
switch {
case err != nil:
s.logger.Printf("[WARN] [web] keep the off-site copies of %s: the end record could not be deleted: %v", app, err)
offboxRedirectTo(w, r, "/backups/restore", "flash.offsite_end.failed", true)
case !kept:
offboxRedirectTo(w, r, "/backups/restore", "flash.offsite_end.nothing_to_keep", true)
default:
s.logger.Printf("[INFO] [web] the household keeps the off-site copies of %s after all (from %s)", app, r.RemoteAddr)
offboxRedirectTo(w, r, "/backups/restore", "flash.offsite_end.kept", false)
}
}
// offsiteEndStartHandler is „delete in 30 days”: POST /backup/offsite-end/start (app). The same press as „delete
// backup data” at a removal — the same record, the same one mail — for an app that was removed without one.
func (s *Server) offsiteEndStartHandler(w http.ResponseWriter, r *http.Request) {
if s.backupMgr == nil {
offboxRedirectTo(w, r, "/backups/restore", "flash.offbox.mgr_unreachable", true)
return
}
_ = r.ParseForm()
app := strings.TrimSpace(r.FormValue("app"))
rec, _, err := s.backupMgr.StartOffsiteEnd(app)
switch {
case errors.Is(err, backup.ErrOffsiteEndNotOffered), errors.Is(err, backup.ErrOffsiteEndLiving):
s.logger.Printf("[WARN] [web] delete-in-30-days for %q refused: %v", app, err)
offboxRedirectTo(w, r, "/backups/restore", "flash.offsite_end.not_possible", true)
case err != nil:
s.logger.Printf("[WARN] [web] delete-in-30-days for %q: the end record was not written: %v", app, err)
offboxRedirectTo(w, r, "/backups/restore", "flash.offsite_end.failed", true)
default:
// Also on a second press: the record stands as it was, and the page says its date again.
offboxRedirectTo(w, r, "/backups/restore", "offsite_end.marked", false, i18n.FormatDate(s.langFor(r), rec.Ends().Local()))
}
}