Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove references to mailchimp #253

Merged
merged 1 commit into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ pytest
**Used on sparc-api for:** Creates tickets from user feedback to be managed \
**Critical:** no

#### Mail Chimp
**Source:** https://mailchimp.com/ \
**Summary:** Email service \
**Used on sparc-api for:** Email subscriptions from sparc-app \
**Critical:** no

#### oSparc
**Source:** https://osparc.io/ \
**Summary:** Biomedeical Modelling and simulation software \
Expand Down
1 change: 0 additions & 1 deletion app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class Config(object):
K_CORE_TECH_LEAD_WRIKE_ID = os.environ.get("K_CORE_TECH_LEAD_WRIKE_ID")
CCB_HEAD_WRIKE_ID = os.environ.get("CCB_HEAD_WRIKE_ID")
MODERATOR_WRIKE_ID = os.environ.get("MODERATOR_WRIKE_ID")
MAILCHIMP_API_KEY = os.environ.get("MAILCHIMP_API_KEY")
OSPARC_API_URL = os.environ.get("OSPARC_API_URL", "https://api.osparc.io")
OSPARC_API_KEY = os.environ.get("OSPARC_API_KEY")
OSPARC_API_SECRET = os.environ.get("OSPARC_API_SECRET")
Expand Down
87 changes: 0 additions & 87 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1691,93 +1691,6 @@ def execute_webhook():
threading.Thread(target=execute_webhook).start()
return jsonify({"status": "success", "message": "Webhook request received and signature verified"}), 204

@app.route("/mailchimp_subscribe", methods=["POST"])
def subscribe_to_mailchimp():
json_data = request.get_json()
if json_data and 'email_address' in json_data and 'first_name' in json_data and 'last_name' in json_data:
email_address = json_data["email_address"]
first_name = json_data['first_name']
last_name = json_data['last_name']
auth = HTTPBasicAuth('AnyUser', Config.MAILCHIMP_API_KEY)
url = 'https://us2.api.mailchimp.com/3.0/lists/c81a347bd8/members/' + email_address

data = {
"email_address": email_address,
"status": "subscribed",
"merge_fields": {
"FNAME": first_name,
"LNAME": last_name
}
}
try:
resp = requests.put(
url=url,
json=data,
auth=auth
)

if resp.status_code == 200:
return resp.json()
else:
return "Failed to subscribe user with response: " + resp.json()
except Exception as ex:
logging.error("Could not subscribe to newsletter", ex)
return {"error": "An error occured while trying to subscribe to the newsletter"}, 500
else:
abort(400, description="Missing email_address, first_name or last_name")


@app.route("/mailchimp_unsubscribe", methods=["POST"])
def unsubscribe_to_mailchimp():
json_data = request.get_json()
if json_data and "email_address" in json_data:
email_address = json_data["email_address"]
auth = HTTPBasicAuth('AnyUser', Config.MAILCHIMP_API_KEY)
url = "https://us2.api.mailchimp.com/3.0/lists/c81a347bd8/members/" + email_address

data = {
"status": "unsubscribed",
}
try:
resp = requests.put(
url=url,
json=data,
auth=auth
)

if resp.status_code == 200:
return resp.json()
else:
return "Failed to unsubscribe user with response: " + resp.json()
except Exception as ex:
logging.error("Could not unsubscribe to newsletter", ex)
return {"error": "An error occured while trying to unsubscribe to the newsletter"}, 500
else:
abort(400, description="Missing email_address")

@app.route("/mailchimp_member_info/<email_address>", methods=["GET"])
def get_mailchimp_member_info(email_address):
if email_address:
auth = HTTPBasicAuth('AnyUser', Config.MAILCHIMP_API_KEY)
url = 'https://us2.api.mailchimp.com/3.0/lists/c81a347bd8/members/' + email_address

try:
resp = requests.get(
url=url,
auth=auth
)

if resp.status_code == 200:
return resp.json()
else:
return "Failed to get member info with response: " + resp.json()
except Exception as ex:
logging.error(f"Failed to get member info for {email_address}", ex)
return {"error": "Could not get member info from MailChimp"}, 500
else:
abort(400, description="Missing email_address")


# Get list of available name / curie pair
@app.route("/get-organ-curies/")
def get_available_uberonids():
Expand Down
25 changes: 0 additions & 25 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,31 +209,6 @@ def test_hubspot_webhook(client):

assert response.status_code == 204

def test_subscribe_to_mailchimp(client):
r = client.post(f"/mailchimp_subscribe", json={})
assert r.status_code == 400

letters = string.ascii_lowercase
email = ''.join(random.choice(letters) for i in range(8))
domain = ''.join(random.choice(letters) for i in range(6))

email_address = '{}@{}.com'.format(email, domain)

r2 = client.post(f"/mailchimp_subscribe", json={"email_address": email_address, "first_name": "Test", "last_name": "User"})
assert r2.status_code == 200

# this part is only for cleaning the mailchimp list and not pollute the mailing list
returned_data = r2.get_json()
member_hash = returned_data["id"]
url = 'https://us2.api.mailchimp.com/3.0/lists/c81a347bd8/members/{}/actions/delete-permanent'.format(member_hash)
auth = HTTPBasicAuth('AnyUser', Config.MAILCHIMP_API_KEY)
resp = requests.post(
url=url,
auth=auth
)
assert resp.status_code == 204


def test_osparc_viewers(client):
r = client.get('/get_osparc_data')
assert r.status_code == 200
Expand Down