ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
fix(recycle-bin): say when a restored domain comes back without HTTPS
Juan Denis8ad1bd467f6c
diff --git a/backend/app/services/domain_restore.py b/backend/app/services/domain_restore.pyindex a4cf9aa5..542f1471 100644--- a/backend/app/services/domain_restore.py+++ b/backend/app/services/domain_restore.py@@ -85,3 +85,15 @@ def on_restore_domain(domain):# sat in the bin, and silently talking to Let's Encrypt during a restore is# not something a "put it back" button should do. A covering wildcard is# re-attached above; a per-domain cert is re-enabled explicitly.+ #+ # But SAY so. Without this the domain comes back on plain HTTP while its row+ # still reads ssl_enabled, and nothing tells the person who restored it —+ # they find out when a browser does. Returning a string makes it a notice on+ # the restore toast, not an error: the restore itself succeeded.+ if domain.ssl_enabled:+ cover = SiteDomainService.covering_base(domain.name)+ if not (cover and SiteDomainService.https_enabled(cover)):+ return (f'“{domain.name}” is being served again, but over HTTP — its '+ f'certificate was not re-issued. Re-enable SSL for the domain '+ f'when you are ready to request one.')+ return Nonediff --git a/backend/app/services/recycle_bin_service.py b/backend/app/services/recycle_bin_service.pyindex 89d0e8d0..f23811f0 100644--- a/backend/app/services/recycle_bin_service.py+++ b/backend/app/services/recycle_bin_service.py@@ -103,14 +103,21 @@ def restore(kind, record_id):return None, blockedrow.restore()db.session.commit()+ item = _serialize(kind, entry, row)if entry['on_restore']:try:- entry['on_restore'](row)+ # A hook may RETURN a string: something the user should know about a+ # restore that otherwise worked (a domain coming back without its+ # certificate, say). That is a notice, not a failure — it rides on+ # the item so the caller can tell it apart from the error slot.+ notice = entry['on_restore'](row)+ if notice:+ item['notice'] = str(notice)except Exception as exc: # noqa: BLE001# The row IS back; the side effect is what failed. Say so rather# than rolling back a restore the user asked for.- return _serialize(kind, entry, row), f'restored, but re-applying config failed: {exc}'- return _serialize(kind, entry, row), None+ return item, f'restored, but re-applying config failed: {exc}'+ return item, Nonedef purge(kind, record_id):diff --git a/backend/tests/test_recycle_bin.py b/backend/tests/test_recycle_bin.pyindex 25d244e5..bb6b528d 100644--- a/backend/tests/test_recycle_bin.py+++ b/backend/tests/test_recycle_bin.py@@ -289,3 +289,68 @@ def test_restoring_a_view_is_refused_when_the_name_was_reused(app):assert item is Noneassert 'already have' in errassert SavedView.query.get(first['id']).deleted_at is not None+++# ---- the restore notice ----------------------------------------------------++def test_restoring_an_https_domain_says_it_came_back_on_http(app, app_with_domain, monkeypatch):+ """on_restore_domain deliberately does not re-issue a certificate, so an+ ssl_enabled domain returns over plain HTTP. Silently is the problem: the+ row still reads ssl_enabled, so nothing tells the person who restored it."""+ from app.services import domain_restore++ monkeypatch.setattr(domain_restore.SiteDomainService, 'write_app_vhost',+ classmethod(lambda cls, a: {'nginx': {}, 'warning': None}))+ # No wildcard covers it, so nothing is serving HTTPS for this name.+ monkeypatch.setattr(domain_restore.SiteDomainService, 'covering_base',+ classmethod(lambda cls, name: None))++ with app.app_context():+ domain = Domain.query.get(app_with_domain['domain_id'])+ domain.ssl_enabled = True+ domain.soft_delete()+ db.session.commit()++ item, err = recycle_bin_service.restore('domain', app_with_domain['domain_id'])+ # The restore SUCCEEDED — the notice must not land in the error slot.+ assert err is None+ assert 'HTTP' in item['notice']+ assert 'certificate was not re-issued' in item['notice']+++def test_no_notice_when_a_wildcard_already_covers_the_domain(app, app_with_domain, monkeypatch):+ """app_vhost_kwargs re-attaches a covering wildcard, so HTTPS really is back+ and warning about it would be noise."""+ from app.services import domain_restore++ monkeypatch.setattr(domain_restore.SiteDomainService, 'write_app_vhost',+ classmethod(lambda cls, a: {'nginx': {}, 'warning': None}))+ monkeypatch.setattr(domain_restore.SiteDomainService, 'covering_base',+ classmethod(lambda cls, name: 'example.com'))+ monkeypatch.setattr(domain_restore.SiteDomainService, 'https_enabled',+ classmethod(lambda cls, base: True))++ with app.app_context():+ domain = Domain.query.get(app_with_domain['domain_id'])+ domain.ssl_enabled = True+ domain.soft_delete()+ db.session.commit()++ item, err = recycle_bin_service.restore('domain', app_with_domain['domain_id'])+ assert err is None+ assert 'notice' not in item+++def test_a_plain_http_domain_restores_without_a_notice(app, app_with_domain, monkeypatch):+ from app.services import domain_restore++ monkeypatch.setattr(domain_restore.SiteDomainService, 'write_app_vhost',+ classmethod(lambda cls, a: {'nginx': {}, 'warning': None}))++ with app.app_context():+ Domain.query.get(app_with_domain['domain_id']).soft_delete()+ db.session.commit()++ item, err = recycle_bin_service.restore('domain', app_with_domain['domain_id'])+ assert err is None+ assert 'notice' not in itemdiff --git a/frontend/src/components/settings/RecycleBinTab.jsx b/frontend/src/components/settings/RecycleBinTab.jsxindex 26e325d9..7482e38b 100644--- a/frontend/src/components/settings/RecycleBinTab.jsx+++ b/frontend/src/components/settings/RecycleBinTab.jsx@@ -44,8 +44,11 @@ export default function RecycleBinTab() {setBusyId(rowKey(row));try {const res = await api.restoreRecord(row.kind, row.id);- // The row can be back while a side effect failed — report which.+ // Three outcomes, not two: the side effect FAILED (warning), it+ // succeeded but left something the user should know (notice — a+ // domain that came back without its certificate), or it just worked.if (res?.warning) toast.error(res.warning);+ else if (res?.item?.notice) toast.warning(res.item.notice);else toast.success(`Restored ${row.noun} “${row.label}”`);await load();} catch (err) {