Fix quota endpoint: path detection, error handling, better messages

- Backend: detect the actual filesystem mountpoint via 'df' instead of
  hardcoding /srv/samba — setquota needs the mountpoint, not a subpath
- Backend: catch CalledProcessError and FileNotFoundError from setquota
  and return the actual error message (e.g. quota not enabled, package
  not installed) instead of crashing with 500
- Frontend: always send the share path in the quota API call so the
  backend can find the right filesystem, even for SMB per-user quotas
- Frontend: read the actual error message from the response and show it
  in the toast instead of just "N quota(s) failed"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
marcandClaude Sonnet 4.6 committed 2026-06-19 22:36:15 +02:00
1 parent 74737568b0
commit 6631b9e832
2 files changed
+36 -15

No files matched your search

+11 -5
View File
@@ -45,25 +45,31 @@ async function submitQuota() {
for (const inp of document.querySelectorAll('.quota-inp')) {
const gb = parseInt(inp.value);
if (!gb || gb <= 0) continue;
calls.push({ type: 'smb', user: inp.dataset.user, quota: gb });
calls.push({ user: inp.dataset.user, quota: gb, path: _qCtx.path });
}
} else {
const user = document.getElementById('qManualUser')?.value.trim();
const gb = parseInt(document.getElementById('qManualGB')?.value);
if (!user) return showToast('Username is required.', 'danger');
if (!gb || gb <= 0) return showToast('Quota must be a positive number.', 'danger');
calls.push({ type: _qCtx.type, user, path: _qCtx.path, quota: gb });
calls.push({ user, path: _qCtx.path || '/srv', quota: gb });
}
if (!calls.length) return showToast('No quota values entered.', 'warning');
bootstrap.Modal.getInstance(document.getElementById('quotaModal')).hide();
const results = await Promise.all(calls.map(body =>
const responses = await Promise.all(calls.map(body =>
apiFetch('/api/quota', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(body) })
));
const failed = results.filter(r => r && !r.ok).length;
if (failed) showToast(`${failed} quota(s) failed to apply.`, 'danger');
const errors = [];
for (const r of responses) {
if (r && !r.ok) {
const d = await r.json().catch(() => ({}));
errors.push(d.error || `HTTP ${r.status}`);
}
}
if (errors.length) showToast('Quota error: ' + errors.join('; '), 'danger');
else showToast(`Quota${calls.length > 1 ? 's' : ''} applied.`);
loadDashboard();