From f0cc29e779ffabab40b692e9c2ed4971822ba5d0 Mon Sep 17 00:00:00 2001 From: Stephan Meijer Date: Thu, 8 Jan 2026 16:01:18 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(backend)=20stylistic=20and?= =?UTF-8?q?=20consistency=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactored converter services based on PR #1609 review comments: - Renamed parameter to `data` across all convert methods for consistency - Replaced recursive call with explicit sequential calls for readability - Hardcoded CONVERSION_API_SECURE=True in Production class for security - Removed unused YdocConverter import from viewsets.py - Updated tests to match new error message wording Signed-off-by: Stephan Meijer --- .../core/services/converter_services.py | 19 ++++++++++--------- .../tests/test_services_converter_services.py | 6 +++--- src/backend/impress/settings.py | 3 +++ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/backend/core/services/converter_services.py b/src/backend/core/services/converter_services.py index 91dd6e5d..e6c28fe2 100644 --- a/src/backend/core/services/converter_services.py +++ b/src/backend/core/services/converter_services.py @@ -25,7 +25,7 @@ class ServiceUnavailableError(ConversionError): class ConverterProtocol(typing.Protocol): """Protocol for converter classes.""" - def convert(self, text, content_type, accept): + def convert(self, data, content_type, accept): """Convert content from one format to another.""" @@ -43,10 +43,11 @@ class Converter: """Convert input into other formats using external microservices.""" if content_type == mime_types.DOCX and accept == mime_types.YJS: - return self.convert( - self.docspec.convert(data, mime_types.DOCX, mime_types.BLOCKNOTE), - mime_types.BLOCKNOTE, - mime_types.YJS, + blocknote_data = self.docspec.convert( + data, mime_types.DOCX, mime_types.BLOCKNOTE + ) + return self.ydoc.convert( + blocknote_data, mime_types.BLOCKNOTE, mime_types.YJS ) return self.ydoc.convert(data, content_type, accept) @@ -111,16 +112,16 @@ class YdocConverter: response.raise_for_status() return response - def convert(self, text, content_type=mime_types.MARKDOWN, accept=mime_types.YJS): + def convert(self, data, content_type=mime_types.MARKDOWN, accept=mime_types.YJS): """Convert a Markdown text into our internal format using an external microservice.""" - if not text: - raise ValidationError("Input text cannot be empty") + if not data: + raise ValidationError("Input data cannot be empty") try: response = self._request( f"{settings.Y_PROVIDER_API_BASE_URL}{settings.CONVERSION_API_ENDPOINT}/", - text, + data, content_type, accept, ) diff --git a/src/backend/core/tests/test_services_converter_services.py b/src/backend/core/tests/test_services_converter_services.py index 5cb9a4b1..760504ce 100644 --- a/src/backend/core/tests/test_services_converter_services.py +++ b/src/backend/core/tests/test_services_converter_services.py @@ -22,9 +22,9 @@ def test_auth_header(settings): def test_convert_empty_text(): - """Should raise ValidationError when text is empty.""" + """Should raise ValidationError when data is empty.""" converter = YdocConverter() - with pytest.raises(ValidationError, match="Input text cannot be empty"): + with pytest.raises(ValidationError, match="Input data cannot be empty"): converter.convert("") @@ -143,5 +143,5 @@ def test_convert_none_input(): """Should raise ValidationError when input is None.""" converter = YdocConverter() - with pytest.raises(ValidationError, match="Input text cannot be empty"): + with pytest.raises(ValidationError, match="Input data cannot be empty"): converter.convert(None) diff --git a/src/backend/impress/settings.py b/src/backend/impress/settings.py index 07a5182a..64ffed97 100755 --- a/src/backend/impress/settings.py +++ b/src/backend/impress/settings.py @@ -1057,6 +1057,9 @@ class Production(Base): # Privacy SECURE_REFERRER_POLICY = "same-origin" + # Conversion API: Always verify SSL in production + CONVERSION_API_SECURE = True + CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache",