Skip to content

Commit

Permalink
Merge branch 'master' into password_breach
Browse files Browse the repository at this point in the history
  • Loading branch information
KamilPawel committed Jun 22, 2023
2 parents 8d713a1 + 69d6aa2 commit 1935d1d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
yarn build
mv build ../portal/frontend
- name: Release codeforlife-portal
uses: ocadotechnology/python-semantic-release@patch-packaging-error
uses: relekang/python-semantic-release@master
with:
github_token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
pypi_token: ${{ secrets.PYPI_TOKEN }}
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

<!--next-version-placeholder-->

## v6.31.2 (2023-06-16)

### Fix

* Allow more scripts from GTM in CSP ([#2103](https://github.com/ocadotechnology/codeforlife-portal/issues/2103)) ([`eb074d5`](https://github.com/ocadotechnology/codeforlife-portal/commit/eb074d521f03470aaa28293790302e2559884763))

## v6.31.1 (2023-06-16)

### Fix

* Correct repo name ([`a85994d`](https://github.com/ocadotechnology/codeforlife-portal/commit/a85994dbd8a30bd18df76523f381ac3a8290e19a))
* Go back to actual semantic release repo ([`c12eb7e`](https://github.com/ocadotechnology/codeforlife-portal/commit/c12eb7ec47328f401407a2116b0e349632bfabba))
* 1454 shorten url in aws emails ([#2101](https://github.com/ocadotechnology/codeforlife-portal/issues/2101)) ([`5f4d68c`](https://github.com/ocadotechnology/codeforlife-portal/commit/5f4d68c0604611cb271fcadc9d2a173bc9db1496))
* Update Gtag reference to new GA4 ([#2099](https://github.com/ocadotechnology/codeforlife-portal/issues/2099)) ([`ee50987`](https://github.com/ocadotechnology/codeforlife-portal/commit/ee50987efb571d2e9bc721e89da17e7be5213963))

## v6.31.0 (2023-06-14)
### Feature
* Remove intermediate pages and go direct to gitbook resources ([#2098](https://github.com/ocadotechnology/codeforlife-portal/issues/2098)) ([`2c6cb61`](https://github.com/ocadotechnology/codeforlife-portal/commit/2c6cb61b9753ecaa610e0d3d479ac5cf3eaf7210))
Expand Down
3 changes: 1 addition & 2 deletions cfl_common/common/csp_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
"https://euc-widget.freshworks.com/",
"https://cdn-ukwest.onetrust.com/",
"https://code.iconify.design/2/2.0.3/iconify.min.js",
"https://www.googletagmanager.com/gtm.js",
"https://www.googletagmanager.com/",
"https://cdn.mouseflow.com/",
"https://www.google-analytics.com/analytics.js",
"https://www.recaptcha.net/",
"https://www.google.com/recaptcha/",
"https://www.gstatic.com/recaptcha/",
Expand Down
6 changes: 5 additions & 1 deletion cfl_common/common/email_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def emailVerificationNeededEmail(request, token):
f"Please go to {url} to verify your email address.\n\nBy activating the account you confirm that you have "
f"read and agreed to our terms ({terms_url}) and our privacy notice ({privacy_notice_url})."
),
"url": {"verify_url": url},
}


Expand All @@ -43,18 +44,21 @@ def parentsEmailVerificationNeededEmail(request, user, token):
f"account you confirm that you have read and agreed to our terms ({terms_url}) and our privacy notice "
f"({privacy_notice_url})."
),
"url": {"verify_url": url},
}


def emailChangeVerificationEmail(request, token):
url = f"{request.build_absolute_uri(reverse('verify_email', kwargs={'token': token}))}"
return {
"subject": f"Email verification needed",
"message": (
f"You are changing your email, please go to "
f"{request.build_absolute_uri(reverse('verify_email', kwargs={'token': token}))} "
f"{url} "
f"to verify your new email address. If you are not part of Code for Life "
f"then please ignore this email."
),
"url": {"verify_url": url},
}


Expand Down
18 changes: 13 additions & 5 deletions cfl_common/common/helpers/emails.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import json
import re
from enum import Enum, auto
from uuid import uuid4

Expand Down Expand Up @@ -41,6 +42,7 @@ def send_email(
subject,
text_content,
title,
replace_url=None,
plaintext_template="email.txt",
html_template="email.html",
):
Expand All @@ -54,7 +56,13 @@ def send_email(

# render templates
plaintext_body = plaintext.render(plaintext_email_context)
html_body = html.render(html_email_context)
original_html_body = html.render(html_email_context)
html_body = original_html_body

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)

# make message using templates
message = EmailMultiAlternatives(subject, plaintext_body, sender, recipients)
Expand Down Expand Up @@ -113,18 +121,18 @@ def send_verification_email(request, user, data, new_email=None, age=None):
# if the user is a teacher
if age is None:
message = emailVerificationNeededEmail(request, verification)
send_email(VERIFICATION_EMAIL, [user.email], message["subject"], message["message"], message["subject"])
send_email(VERIFICATION_EMAIL, [user.email], message["subject"], message["message"], message["subject"], replace_url=message["url"])

if _newsletter_ticked(data):
add_to_dotmailer(user.first_name, user.last_name, user.email, DotmailerUserType.TEACHER)
# if the user is an independent student
else:
if age < 13:
message = parentsEmailVerificationNeededEmail(request, user, verification)
send_email(VERIFICATION_EMAIL, [user.email], message["subject"], message["message"], message["subject"])
send_email(VERIFICATION_EMAIL, [user.email], message["subject"], message["message"], message["subject"], replace_url=message["url"])
else:
message = emailVerificationNeededEmail(request, verification)
send_email(VERIFICATION_EMAIL, [user.email], message["subject"], message["message"], message["subject"])
send_email(VERIFICATION_EMAIL, [user.email], message["subject"], message["message"], message["subject"], replace_url=message["url"])

if _newsletter_ticked(data):
add_to_dotmailer(user.first_name, user.last_name, user.email, DotmailerUserType.STUDENT)
Expand All @@ -133,7 +141,7 @@ def send_verification_email(request, user, data, new_email=None, age=None):
verification = generate_token(user, new_email)

message = emailChangeVerificationEmail(request, verification)
send_email(VERIFICATION_EMAIL, [user.email], message["subject"], message["message"], message["subject"])
send_email(VERIFICATION_EMAIL, [user.email], message["subject"], message["message"], message["subject"], replace_url=message["url"])

message = emailChangeNotificationEmail(request, new_email)
send_email(VERIFICATION_EMAIL, [user.email], message["subject"], message["message"], message["subject"])
Expand Down
2 changes: 1 addition & 1 deletion portal/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "6.31.0"
__version__ = "6.31.2"
22 changes: 6 additions & 16 deletions portal/templates/portal/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,14 @@

{% block google_analytics %}
{% if request|is_production %}
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-R81N6YZYT7"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function() {
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());


ga('create', 'UA-49883146-1', 'auto');
ga('send', 'pageview');

function send_event(category_name, action, label_name) {
ga('send', {
hitType: 'event',
eventCategory: category_name,
eventAction: action,
eventLabel: label_name
});
}
gtag('config', 'G-R81N6YZYT7');
</script>

<script src="/static/portal/js/riveted.min.js"></script>
Expand Down

0 comments on commit 1935d1d

Please sign in to comment.