From 37eaee8bde7c9b499d93c27ff2607dd724d70abb Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Thu, 16 May 2024 17:58:33 -0500 Subject: [PATCH 1/2] feat: add discussion reference to comments and responses It also adds the thread title to the thread events definition --- .../xapi/event_transformers/forum_events.py | 27 +++++++++++++++++++ .../expected/edx.forum.comment.created.json | 9 +++++++ .../expected/edx.forum.response.created.json | 9 +++++++ .../expected/edx.forum.thread.created.json | 1 + .../expected/edx.forum.thread.deleted.json | 1 + .../expected/edx.forum.thread.reported.json | 1 + .../expected/edx.forum.thread.unreported.json | 1 + .../expected/edx.forum.thread.viewed.json | 1 + 8 files changed, 50 insertions(+) diff --git a/event_routing_backends/processors/xapi/event_transformers/forum_events.py b/event_routing_backends/processors/xapi/event_transformers/forum_events.py index 3ec99afc..0bbef139 100644 --- a/event_routing_backends/processors/xapi/event_transformers/forum_events.py +++ b/event_routing_backends/processors/xapi/event_transformers/forum_events.py @@ -27,6 +27,11 @@ def get_object(self): object_id = self.get_data('data.id', True) object_path = self.get_data('context.path', True).rstrip('/').replace(object_id, '').rstrip('/') + kwargs = {} + + if self.get_data('data.title'): + kwargs['name'] = LanguageMap({constants.EN: self.get_data('data.title')}) + return Activity( id='{lms_root_url}{object_path}/{object_id}'.format( lms_root_url=settings.LMS_ROOT_URL, @@ -35,9 +40,31 @@ def get_object(self): ), definition=ActivityDefinition( type=constants.XAPI_ACTIVITY_DISCUSSION, + **kwargs ) ) + def get_context_activities(self): + context_activities = super().get_context_activities() + + discussion = self.get_data('data.discussion.id') + if not discussion: + return context_activities + + context_activities.grouping = [ + Activity( + id='{lms_root_url}/api/discussion/v1/threads/{discussion_id}'.format( + lms_root_url=settings.LMS_ROOT_URL, + discussion_id=discussion + ), + definition=ActivityDefinition( + type=constants.XAPI_ACTIVITY_DISCUSSION, + ) + ) + ] + + return context_activities + @XApiTransformersRegistry.register('edx.forum.thread.created') class ThreadCreatedTransformer(BaseForumThreadTransformer): diff --git a/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.comment.created.json b/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.comment.created.json index 16127d3d..e84d0a5b 100644 --- a/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.comment.created.json +++ b/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.comment.created.json @@ -17,6 +17,15 @@ "type": "http://adlnet.gov/expapi/activities/course" } } + ], + "grouping": [ + { + "id": "http://localhost:18000/api/discussion/v1/threads/64d1df0887e82a002b35a6f7", + "objectType": "Activity", + "definition": { + "type": "http://id.tincanapi.com/activitytype/discussion" + } + } ] }, "extensions": { diff --git a/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.response.created.json b/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.response.created.json index 1377089d..16aedc16 100644 --- a/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.response.created.json +++ b/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.response.created.json @@ -17,6 +17,15 @@ "type": "http://adlnet.gov/expapi/activities/course" } } + ], + "grouping": [ + { + "id": "http://localhost:18000/api/discussion/v1/threads/64b7b2bee68f35003369092d", + "objectType": "Activity", + "definition": { + "type": "http://id.tincanapi.com/activitytype/discussion" + } + } ] }, "extensions": { diff --git a/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.created.json b/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.created.json index 929ea31d..275de8b9 100644 --- a/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.created.json +++ b/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.created.json @@ -27,6 +27,7 @@ }, "object": { "definition": { + "name": {"en": "Another thread in test topic"}, "type": "http://id.tincanapi.com/activitytype/discussion" }, "id": "http://localhost:18000/api/discussion/v1/threads/64abcdfee68f35002fd013c6", diff --git a/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.deleted.json b/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.deleted.json index 5a7a9655..8307eee8 100644 --- a/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.deleted.json +++ b/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.deleted.json @@ -26,6 +26,7 @@ }, "object": { "definition": { + "name": {"en": "Another thread in test topic"}, "type": "http://id.tincanapi.com/activitytype/discussion" }, "id": "http://localhost:18000/api/discussion/v1/threads/64abcdfee68f35002fd013c6", diff --git a/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.reported.json b/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.reported.json index 486b8276..bd4f54c7 100644 --- a/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.reported.json +++ b/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.reported.json @@ -26,6 +26,7 @@ }, "object": { "definition": { + "name": {"en": "title of post"}, "type": "http://id.tincanapi.com/activitytype/discussion" }, "id": "http://localhost:18000/api/discussion/v1/threads/64b7b2bee68f35003369092d", diff --git a/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.unreported.json b/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.unreported.json index d28b70d2..6eb5fb6c 100644 --- a/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.unreported.json +++ b/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.unreported.json @@ -26,6 +26,7 @@ }, "object": { "definition": { + "name": {"en": "title of post"}, "type": "http://id.tincanapi.com/activitytype/discussion" }, "id": "http://localhost:18000/api/discussion/v1/threads/64b7b2bee68f35003369092d", diff --git a/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.viewed.json b/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.viewed.json index a00c62e8..5a78a29f 100644 --- a/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.viewed.json +++ b/event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.thread.viewed.json @@ -26,6 +26,7 @@ }, "object": { "definition": { + "name": {"en": "This is first post"}, "type": "http://id.tincanapi.com/activitytype/discussion" }, "id": "http://localhost:18000/api/discussion/v1/comments/64a817fce68f35002fd013c3", From 12c5c99d684b11cdb37128038fe0969ceed6aa6e Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Wed, 22 May 2024 10:11:55 -0500 Subject: [PATCH 2/2] chore: bump version to v9.2.0 --- CHANGELOG.rst | 8 ++++++++ event_routing_backends/__init__.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c20e4a13..52c48bf5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,14 @@ Change Log Unreleased ~~~~~~~~~~ +[9.2.0] + +* Add discussion reference to comments and responses xAPI events + +[9.1.0] + +* Add python 3.11 and 3.12 support + [9.0.1] * Fix an issue with the event routing backend async task to not find the event-tracking backend. diff --git a/event_routing_backends/__init__.py b/event_routing_backends/__init__.py index 84f7966f..793994cc 100644 --- a/event_routing_backends/__init__.py +++ b/event_routing_backends/__init__.py @@ -2,4 +2,4 @@ Various backends for receiving edX LMS events.. """ -__version__ = '9.1.0' +__version__ = '9.2.0'