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

feat: Create cron job endpoints for incoming anonymisation warnings #2333

Merged
merged 6 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
37 changes: 31 additions & 6 deletions cfl_common/common/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"verify_new_user_second_reminder": 1557173,
"verify_new_user_via_parent": 1551587,
"verify_released_student": 1580574,
"inactive_users_on_website_first_reminder": 1604381,
"inactive_users_on_website_second_reminder": 1606208,
"inactive_users_on_website_final_reminder": 1606215,
}


Expand Down Expand Up @@ -65,7 +68,11 @@
plaintext = loader.get_template(plaintext_template)
html = loader.get_template(html_template)
plaintext_email_context = {"content": text_content}
html_email_context = {"content": text_content, "title": title, "url_prefix": domain()}
html_email_context = {
"content": text_content,
"title": title,
"url_prefix": domain(),
}

# render templates
plaintext_body = plaintext.render(plaintext_email_context)
Expand All @@ -74,11 +81,19 @@

if replace_url:
verify_url = replace_url["verify_url"]
verify_replace_url = re.sub(f"(.*/verify_email/)(.*)", f"\\1", verify_url)
html_body = re.sub(f"({verify_url})(.*){verify_url}", f"\\1\\2{verify_replace_url}", original_html_body)
verify_replace_url = re.sub(

Check warning on line 84 in cfl_common/common/mail.py

View check run for this annotation

Codecov / codecov/patch

cfl_common/common/mail.py#L84

Added line #L84 was not covered by tests
f"(.*/verify_email/)(.*)", f"\\1", verify_url
)
html_body = re.sub(

Check warning on line 87 in cfl_common/common/mail.py

View check run for this annotation

Codecov / codecov/patch

cfl_common/common/mail.py#L87

Added line #L87 was not covered by tests
f"({verify_url})(.*){verify_url}",
f"\\1\\2{verify_replace_url}",
original_html_body,
)

# make message using templates
message = EmailMultiAlternatives(subject, plaintext_body, sender, recipients)
message = EmailMultiAlternatives(
subject, plaintext_body, sender, recipients
)
message.attach_alternative(html_body, "text/html")

message.send()
Expand Down Expand Up @@ -123,7 +138,13 @@

# Dotdigital emails don't work locally, so if testing emails locally use Django to send a dummy email instead
if MODULE_NAME == "local":
django_send_email(from_address, to_addresses, "dummy_subject", "dummy_text_content", "dummy_title")
django_send_email(
from_address,
to_addresses,
"dummy_subject",
"dummy_text_content",
"dummy_title",
)
else:
if auth is None:
auth = app_settings.DOTDIGITAL_AUTH
Expand Down Expand Up @@ -168,4 +189,8 @@
timeout=timeout,
)

assert response.ok, "Failed to send email." f" Reason: {response.reason}." f" Text: {response.text}."
assert response.ok, (

Check warning on line 192 in cfl_common/common/mail.py

View check run for this annotation

Codecov / codecov/patch

cfl_common/common/mail.py#L192

Added line #L192 was not covered by tests
"Failed to send email."
f" Reason: {response.reason}."
f" Text: {response.text}."
)
Loading
Loading