Fix #10252: Add `source_url` to newsletter management

This commit is contained in:
Rob Hudson 2023-05-10 07:05:12 -07:00 коммит произвёл Alex Gibson
Родитель 36b1353a4a
Коммит 89b3000b12
4 изменённых файлов: 12 добавлений и 4 удалений

Просмотреть файл

@ -72,6 +72,8 @@
data-recovery-url="{{ recovery_url }}" data-recovery-url="{{ recovery_url }}"
data-unsubscribe-url="{{ unsubscribe_url }}"> data-unsubscribe-url="{{ unsubscribe_url }}">
<input type="hidden" name="source_url" value="{{ source_url|absolute_url }}">
{# noscript warning to enable JavaScript #} {# noscript warning to enable JavaScript #}
<noscript> <noscript>
<div class="mzp-c-notification-bar mzp-t-error"> <div class="mzp-c-notification-bar mzp-t-error">

Просмотреть файл

@ -149,6 +149,7 @@ def existing(request, token=None):
"updated_url": reverse("newsletter.updated"), "updated_url": reverse("newsletter.updated"),
"recovery_url": reverse("newsletter.recovery"), "recovery_url": reverse("newsletter.recovery"),
"did_confirm": request.GET.get("confirm") == "1", "did_confirm": request.GET.get("confirm") == "1",
"source_url": reverse("newsletter.existing.token", kwargs={"token": ""}),
"form": form, "form": form,
} }

Просмотреть файл

@ -651,8 +651,12 @@ const NewsletterManagementForm = {
const newsletters = encodeURIComponent( const newsletters = encodeURIComponent(
NewsletterManagementForm.getCheckedNewsletters().join(',') NewsletterManagementForm.getCheckedNewsletters().join(',')
); );
// Source URL (hidden field)
const sourceUrl = encodeURIComponent(
_form.querySelector('input[name="source_url"]').value
);
return `format=${format}&country=${country}&lang=${lang}&newsletters=${newsletters}&optin=Y`; return `format=${format}&country=${country}&lang=${lang}&newsletters=${newsletters}&optin=Y&source_url=${sourceUrl}`;
}, },
/** /**

Просмотреть файл

@ -32,6 +32,7 @@ describe('management.es6.js', function () {
</div> </div>
</header> </header>
<form method="post" action="https://basket.mozilla.org/news/user/" class="newsletter-management-form" data-newsletters-url="https://basket.mozilla.org/news/newsletters/" data-strings-url="/en-US/newsletter/newsletter-strings.json" data-updated-url="/en-US/newsletter/updated/" data-recovery-url="/en-US/newsletter/recovery/" data-unsubscribe-url="https://basket.mozilla.org/news/unsubscribe/"> <form method="post" action="https://basket.mozilla.org/news/user/" class="newsletter-management-form" data-newsletters-url="https://basket.mozilla.org/news/newsletters/" data-strings-url="/en-US/newsletter/newsletter-strings.json" data-updated-url="/en-US/newsletter/updated/" data-recovery-url="/en-US/newsletter/recovery/" data-unsubscribe-url="https://basket.mozilla.org/news/unsubscribe/">
<input type="hidden" name="source_url" value="https://www.mozilla.org/en-US/newsletter/existing/">
<div class="loading-spinner hidden"></div> <div class="loading-spinner hidden"></div>
<div class="mzp-c-form-errors hidden"> <div class="mzp-c-form-errors hidden">
<ul class="mzp-u-list-styled"></ul> <ul class="mzp-u-list-styled"></ul>
@ -1003,7 +1004,7 @@ describe('management.es6.js', function () {
`https://basket.mozilla.org/news/user/${TOKEN_MOCK}/` `https://basket.mozilla.org/news/user/${TOKEN_MOCK}/`
); );
expect(xhrRequests[0].requestBody).toEqual( expect(xhrRequests[0].requestBody).toEqual(
'format=H&country=us&lang=en&newsletters=mozilla-and-you%2Cmozilla-foundation%2Cabout-mozilla&optin=Y' 'format=H&country=us&lang=en&newsletters=mozilla-and-you%2Cmozilla-foundation%2Cabout-mozilla&optin=Y&source_url=https%3A%2F%2Fwww.mozilla.org%2Fen-US%2Fnewsletter%2Fexisting%2F'
); );
xhrRequests[0].respond( xhrRequests[0].respond(
200, 200,
@ -1024,7 +1025,7 @@ describe('management.es6.js', function () {
document.querySelector('button[type="submit"]').click(); document.querySelector('button[type="submit"]').click();
expect(xhrRequests[0].requestBody).toEqual( expect(xhrRequests[0].requestBody).toEqual(
'format=H&country=us&lang=en&newsletters=mozilla-and-you%2Cmozilla-foundation%2Ccommon-voice%2Cabout-mozilla&optin=Y' 'format=H&country=us&lang=en&newsletters=mozilla-and-you%2Cmozilla-foundation%2Ccommon-voice%2Cabout-mozilla&optin=Y&source_url=https%3A%2F%2Fwww.mozilla.org%2Fen-US%2Fnewsletter%2Fexisting%2F'
); );
xhrRequests[0].respond( xhrRequests[0].respond(
200, 200,
@ -1047,7 +1048,7 @@ describe('management.es6.js', function () {
document.querySelector('button[type="submit"]').click(); document.querySelector('button[type="submit"]').click();
expect(xhrRequests[0].requestBody).toEqual( expect(xhrRequests[0].requestBody).toEqual(
'format=H&country=us&lang=en&newsletters=mozilla-foundation%2Cabout-mozilla&optin=Y' 'format=H&country=us&lang=en&newsletters=mozilla-foundation%2Cabout-mozilla&optin=Y&source_url=https%3A%2F%2Fwww.mozilla.org%2Fen-US%2Fnewsletter%2Fexisting%2F'
); );
xhrRequests[0].respond( xhrRequests[0].respond(
200, 200,