Fix #806: Use proper site name/domain in emails

merge-requests/757/head
Eliot Berriot 2019-04-23 11:14:58 +02:00
rodzic 71b7f416cc
commit 39485c8e02
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: DD6965E2476E5C27
6 zmienionych plików z 48 dodań i 10 usunięć

Wyświetl plik

@ -1,8 +1,8 @@
{% load account %}{% user_display user as user_display %}{% load i18n %}{% autoescape off %}{% blocktrans with site_name=current_site.name site_domain=current_site.domain %}Hello from {{ site_name }}! {% load account %}{% user_display user as user_display %}{% load i18n %}{% autoescape off %}{% blocktrans with site_name=funkwhale_site_name site_domain=funkwhale_site_domain %}Hello from {{ site_name }}!
You're receiving this e-mail because user {{ user_display }} at {{ site_domain }} has given yours as an e-mail address to connect their account. You're receiving this e-mail because user {{ user_display }} at {{ site_domain }} has given yours as an e-mail address to connect their account.
To confirm this is correct, go to {{ funkwhale_url }}/auth/email/confirm?key={{ key }} To confirm this is correct, go to {{ funkwhale_url }}/auth/email/confirm?key={{ key }}
{% endblocktrans %}{% endautoescape %} {% endblocktrans %}{% endautoescape %}
{% blocktrans with site_name=current_site.name site_domain=current_site.domain %}Thank you from {{ site_name }}! {% blocktrans with site_name=funkwhale_site_name site_domain=funkwhale_site_domain %}Thank you from {{ site_name }}!
{{ site_domain }}{% endblocktrans %} {{ site_domain }}{% endblocktrans %}

Wyświetl plik

@ -1,5 +1,5 @@
{% load i18n %}{% autoescape off %} {% load i18n %}{% autoescape off %}
{% blocktrans %}You're receiving this email because you requested a password reset for your user account at {{ site_name }}.{% endblocktrans %} {% blocktrans with site_name=funkwhale_site_name %}You're receiving this email because you requested a password reset for your user account at {{ site_name }}.{% endblocktrans %}
{% trans "Please go to the following page and choose a new password:" %} {% trans "Please go to the following page and choose a new password:" %}
{{ funkwhale_url }}/auth/password/reset/confirm?uid={{ uid }}&token={{ token }} {{ funkwhale_url }}/auth/password/reset/confirm?uid={{ uid }}&token={{ token }}
@ -7,6 +7,6 @@
{% trans "Thanks for using our site!" %} {% trans "Thanks for using our site!" %}
{% blocktrans %}The {{ site_name }} team{% endblocktrans %} {% blocktrans with site_name=funkwhale_site_name %}The {{ site_name }} team{% endblocktrans %}
{% endautoescape %} {% endautoescape %}

Wyświetl plik

@ -3,11 +3,22 @@ from django.conf import settings
from dynamic_preferences.registries import global_preferences_registry from dynamic_preferences.registries import global_preferences_registry
def get_email_context():
context = {}
context["funkwhale_url"] = settings.FUNKWHALE_URL
manager = global_preferences_registry.manager()
context["funkwhale_site_name"] = (
manager["instance__name"] or settings.FUNKWHALE_HOSTNAME
)
context["funkwhale_site_domain"] = settings.FUNKWHALE_HOSTNAME
return context
class FunkwhaleAccountAdapter(DefaultAccountAdapter): class FunkwhaleAccountAdapter(DefaultAccountAdapter):
def is_open_for_signup(self, request): def is_open_for_signup(self, request):
manager = global_preferences_registry.manager() manager = global_preferences_registry.manager()
return manager["users__registration_enabled"] return manager["users__registration_enabled"]
def send_mail(self, template_prefix, email, context): def send_mail(self, template_prefix, email, context):
context["funkwhale_url"] = settings.FUNKWHALE_URL context.update(get_email_context())
return super().send_mail(template_prefix, email, context) return super().send_mail(template_prefix, email, context)

Wyświetl plik

@ -1,6 +1,5 @@
import re import re
from django.conf import settings
from django.core import validators from django.core import validators
from django.utils.deconstruct import deconstructible from django.utils.deconstruct import deconstructible
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -12,6 +11,7 @@ from versatileimagefield.serializers import VersatileImageFieldSerializer
from funkwhale_api.activity import serializers as activity_serializers from funkwhale_api.activity import serializers as activity_serializers
from funkwhale_api.common import serializers as common_serializers from funkwhale_api.common import serializers as common_serializers
from . import adapters
from . import models from . import models
@ -133,4 +133,4 @@ class MeSerializer(UserReadSerializer):
class PasswordResetSerializer(PRS): class PasswordResetSerializer(PRS):
def get_email_options(self): def get_email_options(self):
return {"extra_email_context": {"funkwhale_url": settings.FUNKWHALE_URL}} return {"extra_email_context": adapters.get_email_context()}

Wyświetl plik

@ -168,15 +168,20 @@ def test_changing_password_updates_secret_key(logged_in_api_client):
assert user.password != password assert user.password != password
def test_can_request_password_reset(factories, api_client, mailoutbox): def test_can_request_password_reset(
factories, preferences, settings, api_client, mailoutbox
):
user = factories["users.User"]() user = factories["users.User"]()
payload = {"email": user.email} payload = {"email": user.email}
emails = len(mailoutbox)
url = reverse("rest_password_reset") url = reverse("rest_password_reset")
preferences["instance__name"] = "Hello world"
response = api_client.post(url, payload) response = api_client.post(url, payload)
assert response.status_code == 200 assert response.status_code == 200
assert len(mailoutbox) > emails
confirmation_message = mailoutbox[-1]
assert "Hello world" in confirmation_message.body
assert settings.FUNKWHALE_HOSTNAME in confirmation_message.body
def test_user_can_patch_his_own_settings(logged_in_api_client): def test_user_can_patch_his_own_settings(logged_in_api_client):
@ -287,3 +292,24 @@ def test_creating_user_creates_actor_as_well(
user = User.objects.get(username="test1") user = User.objects.get(username="test1")
assert user.actor == actor assert user.actor == actor
def test_creating_user_sends_confirmation_email(
api_client, db, settings, preferences, mailoutbox
):
url = reverse("rest_register")
data = {
"username": "test1",
"email": "test1@test.com",
"password1": "testtest",
"password2": "testtest",
}
preferences["users__registration_enabled"] = True
preferences["instance__name"] = "Hello world"
response = api_client.post(url, data)
assert response.status_code == 201
confirmation_message = mailoutbox[-1]
assert "Hello world" in confirmation_message.body
assert settings.FUNKWHALE_HOSTNAME in confirmation_message.body

Wyświetl plik

@ -0,0 +1 @@
Use proper site name/domain in emails (#806)