Skip to content

Commit

Permalink
Merge branch 'main' into TP1-1034-fundriseup-donations-gtm
Browse files Browse the repository at this point in the history
  • Loading branch information
dlopezvsr authored Aug 30, 2024
2 parents 7260da3 + 30e1488 commit 2d4d35b
Show file tree
Hide file tree
Showing 23 changed files with 241 additions and 139 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/continous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
env:
ALLOWED_HOSTS: localhost,mozfest.localhost,default-site.com,secondary-site.com
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NETWORK_SITE_URL: https://foundation.mozilla.org
PULSE_API_DOMAIN: https://network-pulse-api-production.herokuapp.com
PULSE_DOMAIN: https://www.mozillapulse.org
steps:
Expand Down Expand Up @@ -54,7 +53,6 @@ jobs:
DJANGO_SECRET_KEY: secret
DOMAIN_REDIRECT_MIDDLEWARE_ENABLED: False
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NETWORK_SITE_URL: http://localhost:8000
PIPENV_VERBOSITY: -1
PULSE_API_DOMAIN: https://network-pulse-api-production.herokuapp.com
PULSE_DOMAIN: https://www.mozillapulse.org
Expand Down Expand Up @@ -132,7 +130,6 @@ jobs:
DJANGO_SECRET_KEY: secret
DOMAIN_REDIRECT_MIDDLEWARE_ENABLED: False
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NETWORK_SITE_URL: http://localhost:8000
PIPENV_VERBOSITY: -1
PULSE_API_DOMAIN: https://network-pulse-api-production.herokuapp.com
PULSE_DOMAIN: https://www.mozillapulse.org
Expand All @@ -146,7 +143,7 @@ jobs:
CSP_CONNECT_SRC: "*"
CSP_FONT_SRC: "'self' https://code.cdn.mozilla.net https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/fonts/ data: https://static.fundraiseup.com/common-fonts/"
CSP_IMG_SRC: "* data: blob: https://*.fundraiseup.com https://ucarecdn.com https://pay.google.com https://*.paypalobjects.com"
CSP_FRAME_SRC: "'self' https://www.google.com/recaptcha/ https://*.stripe.com https://pay.google.com https://*.paypal.com https://*.fundraiseup.com"
CSP_FRAME_SRC: "'self' https://www.google.com/recaptcha/ https://*.stripe.com https://pay.google.com https://*.paypal.com https://*.fundraiseup.com"
CSP_SCRIPT_SRC: "'self' 'unsafe-inline' https://www.google-analytics.com/analytics.js http://*.shpg.org/ https://comments.mozillafoundation.org/ https://airtable.com https://platform.twitter.com https://cdnjs.cloudflare.com/ajax/libs/gsap/3.8.0/gsap.min.js https://cdnjs.cloudflare.com/ajax/libs/gsap/3.8.0/ScrollTrigger.min.js https://*.googletagmanager.com https://*.fundraiseup.com https://mozillafoundation.tfaforms.net https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/ 'unsafe-eval' https://*.stripe.com https://m.stripe.network https://*.paypal.com https://*.paypalobjects.com https://pay.google.com"
CSP_STYLE_SRC: "'self' 'unsafe-inline' https://code.cdn.mozilla.net https://platform.twitter.com https://mozillafoundation.tfaforms.net https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
SECURE_CROSS_ORIGIN_OPENER_POLICY: "same-origin-allow-popups"
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/visual-regression-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ jobs:
DJANGO_SECRET_KEY: secret
DOMAIN_REDIRECT_MIDDLEWARE_ENABLED: False
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NETWORK_SITE_URL: http://localhost:8000
PIPENV_VERBOSITY: -1
PULSE_API_DOMAIN: https://network-pulse-api-production.herokuapp.com
PULSE_DOMAIN: https://www.mozillapulse.org
Expand Down
3 changes: 1 addition & 2 deletions env.default
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
PULSE_API_DOMAIN=https://network-pulse-api-production.herokuapp.com
PULSE_DOMAIN=https://www.mozillapulse.org

