Skip to content

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.

feat(recycle-bin): Recycle Bin UI under Settings > Admin

Juan Denisac4d3bf227ad
diff --git a/frontend/src/components/settings/RecycleBinTab.jsx b/frontend/src/components/settings/RecycleBinTab.jsx
new file mode 100644
index 00000000..26e325d9
--- /dev/null
+++ b/frontend/src/components/settings/RecycleBinTab.jsx
@@ -0,0 +1,227 @@
+import { useCallback, useEffect, useMemo, useState } from 'react';
+import { Trash2, Undo2, RefreshCw, Clock } from 'lucide-react';
+import api from '@/services/api';
+import { useToast } from '@/contexts/ToastContext';
+import { useAuth } from '@/contexts/AuthContext';
+import { Button } from '@/components/ui/button';
+import EmptyState from '@/components/EmptyState';
+import { SegControl, Pill, DataTable, DataTableFooter } from '@/components/ds';
+import ConfirmDialog from '@/components/ConfirmDialog';
+
+// Everything the panel has soft-deleted, in one place. Type-agnostic on
+// purpose: `kind` comes from the server's registry, so a newly restorable model
+// shows up here with no change to this file.
+export default function RecycleBinTab() {
+ const toast = useToast();
+ const { isAdmin } = useAuth();
+ const [items, setItems] = useState([]);
+ const [kinds, setKinds] = useState([]);
+ const [retentionDays, setRetentionDays] = useState(30);
+ const [kind, setKind] = useState('all');
+ const [loading, setLoading] = useState(true);
+ const [busyId, setBusyId] = useState(null);
+ const [purgeTarget, setPurgeTarget] = useState(null);
+
+ const load = useCallback(async () => {
+ try {
+ setLoading(true);
+ const data = await api.getRecycleBin();
+ setItems(data.items || []);
+ setKinds(data.kinds || []);
+ setRetentionDays(data.retention_days ?? 30);
+ } catch (err) {
+ toast.error(err.message || 'Could not load the recycle bin');
+ } finally {
+ setLoading(false);
+ }
+ }, [toast]);
+
+ useEffect(() => { load(); }, []); // eslint-disable-line react-hooks/exhaustive-deps
+
+ const rowKey = (row) => `${row.kind}:${row.id}`;
+
+ const restore = async (row) => {
+ 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.
+ if (res?.warning) toast.error(res.warning);
+ else toast.success(`Restored ${row.noun} “${row.label}”`);
+ await load();
+ } catch (err) {
+ toast.error(err.message || 'Restore failed');
+ } finally {
+ setBusyId(null);
+ }
+ };
+
+ const purge = async (row) => {
+ setBusyId(rowKey(row));
+ try {
+ await api.purgeRecord(row.kind, row.id);
+ toast.success(`Permanently deleted “${row.label}”`);
+ await load();
+ } catch (err) {
+ toast.error(err.message || 'Delete failed');
+ } finally {
+ setBusyId(null);
+ setPurgeTarget(null);
+ }
+ };
+
+ const shown = useMemo(
+ () => (kind === 'all' ? items : items.filter((i) => i.kind === kind)),
+ [items, kind],
+ );
+
+ const filters = useMemo(() => [
+ { value: 'all', label: 'All', count: items.length },
+ ...kinds.map((k) => ({
+ value: k,
+ label: `${k.replace(/_/g, ' ')}s`,
+ count: items.filter((i) => i.kind === k).length,
+ })),
+ ], [items, kinds]);
+
+ const columns = useMemo(() => [
+ {
+ key: 'label',
+ header: 'Record',
+ sortable: true,
+ hideable: false,
+ type: 'text',
+ value: (r) => r.label,
+ render: (r) => (
+ <div className="sk-cell-name">
+ <span>
+ {r.label}
+ {r.description && <div className="sk-cell-sub">{r.description}</div>}
+ </span>
+ </div>
+ ),
+ },
+ {
+ key: 'kind',
+ header: 'Type',
+ sortable: true,
+ type: 'enum',
+ groupable: true,
+ value: (r) => r.noun,
+ render: (r) => <Pill kind="gray">{r.noun}</Pill>,
+ },
+ {
+ key: 'deleted_at',
+ header: 'Deleted',
+ sortable: true,
+ type: 'date',
+ value: (r) => r.deleted_at,
+ render: (r) => {
+ if (!r.deleted_at) return <span className="dom-dash">—</span>;
+ const when = new Date(r.deleted_at);
+ const days = Math.floor((Date.now() - when.getTime()) / 86400000);
+ const left = retentionDays - days;
+ return (
+ <div>
+ <div className="sk-cell-mono">{when.toLocaleDateString()}</div>
+ <div className={`sk-cell-sub ${left <= 3 ? 'is-urgent' : ''}`}>
+ {left > 0 ? `purges in ${left}d` : 'past retention'}
+ </div>
+ </div>
+ );
+ },
+ },
+ {
+ key: '__actions',
+ header: '',
+ sortable: false,
+ hideable: false,
+ className: 'text-right',
+ render: (r) => (
+ <div className="recyclebin__rowactions">
+ <Button
+ variant="outline"
+ size="sm"
+ disabled={busyId === rowKey(r)}
+ onClick={() => restore(r)}
+ >
+ <Undo2 size={14} /> Restore
+ </Button>
+ {isAdmin && (
+ <Button
+ variant="ghost"
+ size="sm"
+ className="recyclebin__purge"
+ disabled={busyId === rowKey(r)}
+ onClick={() => setPurgeTarget(r)}
+ title="Delete permanently"
+ aria-label={`Delete ${r.label} permanently`}
+ >
+ <Trash2 size={14} />
+ </Button>
+ )}
+ </div>
+ ),
+ },
+ ], [busyId, isAdmin, retentionDays]); // eslint-disable-line react-hooks/exhaustive-deps
+
+ return (
+ <div className="settings-section recyclebin">
+ <div className="settings-section__head">
+ <div>
+ <h2>Recycle bin</h2>
+ <p className="settings-section__hint">
+ Deleted records are kept for {retentionDays} days so they can be put back.
+ Restoring returns the record itself — it does not re-apply configuration
+ that was torn down at delete time (a domain’s vhost, for example).
+ </p>
+ </div>
+ <Button variant="outline" size="sm" onClick={load} disabled={loading}>
+ <RefreshCw size={15} /> Refresh
+ </Button>
+ </div>
+
+ {loading ? (
+ <EmptyState loading loadingVariant="table" title="Loading deleted records…" />
+ ) : items.length === 0 ? (
+ <EmptyState
+ icon={Trash2}
+ title="Nothing deleted"
+ description="Records you delete land here first, so a mistake is a click away from being undone."
+ />
+ ) : (
+ <>
+ <div className="recyclebin__toolbar">
+ <SegControl value={kind} onChange={setKind} options={filters} />
+ <span className="recyclebin__retention">
+ <Clock size={13} /> kept {retentionDays} days
+ </span>
+ </div>
+
+ <DataTable
+ columns={columns}
+ data={shown}
+ keyField={rowKey}
+ defaultSorts={[{ key: 'deleted_at', direction: 'desc' }]}
+ storageKey="serverkit-table-recyclebin"
+ emptyTitle="Nothing of this type"
+ emptyMessage="Try another type."
+ footer={(
+ <DataTableFooter shown={shown.length} total={items.length} noun="record" />
+ )}
+ />
+ </>
+ )}
+
+ <ConfirmDialog
+ isOpen={!!purgeTarget}
+ variant="danger"
+ title={`Permanently delete “${purgeTarget?.label ?? ''}”?`}
+ message="This cannot be undone. The record is removed from the database for good."
+ details={purgeTarget ? `${purgeTarget.noun} · deleted ${purgeTarget.deleted_at?.slice(0, 10) || ''}` : ''}
+ confirmText="Delete permanently"
+ onConfirm={() => purgeTarget && purge(purgeTarget)}
+ onCancel={() => setPurgeTarget(null)}
+ />
+ </div>
+ );
+}
diff --git a/frontend/src/data/settingsIndex.js b/frontend/src/data/settingsIndex.js
index 45ed9d62..0739745a 100644
--- a/frontend/src/data/settingsIndex.js
+++ b/frontend/src/data/settingsIndex.js
@@ -58,6 +58,10 @@ export const SETTINGS_INDEX = [
{ id: 'activity-dashboard', label: 'Activity dashboard', description: 'Monitor team activity and view statistics', keywords: 'activity dashboard stats graphs', tab: 'activity', adminOnly: true },
{ id: 'activity-audit-log', label: 'Audit log', description: 'View a detailed audit trail of all system actions and user activities', keywords: 'audit log history actions', tab: 'activity', adminOnly: true },
+ { id: 'recyclebin-restore', label: 'Restore deleted records', description: 'Put back a domain, saved view or other record that was deleted', keywords: 'recycle bin restore undelete undo trash deleted recover', tab: 'recyclebin', adminOnly: true },
+ { id: 'recyclebin-purge', label: 'Permanently delete records', description: 'Destroy a soft-deleted record for good, or purge everything past retention', keywords: 'purge permanent destroy trash empty retention', tab: 'recyclebin', adminOnly: true },
+
+
{ id: 'site-registration', label: 'Public user registration', description: 'Allow or disable new user registration on the login page', keywords: 'registration public signup', tab: 'site', adminOnly: true },
{ id: 'site-appearance', label: 'Panel title & login layout', description: 'Set the panel name shown in the browser tab and on the sign-in page, and pick the login page layout', keywords: 'title brand name login layout appearance tab centered split minimal', tab: 'site', adminOnly: true },
{ id: 'site-app-ports', label: 'Managed app ports', description: 'Control the base port assigned to new applications', keywords: 'ports app wordpress container', tab: 'site', adminOnly: true },
diff --git a/frontend/src/pages/Settings.jsx b/frontend/src/pages/Settings.jsx
index 66bdbfbe..d05b4302 100644
--- a/frontend/src/pages/Settings.jsx
+++ b/frontend/src/pages/Settings.jsx
@@ -11,6 +11,7 @@ import WhiteLabelTab from '../components/settings/WhiteLabelTab';
import NotificationsTab from '../components/settings/NotificationsTab';
import SystemTab from '../components/settings/SystemTab';
import UsersTab from '../components/settings/UsersTab';
+import RecycleBinTab from '../components/settings/RecycleBinTab';
import ActivityTab from '../components/settings/ActivityTab';
import SiteSettingsTab from '../components/settings/SiteSettingsTab';
import SSOConfigTab from '../components/settings/SSOConfigTab';
@@ -23,18 +24,18 @@ import ModulesTab from '../components/settings/ModulesTab';
import WebhooksTab from '../components/settings/WebhooksTab';
import AboutTab from '../components/settings/AboutTab';
import PluginSlot from '../components/PluginSlot';
-import { Activity, Code, Database, Layers, Link2, PaintBucket, Sparkles, Webhook, Settings as SettingsIcon } from 'lucide-react';
+import { Activity, Code, Database, Layers, Link2, PaintBucket, Sparkles, Trash2, Webhook, Settings as SettingsIcon } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { SegControl } from '@/components/ds';
import PageLayout from '../layouts/PageLayout';
import { useNavigate } from 'react-router-dom';
-const VALID_TABS = ['profile', 'security', 'connections', 'appearance', 'sidebar', 'whitelabel', 'notifications', 'system', 'users', 'activity', 'site', 'sso', 'api', 'webhooks', 'ai', 'modules', 'migrations', 'developer', 'about'];
+const VALID_TABS = ['profile', 'security', 'connections', 'appearance', 'sidebar', 'whitelabel', 'notifications', 'system', 'users', 'activity', 'site', 'sso', 'api', 'webhooks', 'ai', 'modules', 'migrations', 'recyclebin', 'developer', 'about'];
// Tabs that belong to the server-wide "Administration" group (admin-only); the
// rest are personal "My Account" settings. Drives the two-way section switch so
// personal prefs aren't interleaved with destructive system controls.
-const ADMIN_TABS = ['users', 'activity', 'site', 'connections', 'sso', 'api', 'webhooks', 'ai', 'modules', 'migrations', 'system', 'developer'];
+const ADMIN_TABS = ['users', 'activity', 'site', 'connections', 'sso', 'api', 'webhooks', 'ai', 'modules', 'migrations', 'recyclebin', 'system', 'developer'];
const Settings = () => {
const [activeTab, setActiveTab] = useTabParam('/settings', VALID_TABS);
@@ -198,6 +199,14 @@ const Settings = () => {
<Activity size={18} />
Activity
</Button>
+ <Button
+ variant="ghost"
+ className={`settings-nav-item ${activeTab === 'recyclebin' ? 'active' : ''}`}
+ onClick={() => setActiveTab('recyclebin')}
+ >
+ <Trash2 size={18} />
+ Recycle bin
+ </Button>
<Button
variant="ghost"
className={`settings-nav-item ${activeTab === 'site' ? 'active' : ''}`}
@@ -318,6 +327,7 @@ const Settings = () => {
{activeTab === 'notifications' && <NotificationsTab />}
{activeTab === 'users' && isAdmin && <UsersTab />}
{activeTab === 'activity' && isAdmin && <ActivityTab />}
+ {activeTab === 'recyclebin' && isAdmin && <RecycleBinTab />}
{activeTab === 'site' && isAdmin && (
<SiteSettingsTab
onDevModeChange={(v) => { setDevMode(v); refreshDevMode(); }}
diff --git a/frontend/src/services/api/index.js b/frontend/src/services/api/index.js
index 747ea550..4e6cdaa5 100644
--- a/frontend/src/services/api/index.js
+++ b/frontend/src/services/api/index.js
@@ -48,6 +48,7 @@ import * as themeMethods from './themes.js';
import * as dashboardMethods from './dashboards.js';
import * as monitorMethods from './monitors.js';
import * as viewMethods from './views.js';
+import * as recycleBinMethods from './recycleBin.js';
class ApiService extends ApiClient {
constructor() {
@@ -103,6 +104,7 @@ class ApiService extends ApiClient {
dashboardMethods,
monitorMethods,
viewMethods,
+ recycleBinMethods,
];
for (const mod of modules) {
for (const [key, fn] of Object.entries(mod)) {
diff --git a/frontend/src/services/api/recycleBin.js b/frontend/src/services/api/recycleBin.js
new file mode 100644
index 00000000..80d469bd
--- /dev/null
+++ b/frontend/src/services/api/recycleBin.js
@@ -0,0 +1,32 @@
+// Recycle Bin — soft-deleted records across every model that opted into
+// SoftDeleteMixin. Type-agnostic: `kind` comes from the server's registry, so
+// new restorable types appear here without a client change.
+
+// { items: [{ kind, noun, id, label, description, deleted_at, deleted_by_id }],
+// kinds: [...], retention_days }
+export async function getRecycleBin({ kind, limit } = {}) {
+ const params = new URLSearchParams();
+ if (kind) params.set('kind', kind);
+ if (limit) params.set('limit', String(limit));
+ const qs = params.toString();
+ return this.request(`/recycle-bin${qs ? `?${qs}` : ''}`);
+}
+
+// Put a record back. Resolves with { item, warning } — a warning means the row
+// returned but re-applying its side effects (a vhost, say) failed.
+export async function restoreRecord(kind, id) {
+ return this.request(`/recycle-bin/${kind}/${id}/restore`, { method: 'POST' });
+}
+
+// Destroy permanently. Admin-only, and the only irreversible call here.
+export async function purgeRecord(kind, id) {
+ return this.request(`/recycle-bin/${kind}/${id}`, { method: 'DELETE' });
+}
+
+// Reap every tombstone older than the retention window.
+export async function purgeExpiredRecords(retentionDays) {
+ return this.request('/recycle-bin/purge-expired', {
+ method: 'POST',
+ body: JSON.stringify({ retention_days: retentionDays }),
+ });
+}
diff --git a/frontend/src/styles/components/_datagrid.scss b/frontend/src/styles/components/_datagrid.scss
index eba4a0f6..250e01e7 100644
--- a/frontend/src/styles/components/_datagrid.scss
+++ b/frontend/src/styles/components/_datagrid.scss
@@ -1204,3 +1204,44 @@
.sk-viewpick__title { font-size: 17px; }
}
+
+// ---------------------------------------------------------------- recycle bin
+// Settings > Recycle bin. Deliberately quiet: this is a safety net, not a
+// destination — the loudest thing on it should be Restore, not Delete.
+.recyclebin {
+ &__toolbar {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ flex-wrap: wrap;
+ margin-bottom: 14px;
+ }
+
+ &__retention {
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ font-family: var(--mono);
+ font-size: 11px;
+ color: var(--text-ghost);
+ margin-left: auto;
+ }
+
+ &__rowactions {
+ display: flex;
+ align-items: center;
+ justify-content: flex-end;
+ gap: 6px;
+ }
+
+ // Purge is the one irreversible control here, so it stays a quiet icon
+ // until you reach for it.
+ &__purge {
+ color: var(--text-ghost);
+
+ &:hover:not(:disabled) { color: var(--red); background: var(--red-bg); }
+ }
+
+ // "purges in 2d" — the last chance to notice before it is gone for good.
+ .sk-cell-sub.is-urgent { color: var(--amber); }
+}