Skip to content

Commit

Permalink
Data consent updates and privacy improvements (Fixes #14213)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgibson committed May 10, 2024
1 parent 59019ba commit f4e7e09
Show file tree
Hide file tree
Showing 70 changed files with 2,425 additions and 953 deletions.
22 changes: 20 additions & 2 deletions bedrock/base/templates/base-protocol.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<!doctype html>
{# Note the "windows" class, without javascript platform-specific assets default to windows #}
<html class="windows no-js" lang="{{ LANG|replace('en-US', 'en') }}" dir="{{ DIR }}" data-country-code="{{ country_code }}" data-latest-firefox="{{ latest_firefox_version }}" data-esr-versions="{{ esr_firefox_versions|join(' ') }}" {% if settings.GTM_CONTAINER_ID %}data-gtm-container-id="{{ settings.GTM_CONTAINER_ID }}"{% endif %} {% block gtm_page_id %}{% endblock %} {% if settings.STUB_ATTRIBUTION_RATE %}data-stub-attribution-rate="{{ settings.STUB_ATTRIBUTION_RATE }}"{% endif %} {% if settings.SENTRY_FRONTEND_DSN %}data-sentry-dsn="{{ settings.SENTRY_FRONTEND_DSN }}"{% endif %} {% block html_attrs %}{% endblock %}>
<html class="windows no-js" lang="{{ LANG|replace('en-US', 'en') }}" dir="{{ DIR }}" data-country-code="{{ country_code }}" data-needs-consent="{{ needs_data_consent(country_code) }}" data-latest-firefox="{{ latest_firefox_version }}" data-esr-versions="{{ esr_firefox_versions|join(' ') }}" {% if settings.GTM_CONTAINER_ID %}data-gtm-container-id="{{ settings.GTM_CONTAINER_ID }}"{% endif %} {% block gtm_page_id %}{% endblock %} {% if settings.STUB_ATTRIBUTION_RATE %}data-stub-attribution-rate="{{ settings.STUB_ATTRIBUTION_RATE }}"{% endif %} {% if settings.SENTRY_FRONTEND_DSN %}data-sentry-dsn="{{ settings.SENTRY_FRONTEND_DSN }}"{% endif %} {% block html_attrs %}{% endblock %}>
<head>
<meta charset="utf-8">{# Note: Must be within first 512 bytes of page #}

Expand All @@ -16,6 +16,10 @@
{% block experiments %}{% endblock %}
<!--<![endif]-->

<!--[if IE 9]>
{{ js_bundle('site-ie') }}
<![endif]-->

<!--
{% include "includes/careers-teaser.html" %}
-->
Expand Down Expand Up @@ -92,6 +96,10 @@
data-global-previous="{{ ftl('ui-previous') }}"
{% block string_data %}{% endblock %}></div>

{% block consent_banner %}
{% include 'includes/banners/consent-banner.html' %}
{% endblock %}

{% block site_header %}
{% include 'includes/protocol/navigation/navigation.html' %}
{% endblock %}
Expand Down Expand Up @@ -125,6 +133,10 @@
{{ js_bundle('fxa') }}
{{ js_bundle('data') }}
<!--<![endif]-->

<!--[if IE 9]>
{{ js_bundle('lib-ie') }}
<![endif]-->
{% endblock %}

{# Bug 1279291 #}
Expand All @@ -134,7 +146,7 @@
{{ js_bundle('stub-attribution') }}
<!--<![endif]-->

<!--[if gte IE 8]>
<!--[if IE 9]>
{{ js_bundle('stub-attribution-ie') }}
<![endif]-->
{% endif %}
Expand All @@ -151,5 +163,11 @@

{% block third_party_js %}{% endblock %}
<!--<![endif]-->

{% block consent_banner_js %}
<!--[if IE 9]> -->
{{ js_bundle('consent-banner') }}
<!-- <![endif]-->
{% endblock %}
</body>
</html>
25 changes: 0 additions & 25 deletions bedrock/base/templates/includes/affiliate-banner.html

This file was deleted.

25 changes: 25 additions & 0 deletions bedrock/base/templates/includes/banners/consent-banner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{#
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/.
#}

<aside class="moz-consent-banner" id="moz-consent-banner" role="region" aria-label="{{ ftl('consent-banner-aria-label') }}" data-nosnippet="true">
<div class="moz-consent-banner-content">
<h2 class="moz-consent-banner-heading">{{ ftl('consent-banner-heading') }}</h2>
<div class="moz-consent-banner-copy">
<p>{{ ftl('consent-banner-body') }}</p>
<div class="moz-consent-banner-controls">
<button type="button" id="moz-consent-banner-button-reject" class="moz-consent-banner-button moz-consent-banner-button-reject">
{{ ftl('consent-banner-button-reject') }}
</button>
<button type="button" id="moz-consent-banner-button-accept" class="moz-consent-banner-button moz-consent-banner-button-accept">
{{ ftl('consent-banner-button-accept') }}
</button>
<a href="{{ url('privacy.cookie-settings')}}">
{{ ftl('consent-banner-settings-link') }}
</a>
</div>
</div>
</div>
</aside>
4 changes: 2 additions & 2 deletions bedrock/base/templates/includes/google-analytics.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
{{ js_bundle('gtm-snippet') }}
<!--<![endif]-->

<!--[if IE]>
<script src="{{ static('js/ie/gtm-snippet.js') }}"></script>
<!--[if IE 9]>
{{ js_bundle('gtm-snippet-ie') }}
<![endif]-->
{% endif %}
<!-- End Google Tag Manager -->
5 changes: 4 additions & 1 deletion bedrock/base/templates/includes/protocol/footer/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ <h5 class="mzp-c-footer-heading-social">{{ ftl('footer-follow-firefox') }}</h5>
<div class="mzp-c-footer-legal">
<ul class="mzp-c-footer-terms">
<li><a href="{{ url('privacy.notices.websites') }}" data-link-type="footer" data-link-text="Privacy">{{ ftl('footer-websites-privacy-notice') }}</a></li>
<li><a href="{{ url('privacy.notices.websites') }}#user-choices" data-link-type="footer" data-link-text="Cookies">{{ ftl('footer-websites-cookies') }}</a></li>
<li>
{# Link to /privacy/websites/cookie-settings/ is a legal requirement and should not be removed. It must be present on every page (Issue 14213). #}
<a href="{{ url('privacy.cookie-settings') }}" data-link-type="footer" data-link-text="Cookies">{{ ftl('footer-websites-cookies') }}</a>
</li>
<li><a href="{{ url('legal.index') }}" data-link-type="footer" data-link-text="Legal">{{ ftl('footer-websites-legal') }}</a></li>
<li><a href="{{ url('mozorg.about.governance.policies.participation') }}" data-link-type="footer" data-link-text="Community Participation Guidelines">{{ ftl('footer-community-participation-guidelines') }}</a></li>
{% if ftl_has_messages('footer-about-this-site') %}
Expand Down
1 change: 1 addition & 0 deletions bedrock/mozorg/nonlocale_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
page("credits/faq/", "mozorg/credits-faq.html"),
path("robots.txt", views.Robots.as_view(), name="robots.txt"),
path(".well-known/security.txt", views.SecurityDotTxt.as_view(), name="security.txt"),
path(".well-known/gpc.json", views.GpcDotJson.as_view(), name="gpc.json"),
# namespaces
path("2004/em-rdf", views.namespaces, {"namespace": "em-rdf"}),
path("2005/app-update", views.namespaces, {"namespace": "update"}),
Expand Down
4 changes: 4 additions & 0 deletions bedrock/mozorg/templates/mozorg/gpc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"gpc": true,
"lastUpdate": "2024-03-26"
}
1 change: 1 addition & 0 deletions bedrock/mozorg/templates/mozorg/robots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ disallow: /*/firstrun/
disallow: /*/newsletter/existing/
disallow: /*/whatsnew/
disallow: /*/etc/
disallow: /*/privacy/websites/cookie-settings/
{% endif -%}
Sitemap: {{ request.scheme }}://{{ request.get_host() }}/sitemap.xml
10 changes: 10 additions & 0 deletions bedrock/mozorg/templatetags/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
ALL_FX_PLATFORMS = ("windows", "linux", "mac", "android", "ios")


@library.global_function
def needs_data_consent(country_code):
"""
Global helper that can be passed a country_code via a template
in order to determine if cookie consent banner should be shown.
"""
country_list = settings.DATA_CONSENT_COUNTRIES
return country_code in country_list


def _strip_img_prefix(url):
return re.sub(r"^/?img/", "", url)

Expand Down
44 changes: 44 additions & 0 deletions bedrock/mozorg/tests/test_helper_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,3 +1180,47 @@ def test_fxa_button_email(self):
'&utm_source=mozilla.org-firefox-whatsnew73&utm_medium=referral&utm_campaign=whatsnew73"'
)
self.assertEqual(markup, expected)


@pytest.mark.parametrize(
"country_code, expected",
[
("AT", "True"), # Austria
("BE", "True"), # Belgium
("BG", "True"), # Bulgaria
("HR", "True"), # Croatia
("CY", "True"), # Republic of Cyprus
("CZ", "True"), # Czech Republic
("DK", "True"), # Denmark
("EE", "True"), # Estonia
("FI", "True"), # Finland
("FR", "True"), # France
("DE", "True"), # Germany
("GR", "True"), # Greece
("HU", "True"), # Hungary
("IE", "True"), # Ireland
("IS", "True"), # Iceland
("IT", "True"), # Italy
("LV", "True"), # Latvia
("LI", "True"), # Liechtenstein
("LT", "True"), # Lithuania
("LU", "True"), # Luxembourg
("MT", "True"), # Malta
("NL", "True"), # Netherlands
("NO", "True"), # Norway
("PL", "True"), # Poland
("PT", "True"), # Portugal
("RO", "True"), # Romania
("SK", "True"), # Slovakia
("SI", "True"), # Slovenia
("ES", "True"), # Spain
("SE", "True"), # Sweden
("CH", "True"), # Switzerland
("GB", "True"), # United Kingdom
("US", "False"), # United States
("CA", "False"), # Canada
],
)
def test_needs_data_consent(country_code, expected):
template = "{{ needs_data_consent('%s') }}" % country_code
assert render(template) == expected
7 changes: 7 additions & 0 deletions bedrock/mozorg/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ class SecurityDotTxt(RequireSafeMixin, TemplateView):
content_type = "text/plain"


class GpcDotJson(RequireSafeMixin, TemplateView):
# https://github.com/mozilla/bedrock/issues/14213
# served under .well-known/gpc.json
template_name = "mozorg/gpc.json"
content_type = "application/json"


NAMESPACES = {
"addons-bl": {
"namespace": "http://www.mozilla.org/2006/addons-blocklist",
Expand Down
Loading

0 comments on commit f4e7e09

Please sign in to comment.