Skip to content

Commit d76e2e1

Browse files
committed
Migrate LISTMONK_ENABLED to a listmonk_enabled feature flag
Replace the static LISTMONK_ENABLED env config with a global feature flag so Listmonk can be toggled remotely without a deploy. Listmonk credentials stay in env and are now required in production unconditionally.
1 parent a962899 commit d76e2e1

5 files changed

Lines changed: 14 additions & 7 deletions

File tree

app/backend.dev.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ BUG_TOOL_GITHUB_REPO=user/repo
5858
BUG_TOOL_GITHUB_USERNAME=user
5959
BUG_TOOL_GITHUB_TOKEN=token
6060

61-
LISTMONK_ENABLED=0
6261
LISTMONK_BASE_URL=https://localhost
6362
LISTMONK_API_USERNAME=...
6463
LISTMONK_API_KEY=...

app/backend/src/couchers/config.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@
9595
("PUSH_NOTIFICATIONS_VAPID_SUBJECT", str),
9696
# Whether to initiate new activeness probes
9797
("ACTIVENESS_PROBES_ENABLED", bool),
98-
# Listmonk (mailing list)
99-
("LISTMONK_ENABLED", bool),
98+
# Listmonk (mailing list, gated at runtime by the `listmonk_enabled` feature flag)
10099
("LISTMONK_BASE_URL", str),
101100
("LISTMONK_API_USERNAME", str),
102101
("LISTMONK_API_KEY", str),
@@ -150,6 +149,16 @@ def check_config(cfg: dict[str, Any]) -> None:
150149
if not cfg["STRIPE_API_KEY"] or not cfg["STRIPE_WEBHOOK_SECRET"] or not cfg["STRIPE_RECURRING_PRODUCT_ID"]:
151150
raise Exception("Stripe credentials must be configured in production")
152151

152+
# Listmonk is gated at runtime by the `listmonk_enabled` feature flag, which can be flipped on
153+
# remotely at any time, so prod must always have the Listmonk credentials present.
154+
if (
155+
not cfg["LISTMONK_BASE_URL"]
156+
or not cfg["LISTMONK_API_USERNAME"]
157+
or not cfg["LISTMONK_API_KEY"]
158+
or not cfg["LISTMONK_LIST_ID"]
159+
):
160+
raise Exception("Listmonk credentials must be configured in production")
161+
153162
# The following features are gated at runtime by feature flags (`strong_verification_enabled`,
154163
# `postal_verification_enabled`, `recaptcha_enabled`), which can be flipped on remotely at any
155164
# time, so prod must always have their credentials present.

app/backend/src/couchers/jobs/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ def send_host_request_reminders(payload: empty_pb2.Empty) -> None:
614614

615615

616616
def add_users_to_email_list(payload: empty_pb2.Empty) -> None:
617-
if not config["LISTMONK_ENABLED"]:
617+
if not experimentation.get_global_boolean_value("listmonk_enabled", default=False):
618618
logger.info("Not adding users to mailing list")
619619
return
620620

app/backend/src/tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ def testconfig():
209209
config["BUG_TOOL_GITHUB_USERNAME"] = "user"
210210
config["BUG_TOOL_GITHUB_TOKEN"] = "token"
211211

212-
config["LISTMONK_ENABLED"] = False
213212
config["LISTMONK_BASE_URL"] = "https://localhost"
214213
config["LISTMONK_API_USERNAME"] = "..."
215214
config["LISTMONK_API_KEY"] = "..."

app/backend/src/tests/test_bg_jobs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,9 +1217,9 @@ def test_send_host_request_reminders(db, moderator):
12171217
assert find in html, f"Expected to find string {find} in HTML email {subject} to {address}, didn't"
12181218

12191219

1220-
def test_add_users_to_email_list(db):
1220+
def test_add_users_to_email_list(db, feature_flags):
1221+
feature_flags.set("listmonk_enabled", True)
12211222
new_config = config.copy()
1222-
new_config["LISTMONK_ENABLED"] = True
12231223
new_config["LISTMONK_BASE_URL"] = "https://example.com"
12241224
new_config["LISTMONK_API_USERNAME"] = "test_user"
12251225
new_config["LISTMONK_API_KEY"] = "dummy_api_key"

0 commit comments

Comments
 (0)