From af039d045dd09cbf5e26198633c61c460661acff Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Mon, 25 Nov 2024 14:35:02 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7(backend)=20add=20CRISP=5FWEBSITE?= =?UTF-8?q?=5FID=20setting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add setting CRISP_WEBSITE_ID. This setting is used to configure the Crisp chat widget. It will be available to the conf endpoint, to be used by the frontend. --- src/backend/core/api/viewsets.py | 1 + src/backend/core/tests/test_api_config.py | 36 ++++++----------------- src/backend/impress/settings.py | 5 ++++ 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/backend/core/api/viewsets.py b/src/backend/core/api/viewsets.py index ad5acec0..91e5745f 100644 --- a/src/backend/core/api/viewsets.py +++ b/src/backend/core/api/viewsets.py @@ -902,6 +902,7 @@ class ConfigView(views.APIView): """ array_settings = [ "COLLABORATION_SERVER_URL", + "CRISP_WEBSITE_ID", "ENVIRONMENT", "FRONTEND_THEME", "MEDIA_BASE_URL", diff --git a/src/backend/core/tests/test_api_config.py b/src/backend/core/tests/test_api_config.py index 850001bc..96888be5 100644 --- a/src/backend/core/tests/test_api_config.py +++ b/src/backend/core/tests/test_api_config.py @@ -17,17 +17,25 @@ pytestmark = pytest.mark.django_db @override_settings( COLLABORATION_SERVER_URL="http://testcollab/", + CRISP_WEBSITE_ID="123", FRONTEND_THEME="test-theme", MEDIA_BASE_URL="http://testserver/", SENTRY_DSN="https://sentry.test/123", ) -def test_api_config_anonymous(): +@pytest.mark.parametrize("is_authenticated", [False, True]) +def test_api_config(is_authenticated): """Anonymous users should be allowed to get the configuration.""" client = APIClient() + + if is_authenticated: + user = factories.UserFactory() + client.force_login(user) + response = client.get("/api/v1.0/config/") assert response.status_code == HTTP_200_OK assert response.json() == { "COLLABORATION_SERVER_URL": "http://testcollab/", + "CRISP_WEBSITE_ID": "123", "ENVIRONMENT": "test", "FRONTEND_THEME": "test-theme", "LANGUAGES": [["en-us", "English"], ["fr-fr", "French"], ["de-de", "German"]], @@ -35,29 +43,3 @@ def test_api_config_anonymous(): "MEDIA_BASE_URL": "http://testserver/", "SENTRY_DSN": "https://sentry.test/123", } - - -@override_settings( - 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.""" - user = factories.UserFactory() - - client = APIClient() - client.force_login(user) - - response = client.get("/api/v1.0/config/") - 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", - } diff --git a/src/backend/impress/settings.py b/src/backend/impress/settings.py index f75c89eb..3bb1d830 100755 --- a/src/backend/impress/settings.py +++ b/src/backend/impress/settings.py @@ -381,6 +381,11 @@ class Base(Configuration): None, environ_name="FRONTEND_THEME", environ_prefix=None ) + # Crisp + CRISP_WEBSITE_ID = values.Value( + None, environ_name="CRISP_WEBSITE_ID", environ_prefix=None + ) + # Easy thumbnails THUMBNAIL_EXTENSION = "webp" THUMBNAIL_TRANSPARENCY_EXTENSION = "webp"