diff --git a/steward/settings/routes.py b/steward/settings/routes.py index 8afff9a..c905c68 100644 --- a/steward/settings/routes.py +++ b/steward/settings/routes.py @@ -222,8 +222,9 @@ async def notifications(): settings = await get_all_settings(db) if not settings["smtp.tz"] and session.get("tz"): # "Also send to" reads times in the first admin's zone until one is chosen. - async with db.begin(): - await set_setting(db, "smtp.tz", session["tz"]) + # Reading the settings already began this session's transaction. + await set_setting(db, "smtp.tz", session["tz"]) + await db.commit() settings["smtp.tz"] = session["tz"] await _reload_app_config() who = await audience(db) diff --git a/tests/integration/test_users_page.py b/tests/integration/test_users_page.py index 2395ff0..f57b87a 100644 --- a/tests/integration/test_users_page.py +++ b/tests/integration/test_users_page.py @@ -198,3 +198,24 @@ def test_an_account_sets_its_own_address_and_switches_and_an_admin_can_too(app): assert "Who gets email" in page and 'name="notify.alerts.viewer"' in page and "Also send to" in page asyncio.run(_go()) + + +def test_the_first_admin_to_open_notifications_sets_the_also_send_to_zone(app): + async def _go(): + from steward.core.settings import get_setting, set_setting + + async def _tz(): + async with app.db_sessionmaker() as s: + return await get_setting(s, "smtp.tz") + + async with app.db_sessionmaker() as s: + async with s.begin(): + await set_setting(s, "smtp.tz", "") + for zone in ("America/Chicago", "Asia/Tokyo"): + admin, _ = await _client(app) + async with admin.session_transaction() as sess: + sess["tz"] = zone + assert (await admin.get("/settings/notifications/")).status_code == 200 + assert await _tz() == "America/Chicago" # the second admin's zone changes nothing + + asyncio.run(_go())