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",