From c8bb5af4ef441cf7a2c5fab9648a9e24950db694 Mon Sep 17 00:00:00 2001 From: Jhonatan Lopes Date: Tue, 12 Mar 2024 15:43:35 -0300 Subject: [PATCH 001/252] Setup logger and unit tests for `_generate_thank_you_url` function (#12034) * Setup func and logger * Add unit tests * added some more logging statements * formatting --------- Co-authored-by: Daniel Miranda Co-authored-by: danielfmiranda --- .../templatetags/mini_site_tags.py | 39 ++++++++++++------- .../tests/templatetags/test_mini_site_tags.py | 38 ++++++++++++++++++ 2 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 network-api/networkapi/wagtailpages/tests/templatetags/test_mini_site_tags.py diff --git a/network-api/networkapi/wagtailpages/templatetags/mini_site_tags.py b/network-api/networkapi/wagtailpages/templatetags/mini_site_tags.py index a84dd69dcec..e88471242d5 100644 --- a/network-api/networkapi/wagtailpages/templatetags/mini_site_tags.py +++ b/network-api/networkapi/wagtailpages/templatetags/mini_site_tags.py @@ -1,3 +1,4 @@ +import logging from urllib.parse import parse_qsl, urlencode, urlparse, urlunparse from django import template @@ -9,6 +10,8 @@ register = template.Library() +logger = logging.getLogger(__name__) + # Instantiate a mini-site sidebar menu based on the current page's relation to other pages @register.inclusion_tag("wagtailpages/tags/mini_site_sidebar.html", takes_context=True) @@ -22,22 +25,30 @@ def mini_site_horizontal_nav(context, page): return get_mini_side_nav_data(context, page) -# Render a page's CTA (petition, signup, etc.) -@register.inclusion_tag("wagtailpages/tags/cta.html", takes_context=True) -def cta(context, page): - def generate_thank_you_url(url): - """ - Generate a thank you page URL by grabbing the current url and appending thank_you=true - """ +def _generate_thank_you_url(url): + """ + Generate a thank you page URL by grabbing the current url and appending thank_you=true + """ + + logger.debug(f'Generating "thank you URL" for {url}') - parsed_url = urlparse(url) - query_params = parse_qsl(parsed_url.query) - query_params.append(("thank_you", "true")) - query_string = urlencode(query_params) - thank_you_url = urlunparse(parsed_url._replace(query=query_string)) + parsed_url = urlparse(url) + logger.debug(f"parsed_url: {parsed_url}") + query_params = parse_qsl(parsed_url.query) + logger.debug(f"query_params: {query_params}") + query_params.append(("thank_you", "true")) + query_string = urlencode(query_params) + logger.debug(f"query_string: {query_string}") + thank_you_url = urlunparse(parsed_url._replace(query=query_string)) - return thank_you_url + logger.debug(f'Generated "thank you URL": {thank_you_url}') + return thank_you_url + + +# Render a page's CTA (petition, signup, etc.) +@register.inclusion_tag("wagtailpages/tags/cta.html", takes_context=True) +def cta(context, page): cta = {"page": page, "cta": None, "cta_type": None} if page.cta: @@ -59,7 +70,7 @@ def generate_thank_you_url(url): source_url = context["request"].build_absolute_uri() cta["source_url"] = source_url - cta["thank_you_url"] = generate_thank_you_url(source_url) + cta["thank_you_url"] = _generate_thank_you_url(source_url) cta["show_formassembly_thank_you"] = context["request"].GET.get("thank_you") == "true" cta["csp_nonce"] = context["request"].csp_nonce diff --git a/network-api/networkapi/wagtailpages/tests/templatetags/test_mini_site_tags.py b/network-api/networkapi/wagtailpages/tests/templatetags/test_mini_site_tags.py new file mode 100644 index 00000000000..1a3c100257b --- /dev/null +++ b/network-api/networkapi/wagtailpages/tests/templatetags/test_mini_site_tags.py @@ -0,0 +1,38 @@ +from unittest import TestCase + +from faker import Faker + +from networkapi.wagtailpages.templatetags import mini_site_tags + + +class GenerateThankYouURLTests(TestCase): + @classmethod + def setUpClass(cls): + cls.fake = Faker() + + def test_url(self): + url = self.fake.url() + thank_you_url = mini_site_tags._generate_thank_you_url(url) + self.assertEqual(thank_you_url, f"{url}?thank_you=true") + + def test_url_keeps_query_params(self): + url = f"{self.fake.url()}?test=123&testa=123" + thank_you_url = mini_site_tags._generate_thank_you_url(url) + self.assertEqual(thank_you_url, f"{url}&thank_you=true") + + def test_url_keeps_utm_params(self): + url = f"{self.fake.url()}?utm_source=source&utm_medium=medium" + thank_you_url = mini_site_tags._generate_thank_you_url(url) + self.assertEqual(thank_you_url, f"{url}&thank_you=true") + + def test_url_keeps_anchor(self): + base_url = self.fake.url() + url = f"{base_url}#test" + thank_you_url = mini_site_tags._generate_thank_you_url(url) + self.assertEqual(thank_you_url, f"{base_url}?thank_you=true#test") + + def test_url_keeps_query_params_and_anchor(self): + base_url = self.fake.url() + url = f"{base_url}?test=123&testa=123#test" + thank_you_url = mini_site_tags._generate_thank_you_url(url) + self.assertEqual(thank_you_url, f"{base_url}?test=123&testa=123&thank_you=true#test") From a797e0b7e29833584faad9508ac285998646a23e Mon Sep 17 00:00:00 2001 From: Daniel Miranda Date: Tue, 12 Mar 2024 15:33:25 -0700 Subject: [PATCH 002/252] updated networkapi log levels to debug (#12037) --- network-api/networkapi/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/network-api/networkapi/settings.py b/network-api/networkapi/settings.py index 5fd625a448d..ec7fae048cb 100644 --- a/network-api/networkapi/settings.py +++ b/network-api/networkapi/settings.py @@ -679,8 +679,8 @@ class DatabasesDict(TypedDict): "django.db.backends": {"handlers": ["debug-error"], "level": "ERROR"}, "django.utils.autoreload": {"handlers": ["debug-error"], "level": "ERROR"}, "networkapi": { - "handlers": ["info"], - "level": "INFO", + "handlers": ["debug"], + "level": "DEBUG", }, }, } From 4de3f5819df5ae689b0b6c78f150d8b4b5c3c664 Mon Sep 17 00:00:00 2001 From: Rob DiVincenzo Date: Wed, 13 Mar 2024 13:25:34 -0400 Subject: [PATCH 003/252] Include default msgmerge_options, adding --no-fuzzy-matching (#12019) --- network-api/networkapi/management/commands/makemessages.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network-api/networkapi/management/commands/makemessages.py b/network-api/networkapi/management/commands/makemessages.py index 56f8a9b2cc3..7fb214dcdc6 100644 --- a/network-api/networkapi/management/commands/makemessages.py +++ b/network-api/networkapi/management/commands/makemessages.py @@ -2,4 +2,4 @@ class Command(makemessages.Command): - msgmerge_options = ["--no-fuzzy-matching"] + msgmerge_options = makemessages.Command.msgmerge_options + ["--no-fuzzy-matching"] From 3913257bd1b1f1fc1a8c56f2729eb68e394782ff Mon Sep 17 00:00:00 2001 From: Rob DiVincenzo Date: Wed, 13 Mar 2024 15:11:02 -0400 Subject: [PATCH 004/252] Update donate buttons to new use link for foundation.mozilla.org (#11998) * Update donate buttons to new use link for foundation.mozilla.org * update second link in footer * Change footer donate link to ?form=donate-footer --- network-api/networkapi/templates/fragments/footer.html | 4 ++-- network-api/networkapi/templates/fragments/primary_nav.html | 2 +- .../wagtailpages/templates/maintenance/maintenance.html | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/network-api/networkapi/templates/fragments/footer.html b/network-api/networkapi/templates/fragments/footer.html index 0900379862f..21402ad67a0 100644 --- a/network-api/networkapi/templates/fragments/footer.html +++ b/network-api/networkapi/templates/fragments/footer.html @@ -11,7 +11,7 @@

{% trans "We all love the Web. Join Mozilla in defending it." %}

{% trans "Letโ€™s protect the worldโ€™s largest resource for future generations." %}

@@ -57,7 +57,7 @@