# Always add a protocol (ex: https://) in front of the NETWORK_SITE_URL, including for localhost
NETWORK_SITE_URL=http://localhost:8000
# Always add a protocol (ex: https://) in front of the URL, including for localhost
WAGTAILADMIN_BASE_URL=http://localhost:8000
DOMAIN_REDIRECT_MIDDLEWARE_ENABLED=False
TARGET_DOMAINS=foundation.mozilla.org
Expand Down
5 changes: 0 additions & 5 deletions network-api/networkapi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
HEROKU_RELEASE_VERSION=(str, None),
INDEX_PAGE_CACHE_TIMEOUT=(int, 60 * 60 * 24),
MOZFEST_DOMAIN_REDIRECT_ENABLED=(bool, False),
NETWORK_SITE_URL=(str, ""),
PETITION_TEST_CAMPAIGN_ID=(str, ""),
PNI_STATS_DB_URL=(str, None),
PULSE_API_DOMAIN=(str, ""),
Expand Down Expand Up @@ -695,7 +694,6 @@ class DatabasesDict(TypedDict):
FRONTEND = {
"PULSE_API_DOMAIN": env("PULSE_API_DOMAIN"),
"PULSE_DOMAIN": env("PULSE_DOMAIN"),
"NETWORK_SITE_URL": env("NETWORK_SITE_URL"),
"TARGET_DOMAINS": env("TARGET_DOMAINS"),
"SENTRY_DSN": env("SENTRY_DSN"),
"RELEASE_VERSION": env("HEROKU_RELEASE_VERSION"),
Expand All @@ -718,9 +716,6 @@ class DatabasesDict(TypedDict):
# privacynotincluded statistics DB
PNI_STATS_DB_URL = env("PNI_STATS_DB_URL")

# Use network_url to check if we're running prod or not
NETWORK_SITE_URL = env("NETWORK_SITE_URL")

# Blog/Campaign index cache setting
INDEX_PAGE_CACHE_TIMEOUT = env("INDEX_PAGE_CACHE_TIMEOUT")

Expand Down
2 changes: 1 addition & 1 deletion network-api/networkapi/templates/tags/horizontal_nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% for entry in menu_pages %}
{% pageurl entry.page as entry_page_url %}
{% if entry.depth < 2 %}
<a class="multipage-link {% if current_page_url == entry_page_url %}active{% endif %} {% if entry.restriction != None %}multipage-{{ entry.restriction }}-restricted{% endif %} {% if not entry.page.live %}multipage-draft{% endif %}" href="{% pageurl entry.page %}">{{ entry.menu_title }}</a>
<a class="multipage-link {% if current_page_url == entry_page_url %}active{% endif %}" href="{% pageurl entry.page %}">{{ entry.menu_title }} {% include "tags/multipage_menu_link_note.html" with menu_entry=entry %}</a>
{% endif %}
{% endfor %}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% load i18n %}

{% with class="tw-text-red-80 tw-text-sm tw-ml-1" %}
{% comment %}These notes are internal facing only. Only logged in users can see them.{% endcomment %}

{% if menu_entry.restriction == "login" %}
<span class="{{ class }}">(logged in users only)</span>
{% elif menu_entry.restriction == "groups" %}
<span class="{{ class }}">(restricted to specific groups)</span>
{% elif menu_entry.restriction == "password" %}
<span class="{{ class }}">(password protected)</span>
{% endif %}

{% if not menu_entry.page.live %}
<span class="{{ class }}">(draft)</span>
{% endif %}

{% endwith %}
48 changes: 4 additions & 44 deletions network-api/networkapi/wagtailpages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,14 @@
import functools
from django.utils.translation import trans_real

import django
from django.utils.translation.trans_real import accept_language_re
from .override_utils import parse_accept_lang_header, to_language

# WARNING: this is not necessarily a good idea, but is the only way to override
# Django's default behaviour of requiring language codes to be lowercased.
# We have to modify the core Django method, because we have no way to replace
# all the core functionality that relies on this - e.g., url resolvers that
# the Django admin and third party apps use.
# A fix upstream has been asked in https://code.djangoproject.com/ticket/31795


def language_code_to_iso_3166(language):
"""Turn a language name (en-us) into an ISO 3166 format (en-US)."""
language, _, country = language.lower().partition("-")
if country:
return f"{language}-{country.upper()}"
return language


def to_language(locale):
"""Turn a locale name (en_US) into a language name (en-US)."""
return locale.replace("_", "-")


@functools.lru_cache(maxsize=1000)
def parse_accept_lang_header(lang_string):
"""
Parse the lang_string, which is the body of an HTTP Accept-Language
header, and return a tuple of (lang, q-value), ordered by 'q' values.
Return an empty tuple if there are any format errors in lang_string.
"""
result = []
pieces = accept_language_re.split(lang_string.lower())
if pieces[-1]:
return ()
for i in range(0, len(pieces) - 1, 3):
first, lang, priority = pieces[i : i + 3]
if first:
return ()
if priority:
priority = float(priority)
else:
priority = 1.0
result.append((language_code_to_iso_3166(lang), priority))
result.sort(key=lambda k: k[1], reverse=True)
return tuple(result)


# Replace some functions in django.utils.translation.trans_real with our own
# versions that support a language in the form en-US instead of en-us.
django.utils.translation.trans_real.to_language = to_language
django.utils.translation.trans_real.parse_accept_lang_header = parse_accept_lang_header
trans_real.to_language = to_language
trans_real.parse_accept_lang_header = parse_accept_lang_header
40 changes: 40 additions & 0 deletions network-api/networkapi/wagtailpages/override_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import functools

from django.utils.translation.trans_real import accept_language_re


def language_code_to_iso_3166(language):
"""Turn a language name (en-us) into an ISO 3166 format (en-US)."""
language, _, country = language.lower().partition("-")
if country:
return f"{language}-{country.upper()}"
return language


