diff --git a/api/conf/settings/base.py b/api/conf/settings/base.py index d3203f94a78..c49dcc3a0f8 100644 --- a/api/conf/settings/base.py +++ b/api/conf/settings/base.py @@ -6,7 +6,6 @@ "django.contrib.messages", "django.contrib.staticfiles", # Third-party installed apps, more can be added in other settings files. - "corsheaders", "sslserver", ] diff --git a/api/conf/settings/logging.py b/api/conf/settings/logging.py index de60a8ca82a..495827bd760 100644 --- a/api/conf/settings/logging.py +++ b/api/conf/settings/logging.py @@ -115,6 +115,8 @@ def health_check_filter(record: LogRecord) -> bool: if not DEBUG: # WARNING: Do not run in production long-term as it can impact performance. - MIDDLEWARE.append( - "api.middleware.force_debug_cursor_middleware.force_debug_cursor_middleware" # noqa: E501 + middleware = ( + "api.middleware.force_debug_cursor_middleware.force_debug_cursor_middleware" ) + if middleware not in MIDDLEWARE: + MIDDLEWARE.append(middleware) diff --git a/api/conf/settings/oauth2.py b/api/conf/settings/oauth2.py index ca09cc3990a..37d851401ee 100644 --- a/api/conf/settings/oauth2.py +++ b/api/conf/settings/oauth2.py @@ -3,13 +3,12 @@ from conf.settings.base import INSTALLED_APPS, MIDDLEWARE -INSTALLED_APPS += [ - "oauth2_provider", -] +if "oauth2_provider" not in INSTALLED_APPS: + INSTALLED_APPS.append("oauth2_provider") -MIDDLEWARE += [ - "oauth2_provider.middleware.OAuth2TokenMiddleware", -] +middleware = "oauth2_provider.middleware.OAuth2TokenMiddleware" +if middleware not in MIDDLEWARE: + MIDDLEWARE.append(middleware) OAUTH2_PROVIDER = { "SCOPES": { diff --git a/api/conf/settings/openverse.py b/api/conf/settings/openverse.py index 02631153810..ff716941d4b 100644 --- a/api/conf/settings/openverse.py +++ b/api/conf/settings/openverse.py @@ -1,6 +1,5 @@ from conf.settings.base import INSTALLED_APPS -INSTALLED_APPS += [ - "api", -] +if "api" not in INSTALLED_APPS: + INSTALLED_APPS.append("api") diff --git a/api/conf/settings/rest_framework.py b/api/conf/settings/rest_framework.py index 1ced0971b05..b994d45c197 100644 --- a/api/conf/settings/rest_framework.py +++ b/api/conf/settings/rest_framework.py @@ -3,9 +3,8 @@ from conf.settings.base import INSTALLED_APPS -INSTALLED_APPS += [ - "rest_framework", -] +if "rest_framework" not in INSTALLED_APPS: + INSTALLED_APPS.append("rest_framework") THROTTLE_ANON_BURST = config("THROTTLE_ANON_BURST", default="5/hour") diff --git a/api/conf/settings/s3.py b/api/conf/settings/s3.py index c21078c86b0..bcbef2b3c6f 100644 --- a/api/conf/settings/s3.py +++ b/api/conf/settings/s3.py @@ -10,9 +10,8 @@ if USE_S3: - INSTALLED_APPS += [ - "storages", - ] + if "storages" not in INSTALLED_APPS: + INSTALLED_APPS.append("storages") STORAGES["default"]["BACKEND"] = "storages.backends.s3boto3.S3Boto3Storage" diff --git a/api/conf/settings/security.py b/api/conf/settings/security.py index af5bdef5490..22182999788 100644 --- a/api/conf/settings/security.py +++ b/api/conf/settings/security.py @@ -2,6 +2,8 @@ from decouple import config +from conf.settings.base import INSTALLED_APPS, MIDDLEWARE + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ @@ -35,6 +37,13 @@ CSRF_TRUSTED_ORIGINS = ["https://*.openverse.engineering"] # Allow anybody to access the API from any domain +if "corsheaders" not in INSTALLED_APPS: + INSTALLED_APPS.append("corsheaders") + +middleware = "corsheaders.middleware.CorsMiddleware" +if middleware not in MIDDLEWARE: + MIDDLEWARE.insert(0, middleware) + CORS_ORIGIN_ALLOW_ALL = True # Proxy handling, for production diff --git a/api/conf/settings/spectacular.py b/api/conf/settings/spectacular.py index 690750350d7..e1165db07de 100644 --- a/api/conf/settings/spectacular.py +++ b/api/conf/settings/spectacular.py @@ -4,9 +4,8 @@ from conf.settings.misc import API_VERSION -INSTALLED_APPS += [ - "drf_spectacular", -] +if "drf_spectacular" not in INSTALLED_APPS: + INSTALLED_APPS.append("drf_spectacular") SPECTACULAR_SETTINGS = { "TITLE": "Openverse API",