🔧(backend) add FRONTEND_THEME setting

The frontend need to know the theme to be used,
so we need to add a new setting to the backend,
in order to expose this value to the frontend.
This commit is contained in:
Anthony LC
2024-11-15 11:43:10 +01:00
committed by Anthony LC
parent 016597d5a2
commit c8edbd285b
4 changed files with 22 additions and 9 deletions

View File

@@ -48,3 +48,6 @@ AI_MODEL=llama
# Collaboration
COLLABORATION_SERVER_URL=ws://localhost:4444
# Frontend
FRONTEND_THEME=dsfr

View File

@@ -901,8 +901,9 @@ class ConfigView(views.APIView):
Return a dictionary of public settings.
"""
array_settings = [
"ENVIRONMENT",
"COLLABORATION_SERVER_URL",
"ENVIRONMENT",
"FRONTEND_THEME",
"MEDIA_BASE_URL",
"LANGUAGES",
"LANGUAGE_CODE",

View File

@@ -16,9 +16,10 @@ pytestmark = pytest.mark.django_db
@override_settings(
SENTRY_DSN="https://sentry.test/123",
MEDIA_BASE_URL="http://testserver/",
COLLABORATION_SERVER_URL="http://testcollab/",
FRONTEND_THEME="test-theme",
MEDIA_BASE_URL="http://testserver/",
SENTRY_DSN="https://sentry.test/123",
)
def test_api_config_anonymous():
"""Anonymous users should be allowed to get the configuration."""
@@ -27,18 +28,20 @@ def test_api_config_anonymous():
assert response.status_code == HTTP_200_OK
assert response.json() == {
"COLLABORATION_SERVER_URL": "http://testcollab/",
"ENVIRONMENT": "test",
"FRONTEND_THEME": "test-theme",
"LANGUAGES": [["en-us", "English"], ["fr-fr", "French"], ["de-de", "German"]],
"LANGUAGE_CODE": "en-us",
"SENTRY_DSN": "https://sentry.test/123",
"ENVIRONMENT": "test",
"MEDIA_BASE_URL": "http://testserver/",
"SENTRY_DSN": "https://sentry.test/123",
}
@override_settings(
SENTRY_DSN="https://sentry.test/123",
MEDIA_BASE_URL="http://testserver/",
COLLABORATION_SERVER_URL="http://testcollab/",
FRONTEND_THEME="test-theme",
MEDIA_BASE_URL="http://testserver/",
SENTRY_DSN="https://sentry.test/123",
)
def test_api_config_authenticated():
"""Authenticated users should be allowed to get the configuration."""
@@ -51,9 +54,10 @@ def test_api_config_authenticated():
assert response.status_code == HTTP_200_OK
assert response.json() == {
"COLLABORATION_SERVER_URL": "http://testcollab/",
"ENVIRONMENT": "test",
"FRONTEND_THEME": "test-theme",
"MEDIA_BASE_URL": "http://testserver/",
"LANGUAGES": [["en-us", "English"], ["fr-fr", "French"], ["de-de", "German"]],
"LANGUAGE_CODE": "en-us",
"SENTRY_DSN": "https://sentry.test/123",
"ENVIRONMENT": "test",
"MEDIA_BASE_URL": "http://testserver/",
}

View File

@@ -382,6 +382,11 @@ class Base(Configuration):
None, environ_name="COLLABORATION_SERVER_URL", environ_prefix=None
)
# Frontend
FRONTEND_THEME = values.Value(
None, environ_name="FRONTEND_THEME", environ_prefix=None
)
# Easy thumbnails
THUMBNAIL_EXTENSION = "webp"
THUMBNAIL_TRANSPARENCY_EXTENSION = "webp"