From d941c6b012d31548ccca52ac883bbafdb7a6c73e Mon Sep 17 00:00:00 2001 From: Marcos Prieto Date: Fri, 21 Mar 2025 10:28:15 +0100 Subject: [PATCH] Expose annotation.text_rendered on the authority queue This will save work for the clients (LMS) and guarantee that the text rendered is always the same. --- h/services/annotation_authority_queue.py | 2 ++ tests/unit/h/services/annotation_authority_queue_test.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/h/services/annotation_authority_queue.py b/h/services/annotation_authority_queue.py index d3455ef097e..408ac87d5f2 100644 --- a/h/services/annotation_authority_queue.py +++ b/h/services/annotation_authority_queue.py @@ -48,6 +48,8 @@ def publish(self, event_action: str, annotation_id: str) -> None: annotation_dict = self._annotation_json_service.present_for_user( annotation=annotation, user=annotation.slim.user, with_metadata=True ) + # We already done the work to sanitize the text, send that value to the queue + annotation_dict["text_rendered"] = annotation.text_rendered payload = { "action": event_action, diff --git a/tests/unit/h/services/annotation_authority_queue_test.py b/tests/unit/h/services/annotation_authority_queue_test.py index 442377b7603..10b99483891 100644 --- a/tests/unit/h/services/annotation_authority_queue_test.py +++ b/tests/unit/h/services/annotation_authority_queue_test.py @@ -44,6 +44,8 @@ def test_publish( annotation, Connection, ): + annotation_presented = {"id": annotation.id} + annotation_json_service.present_for_user.return_value = annotation_presented annotation_read_service.get_annotation_by_id.return_value = annotation svc.publish("create", sentinel.annotation_id) @@ -56,6 +58,7 @@ def test_publish( user=annotation_read_service.get_annotation_by_id.return_value.slim.user, with_metadata=True, ) + assert annotation_presented["text_rendered"] == annotation.text_rendered Celery.assert_called_once_with( annotation_read_service.get_annotation_by_id.return_value.authority, ) @@ -67,7 +70,7 @@ def test_publish( kwargs={ "event": { "action": "create", - "annotation": annotation_json_service.present_for_user.return_value, + "annotation": annotation_presented, } }, )