Skip to content

Commit

Permalink
fix: Moved the dynamic population of ALLOWED_HOSTS to the ready() method
Browse files Browse the repository at this point in the history
  • Loading branch information
amirtds committed Jan 29, 2024
1 parent d178cd0 commit f7b38a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
10 changes: 1 addition & 9 deletions lms/envs/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions openedx/core/djangoapps/appsembler/sites/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit f7b38a0

Please sign in to comment.