From 1bf9348706a361e7bd5116f55a65d3c5c60c3b36 Mon Sep 17 00:00:00 2001 From: DonHaul Date: Tue, 10 Sep 2024 14:11:24 +0200 Subject: [PATCH] mailtrain: force subscribe if unsubscribed * ref: cern-sis/issues-inspire/issues/360 --- backend/inspirehep/mailing/providers/mailtrain.py | 7 ++++++- .../cassettes/test_mailtrain_subscribe_user_to_list.yaml | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/inspirehep/mailing/providers/mailtrain.py b/backend/inspirehep/mailing/providers/mailtrain.py index ee70ca66cb..db417eced2 100644 --- a/backend/inspirehep/mailing/providers/mailtrain.py +++ b/backend/inspirehep/mailing/providers/mailtrain.py @@ -23,7 +23,12 @@ def mailtrain_subscribe_user_to_list(list_id, email, first_name, last_name): last_name (str): user last name. """ LOGGER.info("Adding user to the mailing list.", list_id=list_id, email=email) - data = {"FIRST_NAME": first_name, "LAST_NAME": last_name, "EMAIL": email} + data = { + "FIRST_NAME": first_name, + "LAST_NAME": last_name, + "EMAIL": email, + "FORCE_SUBSCRIBE": "yes", + } response = requests.post( f"{current_app.config.get('MAILTRAIN_URL')}/api/subscribe/{list_id}", params={"access_token": current_app.config.get("MAILTRAIN_API_TOKEN")}, diff --git a/backend/tests/integration/mailing/cassettes/test_mailtrain_subscribe_user_to_list.yaml b/backend/tests/integration/mailing/cassettes/test_mailtrain_subscribe_user_to_list.yaml index f9e361261e..ba9e9b8246 100644 --- a/backend/tests/integration/mailing/cassettes/test_mailtrain_subscribe_user_to_list.yaml +++ b/backend/tests/integration/mailing/cassettes/test_mailtrain_subscribe_user_to_list.yaml @@ -1,6 +1,6 @@ interactions: - request: - body: FIRST_NAME=Firstname&LAST_NAME=Lastname&EMAIL=test%40email.ch + body: FIRST_NAME=Firstname&LAST_NAME=Lastname&EMAIL=test%40email.ch&FORCE_SUBSCRIBE=yes headers: Accept: - '*/*' @@ -9,7 +9,7 @@ interactions: Connection: - keep-alive Content-Length: - - '61' + - '81' Content-Type: - application/x-www-form-urlencoded User-Agent: