disallow to disable guard during focus
docker / image (push) Failing after 24s
lint / ruff (push) Failing after 28s
tests / backend (push) Successful in 37s
tests / desktop (push) Successful in 22s
tests / android-core (push) Successful in 49s
tests / web (push) Successful in 1m20s
android / apk (push) Successful in 8m49s

This commit is contained in:
timka123 committed 2026-10-28 09:50:58 +03:00
1 parent 157a113c39
commit d280101bce
21 files changed
+481 -43

No files matched your search

+23 -3
View File
@@ -20,7 +20,7 @@ from sqlalchemy.orm import Session
from app.config import env_settings
from app.models import SettingsRow
from app.services import pomodoro
from app.services import blocker_service, pomodoro
from app.settings_schema import SECRET_FIELDS, SECRET_MASK, AppSettings
_SETTINGS_ID = 1
@@ -192,10 +192,17 @@ def unmask_secrets(stored: dict[str, Any], incoming: dict[str, Any]) -> dict[str
def apply_patch(session: Session, patch: dict[str, Any]) -> AppSettings:
"""Merge a partial settings document (as the UI sends it) and store it."""
current = load_settings(session).model_dump(mode="json")
stored = load_settings(session)
current = stored.model_dump(mode="json")
patch = unmask_secrets(current, patch)
merged = _merge(current, patch)
updated = save_settings(session, AppSettings.model_validate(merged))
candidate = AppSettings.model_validate(merged)
# Validate, then refuse, then write: a malformed patch stays a 422 rather
# than becoming a 409, and nothing is stored either way.
blocker_service.ensure_guard_not_switched_off(session, stored, candidate)
updated = save_settings(session, candidate)
# A changed Focus/Short/Long minute (directly, or via a preset) resizes
# whatever interval is already running or paused — see
@@ -203,3 +210,16 @@ def apply_patch(session: Session, patch: dict[str, Any]) -> AppSettings:
# is simplest to always run it rather than detect which keys changed.
pomodoro.rescale_current(session, updated)
return updated
def reset_to_env(session: Session) -> AppSettings:
"""Back to the environment seed — refused if that would unguard a live interval.
`settings_from_env` never touches the `blocker` subtree, so a reset always
lands on the schema default `enabled = False`: without this check one POST
would switch the focus guard off mid-interval.
"""
stored = load_settings(session)
fresh = settings_from_env()
blocker_service.ensure_guard_not_switched_off(session, stored, fresh)
return save_settings(session, fresh)