From 6978d29d2d9c1be3d748133d2ebb29d1aecff9f7 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar <theskumar@users.noreply.github.com> Date: Fri, 22 Jul 2022 13:50:01 +0530 Subject: [PATCH] Make WAGTAILADMIN_BASE_URL top-level config to be able to deprecate PRIMARY_HOST --- hypha/apply/users/tests/test_utils.py | 13 ++++--------- hypha/settings/base.py | 7 +++---- hypha/settings/test.py | 2 +- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/hypha/apply/users/tests/test_utils.py b/hypha/apply/users/tests/test_utils.py index 95245b41a..7c490bb03 100644 --- a/hypha/apply/users/tests/test_utils.py +++ b/hypha/apply/users/tests/test_utils.py @@ -1,5 +1,3 @@ -from test.support import EnvironmentVarGuard - from django.core import mail from django.test import TestCase, override_settings @@ -10,12 +8,9 @@ from ..utils import send_activation_email @override_settings(ROOT_URLCONF='hypha.apply.urls') class TestActivationEmail(TestCase): - def setUp(self) -> None: - self.env = EnvironmentVarGuard() - self.env.set('PRIMARY_HOST', 'primary-domain.org') def test_activation_email_includes_link(self): - with self.env: - send_activation_email(UserFactory()) - assert len(mail.outbox) == 1 - assert "password reset form at https://primary-domain.org" in mail.outbox[0] + send_activation_email(UserFactory()) + assert len(mail.outbox) == 1 + email_body = mail.outbox[0].body + assert "password reset form at: https://primary-test-host.org" in email_body diff --git a/hypha/settings/base.py b/hypha/settings/base.py index 6bd425583..0e3f129a4 100644 --- a/hypha/settings/base.py +++ b/hypha/settings/base.py @@ -587,10 +587,9 @@ if env.bool('BASIC_AUTH_ENABLED', False): BASIC_AUTH_WHITELISTED_IP_NETWORKS = env.list('BASIC_AUTH_WHITELISTED_IP_NETWORKS', []) -if env.str('PRIMARY_HOST', None): - # This is used by Wagtail's email notifications for constructing absolute - # URLs. - WAGTAILADMIN_BASE_URL = 'https://{}'.format(env.str('PRIMARY_HOST')) +# This is used by Wagtail's email notifications for constructing absolute URLs. +PRIMARY_HOST = env.str('PRIMARY_HOST', None) +WAGTAILADMIN_BASE_URL = env.str("WAGTAILADMIN_BASE_URL", None) or f'https://{PRIMARY_HOST}' if PRIMARY_HOST else None # Security configuration diff --git a/hypha/settings/test.py b/hypha/settings/test.py index 6cd3f6fae..7e3a944cc 100644 --- a/hypha/settings/test.py +++ b/hypha/settings/test.py @@ -23,4 +23,4 @@ PASSWORD_HASHERS = [ 'django.contrib.auth.hashers.MD5PasswordHasher', ] -WAGTAILADMIN_BASE_URL = 'http://base-admin-url/' +WAGTAILADMIN_BASE_URL = "https://primary-test-host.org" -- GitLab