def to_language(locale):
"""Turn a locale name (en_US) into a language name (en-US)."""
return locale.replace("_", "-")


@functools.lru_cache(maxsize=1000)
def parse_accept_lang_header(lang_string):
"""
Parse the lang_string, which is the body of an HTTP Accept-Language
header, and return a tuple of (lang, q-value), ordered by 'q' values.
Return an empty tuple if there are any format errors in lang_string.
"""
result = []
pieces = accept_language_re.split(lang_string.lower())
if pieces[-1]:
return ()
for i in range(0, len(pieces) - 1, 3):
first, lang, priority = pieces[i : i + 3]
if first:
return ()
if priority:
priority = float(priority)
else:
priority = 1.0
result.append((language_code_to_iso_3166(lang), priority))
result.sort(key=lambda k: k[1], reverse=True)
return tuple(result)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% for entry in menu_pages %}
{% pageurl entry.page as entry_page_url %}
<div class="multipage-link-wrapper">
<a class="multipage-link {% if current_page_url == entry_page_url %}active{% endif %} {% if entry.restriction != None %}multipage-{{ entry.restriction }}-restricted{% endif %} {% if not entry.page.live %}multipage-draft{% endif %}" href="{% pageurl entry.page %}">{% if entry.depth == 2 %}→ {% endif %}{{ entry.menu_title }}
<a class="multipage-link {% if current_page_url == entry_page_url %}active{% endif %} {% if entry.restriction != None %}multipage-{{ entry.restriction }}-restricted{% endif %} {% if not entry.page.live %}multipage-draft{% endif %}" href="{% pageurl entry.page %}">{% if entry.depth == 2 %}→ {% endif %}{{ entry.menu_title }} {% include "tags/multipage_menu_link_note.html" with menu_entry=entry %}
</a>
</div>
{% endfor %}
Expand Down
10 changes: 5 additions & 5 deletions network-api/networkapi/wagtailpages/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
from wagtail.images.models import Image
from wagtail.models import Collection, Locale

from networkapi.wagtailpages import (
language_code_to_iso_3166,
parse_accept_lang_header,
to_language,
)
from networkapi.wagtailpages.factory import blog as blog_factories
from networkapi.wagtailpages.factory.blog import (
BlogIndexPageFactory,
BlogPageFactory,
FeaturedBlogPagesFactory,
)
from networkapi.wagtailpages.factory.profiles import ProfileFactory
from networkapi.wagtailpages.override_utils import (
language_code_to_iso_3166,
parse_accept_lang_header,
to_language,
)
from networkapi.wagtailpages.pagemodels.blog.blog import BlogAuthors, BlogPage
from networkapi.wagtailpages.pagemodels.profiles import Profile
from networkapi.wagtailpages.tests.base import WagtailpagesTestCase
Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"autoprefixer": "^10.4.20",
"axe-core": "^4.10.0",
"bootstrap": "^4.6.0",
"chart.js": "4.4.3",
"chart.js": "4.4.4",
"classnames": "2.5.1",
"countup.js": "^2.8.0",
"cssnano": "^6.1.2",
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ django-querystring-tag==1.0.3
# via -r requirements.in
django-redis==5.4.0
# via -r requirements.in
django-storages==1.14.3
django-storages==1.14.4
# via -r requirements.in
django-taggit==3.0.0
# via wagtail
Expand All @@ -113,7 +113,7 @@ draftjs-exporter==2.1.7
# via wagtail
et-xmlfile==1.1.0
# via openpyxl
factory-boy==3.3.0
factory-boy==3.3.1
# via
# -r requirements.in
# wagtail-factories
Expand Down Expand Up @@ -182,7 +182,7 @@ python-dateutil==2.8.2
# botocore
# faker
# heroku3
python-slugify==8.0.3
python-slugify==8.0.4
# via -r requirements.in
python3-openid==3.2.0
# via social-auth-core
Expand Down Expand Up @@ -221,7 +221,7 @@ six==1.16.0
# python-dateutil
smmap==5.0.0
# via gitdb
social-auth-app-django==5.4.1
social-auth-app-django==5.4.2
# via -r requirements.in
social-auth-core==4.4.1
# via social-auth-app-django
Expand Down Expand Up @@ -263,7 +263,7 @@ wagtail==5.2.6
# wagtail-localize-git
# wagtail-metadata
# wagtailmedia
wagtail-ab-testing==0.9
wagtail-ab-testing==0.10
# via -r requirements.in
wagtail-color-panel==1.5.0
# via -r requirements.in
Expand Down
2 changes: 1 addition & 1 deletion source/js/buyers-guide/bg-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let main = {

this.fetchEnv((envData) => {
env = envData;
networkSiteURL = env.NETWORK_SITE_URL;
networkSiteURL = window.location.origin;
if (env.SENTRY_DSN) {
// Initialize Sentry error reporting
initializeSentry(
Expand Down
Loading

0 comments on commit 2d4d35b

Please sign in to comment.