Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Generate whole url on the backend

TOMEK80dd2b8a845c
diff --git a/saleor/account/emails.py b/saleor/account/emails.py
index ada50ab9c1..dc7c893576 100644
--- a/saleor/account/emails.py
+++ b/saleor/account/emails.py
@@ -1,6 +1,7 @@
from celery import shared_task
from django.conf import settings
from django.contrib.sites.models import Site
+from django.templatetags.static import static
from django.urls import reverse
from templated_email import send_templated_mail
@@ -12,8 +13,13 @@ def send_password_reset_email(context, recipient):
reset_url = build_absolute_uri(
reverse(
'account:reset-password-confirm',
- kwargs={'uidb64': context['uid'], 'token': context['token']}))
+ kwargs={
+ 'uidb64': context['uid'],
+ 'token': context['token']}))
+ logo_url = build_absolute_uri(
+ location=None) + static('images/logo-document.svg')
context['reset_url'] = reset_url
+ context['logo_url'] = logo_url
send_templated_mail(
template_name='account/password_reset',
from_email=settings.DEFAULT_FROM_EMAIL,
@@ -24,12 +30,14 @@ def send_password_reset_email(context, recipient):
@shared_task
def send_account_delete_confirmation_email(token, recipient_email):
site = Site.objects.get_current()
- absolute_url = build_absolute_uri(location=None)
+ logo_url = build_absolute_uri(
+ location=None) + static('images/logo-document.svg')
delete_url = build_absolute_uri(
reverse('account:delete-confirm', kwargs={'token': token}))
ctx = {
'site_name': site.name,
- 'absolute_url': absolute_url,
+ 'domain': site.domain,
+ 'logo_url': logo_url,
'url': delete_url}
send_templated_mail(
template_name='account/account_delete',
diff --git a/saleor/dashboard/emails.py b/saleor/dashboard/emails.py
index 752d19a650..fa3cc32403 100644
--- a/saleor/dashboard/emails.py
+++ b/saleor/dashboard/emails.py
@@ -2,6 +2,7 @@ from celery import shared_task
from django.conf import settings
from django.contrib.auth.tokens import default_token_generator
from django.contrib.sites.models import Site
+from django.templatetags.static import static
from django.urls import reverse
from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode
@@ -13,12 +14,19 @@ from ..core.utils import build_absolute_uri
@shared_task
def send_set_password_email(staff):
site = Site.objects.get_current()
- absolute_url = build_absolute_uri(location=None)
+ uid = urlsafe_base64_encode(force_bytes(staff.pk)).decode()
+ token = default_token_generator.make_token(staff)
+ logo_url = build_absolute_uri(
+ location=None) + static('images/logo-document.svg')
+ password_set_url = build_absolute_uri(
+ reverse(
+ 'account:reset-password-confirm',
+ kwargs={'token': token, 'uidb64': uid}))
ctx = {
- 'absolute_url': absolute_url,
+ 'password_set_url': password_set_url,
'site_name': site.name,
- 'uid': urlsafe_base64_encode(force_bytes(staff.pk)).decode(),
- 'token': default_token_generator.make_token(staff)}
+ 'domain': site.domain,
+ 'logo_url': logo_url}
send_templated_mail(
template_name='dashboard/staff/set_password',
from_email=settings.DEFAULT_FROM_EMAIL,
@@ -29,9 +37,11 @@ def send_set_password_email(staff):
@shared_task
def send_promote_customer_to_staff_email(staff):
site = Site.objects.get_current()
- absolute_url = build_absolute_uri(location=None)
+ logo_url = build_absolute_uri(
+ location=None) + static('images/logo-document.svg')
ctx = {
- 'absolute_url': absolute_url,
+ 'logo_url': logo_url,
+ 'domain': site.domain,
'url': build_absolute_uri(reverse('dashboard:index')),
'site_name': site.name}
send_templated_mail(
diff --git a/saleor/order/emails.py b/saleor/order/emails.py
index 44aa2ac0c9..9e18ef0752 100644
--- a/saleor/order/emails.py
+++ b/saleor/order/emails.py
@@ -1,6 +1,7 @@
from celery import shared_task
from django.conf import settings
from django.contrib.sites.models import Site
+from django.templatetags.static import static
from django.urls import reverse
from templated_email import send_templated_mail
@@ -18,13 +19,11 @@ CONFIRM_NOTE_TEMPLATE = 'order/note/confirm_note'
def get_email_context(order_token):
"""Prepares context required for email template rendering."""
site = Site.objects.get_current()
- absolute_url = build_absolute_uri(location=None)
+ logo_url = build_absolute_uri(
+ location=None) + static('images/logo-document.svg')
order_url = build_absolute_uri(
reverse('order:details', kwargs={'token': order_token}))
- ctx = {
- 'site_name': site.name,
- 'absolute_url': absolute_url,
- 'url': order_url}
+ ctx = {'site_name': site.name, 'logo_url': logo_url, 'url': order_url}
return ctx
diff --git a/templates/templated_email/account/account_delete.email b/templates/templated_email/account/account_delete.email
index f94a07e231..aa640ac19c 100644
--- a/templates/templated_email/account/account_delete.email
+++ b/templates/templated_email/account/account_delete.email
@@ -8,7 +8,7 @@
{% blocktrans context "Account delete reset e-mail text" %}
Hi!
-You're receiving this e-mail because you or someone else has requested a deletion of your user account at {{ absolute_url }}.
+You're receiving this e-mail because you or someone else has requested a deletion of your user account at {{ domain }}.
Click the link below to delete your account.
Please note that this action is permanent and cannot be reversed.
diff --git a/templates/templated_email/account/password_reset.email b/templates/templated_email/account/password_reset.email
index 0129f03ac3..10ae382451 100644
--- a/templates/templated_email/account/password_reset.email
+++ b/templates/templated_email/account/password_reset.email
@@ -8,11 +8,11 @@
{% blocktrans context "Password reset e-mail text" %}
Hi!
-You're receiving this e-mail because you or someone else has requested a password for your user account at {{ absolute_url }}.
+You're receiving this e-mail because you or someone else has requested a password for your user account at {{ domain }}.
It can be safely ignored if you did not request a password reset. Click the link below to reset your password.
{% endblocktrans %}
-{{ absolute_url }}{% url 'account:reset-password-confirm' uidb64=uid token=token %}
+{{ reset_url }}
This is an automatically generated email, please do not reply.
diff --git a/templates/templated_email/dashboard/staff/set_password.email b/templates/templated_email/dashboard/staff/set_password.email
index bde114e30f..511117b0a2 100644
--- a/templates/templated_email/dashboard/staff/set_password.email
+++ b/templates/templated_email/dashboard/staff/set_password.email
@@ -5,11 +5,11 @@
{% blocktrans context "Set password for staff member e-mail text" %}
Hi!
-You're receiving this e-mail because you have to set password for your staff member account at {{ absolute_url }}.
+You're receiving this e-mail because you have to set password for your staff member account at {{ domain }}.
Click the link below to reset your password.
{% endblocktrans %}
-{{ absolute_url }}{% url 'account:reset-password-confirm' uidb64=uid token=token %}
+{{ password_set_url }}
{% blocktrans context "Set password for staff member e-mail text" %}
This is an automatically generated email, please do not reply.
diff --git a/templates/templated_email/source/password_reset.mjml b/templates/templated_email/source/password_reset.mjml
index 7c30067814..eada7608bb 100644
--- a/templates/templated_email/source/password_reset.mjml
+++ b/templates/templated_email/source/password_reset.mjml
@@ -14,13 +14,13 @@
</mj-text>
<mj-text>
{% blocktrans trimmed context "Password reset e-mail text" %}
- You're receiving this e-mail because you or someone else has requested a password for your user account at {{ absolute_url }}.<br/>
+ You're receiving this e-mail because you or someone else has requested a password for your user account at {{ domain }}.<br/>
It can be safely ignored if you did not request a password reset. Click the link below to reset your password.
{% endblocktrans %}
</mj-text>
<mj-text>
- <a href="{{ absolute_url }}{% url 'account:reset-password-confirm' uidb64=uid token=token %}">
- {{ absolute_url }}{% url 'account:reset-password-confirm' uidb64=uid token=token %}
+ <a href="{{ reset_url }}">
+ {{ reset_url }}
</a>
</mj-text>
</mj-column>
diff --git a/templates/templated_email/source/promote_customer.mjml b/templates/templated_email/source/promote_customer.mjml
index 05c8ea2b33..b6eb8bc37b 100644
--- a/templates/templated_email/source/promote_customer.mjml
+++ b/templates/templated_email/source/promote_customer.mjml
@@ -14,7 +14,7 @@
</mj-text>
<mj-text>
{% blocktrans trimmed context "Promote customer to staff member confirmation e-mail text" %}
- You're receiving this e-mail because you have been promoted to staff member at {{ absolute_url }}.<br/>
+ You're receiving this e-mail because you have been promoted to staff member at {{ domain }}.<br/>
To access dashboard please visit: <a href="{{ url }}">{{ url }}</a>
{% endblocktrans %}
</mj-text>
diff --git a/templates/templated_email/source/set_password.mjml b/templates/templated_email/source/set_password.mjml
index fae820f105..59483edad1 100644
--- a/templates/templated_email/source/set_password.mjml
+++ b/templates/templated_email/source/set_password.mjml
@@ -14,13 +14,13 @@
</mj-text>
<mj-text>
{% blocktrans trimmed context "Set password for staff member e-mail text" %}
- You're receiving this e-mail because you have to set password for your staff member account at {{ absolute_url }}.<br/>
+ You're receiving this e-mail because you have to set password for your staff member account at {{ domain }}.<br/>
Click the link below to set up your password.
{% endblocktrans %}
</mj-text>
<mj-text>
- <a href="{{ absolute_url }}{% url 'account:reset-password-confirm' uidb64=uid token=token %}">
- {{ absolute_url }}{% url 'account:reset-password-confirm' uidb64=uid token=token %}
+ <a href="{{ password_set_url }}">
+ {{ password_set_url }}
</a>
</mj-text>
</mj-column>
diff --git a/templates/templated_email/source/shared/header.mjml b/templates/templated_email/source/shared/header.mjml
index 57bfd37c55..916a579ec4 100644
--- a/templates/templated_email/source/shared/header.mjml
+++ b/templates/templated_email/source/shared/header.mjml
@@ -3,6 +3,6 @@
</mj-raw>
<mj-section>
<mj-column>
- <mj-image src="{{ absolute_url }}{% static 'images/logo-document.svg' %}" height="38px" width="176px"/>
+ <mj-image src="{{ logo_url }}" height="38px" width="176px"/>
</mj-column>
</mj-section>
diff --git a/tests/dashboard/test_staff.py b/tests/dashboard/test_staff.py
index 98d7a7c571..56a9e932ed 100644
--- a/tests/dashboard/test_staff.py
+++ b/tests/dashboard/test_staff.py
@@ -1,5 +1,6 @@
from django.contrib.auth.tokens import default_token_generator
from django.core import mail
+from django.templatetags.static import static
from django.urls import reverse
from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode
@@ -97,12 +98,18 @@ def test_staff_create_email_with_set_link_password(admin_client):
def test_send_set_password_email(staff_user, site_settings):
site = site_settings.site
- absolute_url = build_absolute_uri(location=None)
+ uid = urlsafe_base64_encode(force_bytes(staff_user.pk)).decode()
+ token = default_token_generator.make_token(staff_user)
+ logo_url = build_absolute_uri(
+ location=None) + static('images/logo-document.svg')
+ password_set_url = build_absolute_uri(
+ reverse(
+ 'account:reset-password-confirm',
+ kwargs={'token': token, 'uidb64': uid}))
ctx = {
- 'absolute_url': absolute_url,
- 'site_name': site.name,
- 'uid': urlsafe_base64_encode(force_bytes(staff_user.pk)).decode(),
- 'token': default_token_generator.make_token(staff_user)}
+ 'logo_url': logo_url,
+ 'password_set_url': password_set_url,
+ 'site_name': site.name}
send_templated_mail(
template_name='dashboard/staff/set_password',
from_email=DEFAULT_FROM_EMAIL,
@@ -112,8 +119,8 @@ def test_send_set_password_email(staff_user, site_settings):
generated_link = reverse(
'account:reset-password-confirm',
kwargs={
- 'uidb64': ctx['uid'],
- 'token': ctx['token']})
+ 'uidb64': uid,
+ 'token': token})
absolute_generated_link = build_absolute_uri(generated_link)
sended_message = mail.outbox[0].body
assert absolute_generated_link in sended_message
diff --git a/tests/test_emails.py b/tests/test_emails.py
index 6c7d14b2e6..d6a4ce039f 100644
--- a/tests/test_emails.py
+++ b/tests/test_emails.py
@@ -2,6 +2,7 @@ from unittest import mock
import pytest
from django.conf import settings
+from django.templatetags.static import static
from django.urls import reverse
from templated_email import get_connection
@@ -11,12 +12,13 @@ from saleor.core.utils import build_absolute_uri
def test_get_email_context(order, site_settings):
site = site_settings.site
- absolute_url = build_absolute_uri(location=None)
+ logo_url = build_absolute_uri(
+ location=None) + static('images/logo-document.svg')
order_url = build_absolute_uri(
reverse('order:details', kwargs={'token': order.token}))
proper_context = {
'site_name': site.name,
- 'absolute_url': absolute_url,
+ 'logo_url': logo_url,
'url': order_url}
received_context = emails.get_email_context(order.token)