fix: always send device config on save — sync toggle now works both ways

This commit is contained in:
Mathieu Moran
2026-08-12 00:16:57 -04:00
parent 79222c8bb5
commit 69109762a8
2 changed files with 18 additions and 16 deletions
+7 -3
View File
@@ -36,10 +36,14 @@ def update_device_config(body, errors):
# Allow toggling sync_enabled off # Allow toggling sync_enabled off
if "sync_enabled" in body and not body["sync_enabled"]: if "sync_enabled" in body and not body["sync_enabled"]:
_set_sync_enabled(False) _set_sync_enabled(False)
# Toggling off is always allowed — don't return error even if # Toggling off is always allowed — don't error on locked fields
# other locked fields are in the body (the JS always sends them). # (the JS always sends them alongside the toggle).
return errors return errors
# User cannot edit locked fields while syncing from server. # Sync is staying enabled — locked fields are ignored silently.
# The JS always sends them; rejecting would break the save flow.
if "sync_enabled" in body and body["sync_enabled"]:
return errors
# User tried to edit locked fields without the sync toggle — reject.
if any(k in body for k in ["owner_name", "car_model", "avatar_path"]): if any(k in body for k in ["owner_name", "car_model", "avatar_path"]):
errors["error"] = "Cannot edit device config while server sync is enabled. Server is source of truth." errors["error"] = "Cannot edit device config while server sync is enabled. Server is source of truth."
return errors return errors
+1 -3
View File
@@ -459,8 +459,7 @@ form.addEventListener('submit', async event => {
} }
populateRemoteConfig(remoteConfigResult); populateRemoteConfig(remoteConfigResult);
// Save device config (skip if sync is enabled — server is source of truth) // Save device config (always send — backend validates locked fields when sync is on)
if (!fields.deviceSyncEnabled.checked) {
const deviceConfigResponse = await fetch('/api/device-config', { const deviceConfigResponse = await fetch('/api/device-config', {
method: 'POST', method: 'POST',
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
@@ -472,7 +471,6 @@ form.addEventListener('submit', async event => {
throw new Error(deviceConfigResult.error || `HTTP ${deviceConfigResponse.status}`); throw new Error(deviceConfigResult.error || `HTTP ${deviceConfigResponse.status}`);
} }
populateDeviceConfig(deviceConfigResult); populateDeviceConfig(deviceConfigResult);
}
showMessage('Settings saved.', 'success'); showMessage('Settings saved.', 'success');
} catch (error) { } catch (error) {