forked from mozilla/pontoon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create email consent page (mozilla#3231)
- Adds Email consent screen as per the spec for existing and new users. - Prevent random test failures
- Loading branch information
Showing
17 changed files
with
361 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
pontoon/base/migrations/0062_userprofile_email_consent_dismissed_at.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.11 on 2024-05-15 16:42 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("base", "0061_userprofile_email_communications_enabled"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="userprofile", | ||
name="email_consent_dismissed_at", | ||
field=models.DateTimeField(blank=True, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pytest | ||
|
||
from django.urls import reverse | ||
from django.utils import timezone | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_EmailConsentMiddleware(client, member, settings): | ||
# By default, Email consent page is disabled | ||
response = member.client.get("/") | ||
assert response.status_code == 200 | ||
|
||
# If Email consent page is enabled, redirect any view to it | ||
settings.EMAIL_CONSENT_ENABLED = True | ||
response = member.client.get("/") | ||
assert response.status_code == 302 | ||
|
||
# Unless that view is the Email consent page itself | ||
response = member.client.get(reverse("pontoon.messaging.email_consent")) | ||
assert response.status_code == 200 | ||
|
||
# Or the request is AJAX | ||
response = member.client.get("/", headers={"x-requested-with": "XMLHttpRequest"}) | ||
assert response.status_code == 200 | ||
|
||
# Or the user has already dismissed the Email consent | ||
profile = member.user.profile | ||
profile.email_consent_dismissed_at = timezone.now() | ||
profile.save() | ||
response = member.client.get("/") | ||
assert response.status_code == 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
body > header { | ||
background: transparent; | ||
border-color: transparent; | ||
position: fixed; | ||
width: 100%; | ||
z-index: 10; | ||
} | ||
|
||
body > header.menu-opened { | ||
border-color: var(--main-border-1); | ||
} | ||
|
||
#main section { | ||
display: flex; | ||
flex-direction: column; | ||
height: 100vh; | ||
|
||
background-image: var(--homepage-background-image); | ||
background-attachment: fixed; | ||
background-size: cover; | ||
} | ||
|
||
#main section .container { | ||
display: flex; | ||
flex: 1; | ||
flex-direction: column; | ||
align-items: start; | ||
justify-content: center; | ||
overflow: hidden; | ||
} | ||
|
||
#main .buttons { | ||
display: flex; | ||
margin-bottom: 10px; | ||
} | ||
|
||
#main .buttons button { | ||
background: transparent; | ||
border: none; | ||
border-radius: 2px; | ||
box-sizing: content-box; | ||
color: var(--white-1); | ||
display: flex; | ||
font-size: 16px; | ||
width: 120px; | ||
height: 40px; | ||
padding: 4px; | ||
justify-content: center; | ||
align-items: center; | ||
font-weight: 400; | ||
} | ||
|
||
#main .buttons button.enable { | ||
background-color: var(--status-translated); | ||
color: var(--homepage-tour-button-color); | ||
width: 320px; | ||
} | ||
|
||
#main h1 { | ||
font-size: 64px; | ||
margin-bottom: 10px; | ||
} | ||
|
||
#main p { | ||
font-size: 22px; | ||
font-weight: 300; | ||
line-height: 36px; | ||
margin-bottom: 60px; | ||
width: 900px; | ||
} | ||
|
||
#main p.privacy-notice { | ||
font-size: 14px; | ||
} | ||
|
||
#main p.privacy-notice a { | ||
color: var(--status-translated); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
$(function () { | ||
$('.buttons button').click(function (e) { | ||
e.preventDefault(); | ||
const self = $(this); | ||
|
||
$.ajax({ | ||
url: '/dismiss-email-consent/', | ||
type: 'POST', | ||
data: { | ||
csrfmiddlewaretoken: $('body').data('csrf'), | ||
value: self.is('.enable'), | ||
}, | ||
success: function (data) { | ||
window.location.href = data.next; | ||
}, | ||
error: function (request) { | ||
if (request.responseText === 'error') { | ||
Pontoon.endLoader('Oops, something went wrong.', 'error'); | ||
} else { | ||
Pontoon.endLoader(request.responseText, 'error'); | ||
} | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{% extends 'base.html' %} | ||
|
||
{% block title %}Email consent{% endblock %} | ||
|
||
{% block class %}email-consent{% endblock %} | ||
|
||
{% block middle %} | ||
<section id="main"> | ||
<section> | ||
<div class="container"> | ||
<h1>{{ settings.EMAIL_CONSENT_TITLE }}</h1> | ||
<p class="main-text">{{ settings.EMAIL_CONSENT_MAIN_TEXT|safe }}</p> | ||
<div class="buttons"> | ||
<button class="enable">Enable email communications</button> | ||
<button class="disable">No, thanks</button> | ||
</div> | ||
<p class="privacy-notice">{{ settings.EMAIL_CONSENT_PRIVACY_NOTICE|safe }}</p> | ||
</div> | ||
</section> | ||
</section> | ||
{% endblock %} | ||
|
||
{% block extend_css %} | ||
{% stylesheet 'email_consent' %} | ||
{% endblock %} | ||
|
||
{% block extend_js %} | ||
{% javascript 'email_consent' %} | ||
{% endblock %} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pytest | ||
|
||
from pontoon.base.models import User | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_dismiss_email_consent(member): | ||
"""Test if dismiss_email_consent view works and fails as expected.""" | ||
params = {} | ||
response = member.client.post(f"/dismiss-email-consent/", params) | ||
assert response.status_code == 400 | ||
assert response.json()["message"] == "Bad Request: Value not set" | ||
|
||
params = { | ||
"value": "false", | ||
} | ||
response = member.client.post(f"/dismiss-email-consent/", params) | ||
profile = User.objects.get(pk=member.user.pk).profile | ||
assert profile.email_communications_enabled is False | ||
assert profile.email_consent_dismissed_at is not None | ||
assert response.status_code == 200 | ||
assert response.json()["next"] == "/" | ||
|
||
params = { | ||
"value": "true", | ||
} | ||
response = member.client.post(f"/dismiss-email-consent/", params) | ||
profile = User.objects.get(pk=member.user.pk).profile | ||
assert profile.email_communications_enabled is True | ||
assert profile.email_consent_dismissed_at is not None | ||
assert response.status_code == 200 | ||
assert response.json()["next"] == "/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.urls import path | ||
|
||
from . import views | ||
|
||
urlpatterns = [ | ||
# Email consent | ||
path( | ||
"email-consent/", | ||
views.email_consent, | ||
name="pontoon.messaging.email_consent", | ||
), | ||
path( | ||
"dismiss-email-consent/", | ||
views.dismiss_email_consent, | ||
name="pontoon.messaging.dismiss_email_consent", | ||
), | ||
] |
Oops, something went wrong.