From 016597d5a2ccece7fbe557d8625e4a6b131247a0 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Fri, 15 Nov 2024 11:36:40 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7(backend)=20add=20COLLABORATION=5FS?= =?UTF-8?q?ERVER=5FURL=20setting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The frontend need to know the collab server url, so we need to add a new setting to the backend, in order to expose this value to the frontend. If the setting is not defined, the frontend current domain will be used as the base url. In production this setting do not need to be defined since we have nginx capturing the ws requests, but in development we need to define it to target the collaboration server. --- env.d/development/common.dist | 3 +++ src/backend/core/api/viewsets.py | 1 + src/backend/core/tests/test_api_config.py | 7 ++++++- src/backend/impress/settings.py | 5 +++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/env.d/development/common.dist b/env.d/development/common.dist index ec20b2d5..9e8e8253 100644 --- a/env.d/development/common.dist +++ b/env.d/development/common.dist @@ -45,3 +45,6 @@ OIDC_AUTH_REQUEST_EXTRA_PARAMS={"acr_values": "eidas1"} AI_BASE_URL=https://openaiendpoint.com AI_API_KEY=password AI_MODEL=llama + +# Collaboration +COLLABORATION_SERVER_URL=ws://localhost:4444 diff --git a/src/backend/core/api/viewsets.py b/src/backend/core/api/viewsets.py index 203c1942..394dbc7d 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 = [ "ENVIRONMENT", + "COLLABORATION_SERVER_URL", "MEDIA_BASE_URL", "LANGUAGES", "LANGUAGE_CODE", diff --git a/src/backend/core/tests/test_api_config.py b/src/backend/core/tests/test_api_config.py index 405ff27a..3c1daab6 100644 --- a/src/backend/core/tests/test_api_config.py +++ b/src/backend/core/tests/test_api_config.py @@ -18,6 +18,7 @@ pytestmark = pytest.mark.django_db @override_settings( SENTRY_DSN="https://sentry.test/123", MEDIA_BASE_URL="http://testserver/", + COLLABORATION_SERVER_URL="http://testcollab/", ) def test_api_config_anonymous(): """Anonymous users should be allowed to get the configuration.""" @@ -25,6 +26,7 @@ def test_api_config_anonymous(): response = client.get("/api/v1.0/config/") assert response.status_code == HTTP_200_OK assert response.json() == { + "COLLABORATION_SERVER_URL": "http://testcollab/", "LANGUAGES": [["en-us", "English"], ["fr-fr", "French"], ["de-de", "German"]], "LANGUAGE_CODE": "en-us", "SENTRY_DSN": "https://sentry.test/123", @@ -34,7 +36,9 @@ def test_api_config_anonymous(): @override_settings( - SENTRY_DSN="https://sentry.test/123", MEDIA_BASE_URL="http://testserver/" + SENTRY_DSN="https://sentry.test/123", + MEDIA_BASE_URL="http://testserver/", + COLLABORATION_SERVER_URL="http://testcollab/", ) def test_api_config_authenticated(): """Authenticated users should be allowed to get the configuration.""" @@ -46,6 +50,7 @@ def test_api_config_authenticated(): response = client.get("/api/v1.0/config/") assert response.status_code == HTTP_200_OK assert response.json() == { + "COLLABORATION_SERVER_URL": "http://testcollab/", "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 ec62e86d..25bf9c4a 100755 --- a/src/backend/impress/settings.py +++ b/src/backend/impress/settings.py @@ -377,6 +377,11 @@ class Base(Configuration): # Sentry SENTRY_DSN = values.Value(None, environ_name="SENTRY_DSN", environ_prefix=None) + # Collaboration + COLLABORATION_SERVER_URL = values.Value( + None, environ_name="COLLABORATION_SERVER_URL", environ_prefix=None + ) + # Easy thumbnails THUMBNAIL_EXTENSION = "webp" THUMBNAIL_TRANSPARENCY_EXTENSION = "webp"