From 1c2a96bf76e06da2fe0492413422330f10b8c1cd Mon Sep 17 00:00:00 2001 From: SaadYousaf Date: Wed, 10 Jan 2024 12:42:54 +0500 Subject: [PATCH] feat: add new tracking event for course updates. --- .../contentstore/course_info_model.py | 3 +++ cms/djangoapps/contentstore/utils.py | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/cms/djangoapps/contentstore/course_info_model.py b/cms/djangoapps/contentstore/course_info_model.py index 3a9d5d92de4..8f59998e716 100644 --- a/cms/djangoapps/contentstore/course_info_model.py +++ b/cms/djangoapps/contentstore/course_info_model.py @@ -19,6 +19,7 @@ from django.http import HttpResponseBadRequest from django.utils.translation import gettext as _ +from cms.djangoapps.contentstore.utils import track_course_update_event from openedx.core.lib.xblock_utils import get_course_update_items from xmodule.html_block import CourseInfoBlock # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order @@ -85,6 +86,8 @@ def update_course_updates(location, update, passed_id=None, user=None): # update db record save_course_update_items(location, course_updates, course_update_items, user) + # track course update event + track_course_update_event(location.course_key, user, course_update_dict) # remove status key if "status" in course_update_dict: del course_update_dict["status"] diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index 0c6a44a3d10..8ef99dc331f 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -14,6 +14,7 @@ from django.urls import reverse from django.utils import translation from django.utils.translation import gettext as _ +from eventtracking import tracker from help_tokens.core import HelpUrlExpert from lti_consumer.models import CourseAllowPIISharingInLTIFlag from opaque_keys.edx.keys import CourseKey, UsageKey @@ -37,6 +38,7 @@ CourseStaffRole, GlobalStaff, ) +from common.djangoapps.track import contexts from common.djangoapps.util.course import get_link_for_about_page from common.djangoapps.util.milestones_helpers import ( is_prerequisite_courses_enabled, @@ -1806,3 +1808,21 @@ def can_read(self, course_key): def can_write(self, course_key): """ Does the user have read access to the given course/library? """ return has_studio_write_access(self._user, course_key) + + +def track_course_update_event(course_key, user, event_data=None): + """ + Track course update event + """ + event_name = 'edx.contentstore.course_update' + event_data['course_id'] = str(course_key) + event_data['user_id'] = str(user.id) + event_data['user_forums_roles'] = [ + role.name for role in user.roles.filter(course_id=str(course_key)) + ] + event_data['user_course_roles'] = [ + role.role for role in user.courseaccessrole_set.filter(course_id=str(course_key)) + ] + context = contexts.course_context_from_course_id(course_key) + with tracker.get_tracker().context(event_name, context): + tracker.emit(event_name, event_data)