From f7b38a0e4491dad9d0884fc4bf956d095ef60e41 Mon Sep 17 00:00:00 2001 From: Amir Tadrisi Date: Wed, 15 Nov 2023 19:54:10 -0500 Subject: [PATCH] fix: Moved the dynamic population of ALLOWED_HOSTS to the ready() method --- lms/envs/production.py | 10 +--------- openedx/core/djangoapps/appsembler/sites/apps.py | 5 +++++ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lms/envs/production.py b/lms/envs/production.py index 1fd92d68032a..9bd2e51c1183 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -27,9 +27,7 @@ import yaml from corsheaders.defaults import default_headers as corsheaders_default_headers from django.core.exceptions import ImproperlyConfigured -from django.contrib.sites.models import Site from path import Path as path -from django.conf import settings from openedx.core.djangoapps.plugins import plugin_settings, constants as plugin_constants from openedx.core.lib.derived import derive_settings @@ -212,17 +210,11 @@ def get_env_setting(setting): CMS_BASE = ENV_TOKENS.get('CMS_BASE', 'studio.edx.org') -# Fetching all domain names from the Site model -site_domains = [site.domain for site in Site.objects.all()] - -ALLOWED_HOSTS = site_domains + [ +ALLOWED_HOSTS = [ ENV_TOKENS.get('LMS_BASE', ''), FEATURES.get('PREVIEW_LMS_BASE', '') ] -# Ensure that no empty strings are in ALLOWED_HOSTS -ALLOWED_HOSTS = [host for host in ALLOWED_HOSTS if host] - # allow for environments to specify what cookie name our login subsystem should use # this is to fix a bug regarding simultaneous logins between edx.org and edge.edx.org which can # happen with some browsers (e.g. Firefox) diff --git a/openedx/core/djangoapps/appsembler/sites/apps.py b/openedx/core/djangoapps/appsembler/sites/apps.py index 90e791c716ce..cf918385307f 100644 --- a/openedx/core/djangoapps/appsembler/sites/apps.py +++ b/openedx/core/djangoapps/appsembler/sites/apps.py @@ -10,8 +10,13 @@ class SitesConfig(AppConfig): def ready(self): from openedx.core.djangoapps.appsembler.sites.models import patched_clear_site_cache from openedx.core.djangoapps.site_configuration.models import SiteConfiguration + from django.contrib.sites.models import Site + from django.conf import settings from .config_values_modifier import init_configuration_modifier_for_site_config pre_save.connect(patched_clear_site_cache, sender=SiteConfiguration) post_init.connect(init_configuration_modifier_for_site_config, sender=SiteConfiguration) + # Update ALLOWED_HOSTS based on Site model + site_domains = [site.domain for site in Site.objects.all()] + settings.ALLOWED_HOSTS.extend(site_domains)