Skip to content

Stock compose no longer locks Settings > Email, and removing SMTP_* unlocks it - #90

Closed
stupleb wants to merge 1 commit into
TraceApps:devfrom
stupleb:fix/smtp-env-lock
Closed

stupleb wants to merge 1 commit into
TraceApps:devfrom
stupleb:fix/smtp-env-lock

Conversation

@stupleb

@stupleb stupleb commented Nov 10, 2026

Copy link
Copy Markdown

The stock docker-compose.yml passes every SMTP_* variable, and when .env doesn't set them they arrive empty, apart from SMTP_PORT=587 and SMTP_SECURE=false. seedSmtpFromEnv counts any variable that's present as set, so a fresh install from the compose file writes an empty server into app_config, sets smtp_env_locked, and Settings > Email (SMTP) shows a locked form with no server in it. The compose file says SMTP can also be set in the Settings UI, but with the stock file it can't.

The lock also never comes off. Once SMTP_* has locked the form, removing the variables and restarting leaves it locked, and the old server stays in app_config, so mail keeps going to it. seedAiFromEnv already clears its lock in that case (from NutriTrace #36); SMTP never got the same.

With this change the environment manages email only when SMTP_HOST names a server. Then it writes the SMTP_* values it has and locks the form, as before. Without one (unset, or empty as the stock compose passes it), the form is the admin's. If an earlier SMTP_HOST had locked it, it unlocks and the values that environment wrote are cleared, so mail stops going to a server nobody configures any more. That goes one step further than the AI fix, which keeps the old values after unlocking; I'm happy to keep them instead if you'd rather match it.

Tests

scripts/smtp-env-lock.test.js covers the stock compose values leaving the form unlocked and a server saved in Settings untouched, SMTP_HOST overriding saved values and locking, removing the variables or emptying SMTP_HOST unlocking and clearing, and repeated starts without SMTP_* keeping a server set up in Settings. On dev without the fix, three of its five tests fail.

What I ran

  • npm run i18n:check and npm test on node:24-bookworm, the steps ci.yml runs: 1167 tests, all passing (the 1162 on dev plus these 5).
  • This branch's server, started three times on one scratch database, reading /api/app-config/env-locks and /api/app-config as an admin: with the stock compose values the form is unlocked; with SMTP_HOST=mail.example.com it's locked with that server; with SMTP_* removed it's unlocked and empty. On dev all three are locked, and the last still holds mail.example.com.

NutriTrace's dev has the same seedSmtpFromEnv; I can open the same change there if that helps.

…cks when SMTP_* is removed

The stock docker-compose.yml passes every SMTP_* variable, empty when .env doesn't set them, and an empty variable counted as set, so Settings > Email (SMTP) was locked with no server. Once locked, removing the variables never unlocked it, and mail kept going to the old server. The environment now manages email only when SMTP_HOST names a server; without one the settings are the admin's, and values an earlier SMTP_HOST wrote are cleared.
@thebigjoe1

Copy link
Copy Markdown
Contributor

Thanks! This is on dev now (fb85346), with the same rule as LiftTrace.

@thebigjoe1 thebigjoe1 closed this Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants