From a20a63d6edd5858ce97ca5ff00965f5c06e226ad Mon Sep 17 00:00:00 2001 From: Agate Date: Mon, 20 Apr 2020 15:42:29 +0200 Subject: [PATCH] Fixed issue with confirmation email not sending when signup-approval was enabled --- api/funkwhale_api/users/views.py | 8 ++++++++ api/tests/users/test_views.py | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/api/funkwhale_api/users/views.py b/api/funkwhale_api/users/views.py index 7e94f34a6..848bc7e6b 100644 --- a/api/funkwhale_api/users/views.py +++ b/api/funkwhale_api/users/views.py @@ -5,6 +5,7 @@ from rest_framework import mixins, viewsets from rest_framework.decorators import action from rest_framework.response import Response +from funkwhale_api.common import authentication from funkwhale_api.common import preferences from . import models, serializers, tasks @@ -26,6 +27,13 @@ class RegisterView(registration_views.RegisterView): def is_open_for_signup(self, request): return get_adapter().is_open_for_signup(request) + def perform_create(self, serializer): + user = super().perform_create(serializer) + if not user.is_active: + # manual approval, we need to send the confirmation email by hand + authentication.send_email_confirmation(self.request, user) + return user + class VerifyEmailView(registration_views.VerifyEmailView): action = "verify-email" diff --git a/api/tests/users/test_views.py b/api/tests/users/test_views.py index f02c16538..3a8929cd4 100644 --- a/api/tests/users/test_views.py +++ b/api/tests/users/test_views.py @@ -418,7 +418,9 @@ def test_username_with_existing_local_account_are_invalid( assert "username" in response.data -def test_signup_with_approval_enabled(preferences, factories, api_client, mocker): +def test_signup_with_approval_enabled( + preferences, factories, api_client, mocker, mailoutbox, settings +): url = reverse("rest_register") data = { "username": "test1", @@ -455,6 +457,10 @@ def test_signup_with_approval_enabled(preferences, factories, api_client, mocker new_status="pending", ) + confirmation_message = mailoutbox[-1] + assert "confirm" in confirmation_message.body + assert settings.FUNKWHALE_HOSTNAME in confirmation_message.body + def test_signup_with_approval_enabled_validation_error( preferences, factories, api_client