Skip to content

Commit

Permalink
feat: add new tracking event for course updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
SaadYousaf authored and mariajgrimaldi committed Jan 23, 2024
1 parent 408e104 commit 1c2a96b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cms/djangoapps/contentstore/course_info_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down
20 changes: 20 additions & 0 deletions cms/djangoapps/contentstore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)

0 comments on commit 1c2a96b

Please sign in to comment.