Skip to content

Commit

Permalink
feat: [ACI-183, ACI-189] emit new grade events
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrylo-kh committed Jan 16, 2024
1 parent e9d84d0 commit 1a89c61
Show file tree
Hide file tree
Showing 13 changed files with 278 additions and 236 deletions.
44 changes: 41 additions & 3 deletions lms/djangoapps/grades/signals/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

from django.dispatch import receiver
from opaque_keys.edx.keys import LearningContextKey
from openedx_events.learning.signals import EXAM_ATTEMPT_REJECTED, EXAM_ATTEMPT_VERIFIED
from openedx_events.learning.data import UserCourseData, CourseData, UserData, UserPersonalData
from openedx_events.learning.signals import (
EXAM_ATTEMPT_REJECTED,
EXAM_ATTEMPT_VERIFIED,
COURSE_GRADE_NOW_PASSED as COURSE_GRADE_NOW_PASSED_PUBLIC,
COURSE_GRADE_NOW_FAILED as COURSE_GRADE_NOW_FAILED_PUBLIC,
)
from submissions.models import score_reset, score_set
from xblock.scorable import ScorableXBlockMixin, Score

Expand Down Expand Up @@ -281,19 +287,51 @@ def listen_for_passing_grade(sender, user, course_id, **kwargs): # pylint: disa
"""
Listen for a signal indicating that the user has passed a course run.
Emits an edx.course.grade.now_passed event
Emits an edx.course.grade.now_passed event.
Emits a public event org.openedx.learning.course.grade.now.passed.v1.
"""
events.course_grade_now_passed(user, course_id)
# .. event_implemented_name: COURSE_GRADE_NOW_PASSED
COURSE_GRADE_NOW_PASSED_PUBLIC.send_event(
user_course_data=UserCourseData(
user=UserData(
pii=UserPersonalData(
username=user.username, email=user.email, name=user.get_full_name()
),
id=user.id,
is_active=user.is_active,
),
course=CourseData(
course_key=course_id,
)
)
)


@receiver(COURSE_GRADE_NOW_FAILED)
def listen_for_failing_grade(sender, user, course_id, **kwargs): # pylint: disable=unused-argument
"""
Listen for a signal indicating that the user has failed a course run.
Emits an edx.course.grade.now_failed event
Emits an edx.course.grade.now_failed event.
Emits a public event org.openedx.learning.course.grade.now.failed.v1.
"""
events.course_grade_now_failed(user, course_id)
# .. event_implemented_name: COURSE_GRADE_NOW_FAILED
COURSE_GRADE_NOW_FAILED_PUBLIC.send_event(
user_course_data=UserCourseData(
user=UserData(
pii=UserPersonalData(
username=user.username, email=user.email, name=user.get_full_name()
),
id=user.id,
is_active=user.is_active,
),
course=CourseData(
course_key=course_id,
)
)
)


@receiver(COURSE_GRADE_PASSED_FIRST_TIME)
Expand Down
10 changes: 9 additions & 1 deletion lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@
# .. toggle_use_cases: opt_in
# .. toggle_creation_date: 2023-10-10
# .. toggle_tickets: https://github.com/openedx/openedx-events/issues/210
'SEND_LEARNING_CERTIFICATE_LIFECYCLE_EVENTS_TO_BUS': False
'SEND_LEARNING_CERTIFICATE_LIFECYCLE_EVENTS_TO_BUS': False,
}

# Specifies extra XBlock fields that should available when requested via the Course Blocks API
Expand Down Expand Up @@ -5447,6 +5447,14 @@ def _should_send_certificate_events(settings):
'course-authoring-xblock-lifecycle':
{'event_key_field': 'xblock_info.usage_key', 'enabled': False},
},
'org.openedx.learning.course.grade.now.passed.v1': {
'learning-grade-lifecycle':
{'event_key_field': 'user_course_data.course.course_key', 'enabled': True},
},
'org.openedx.learning.course.grade.now.failed.v1': {
'learning-grade-lifecycle':
{'event_key_field': 'user_course_data.course.course_key', 'enabled': True},
},
}
derived_collection_entry('EVENT_BUS_PRODUCER_CONFIG', 'org.openedx.learning.certificate.created.v1',
'learning-certificate-lifecycle', 'enabled')
Expand Down
10 changes: 5 additions & 5 deletions requirements/edx-sandbox/py38.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ cryptography==38.0.4
# -r requirements/edx-sandbox/py38.in
cycler==0.12.1
# via matplotlib
fonttools==4.46.0
fonttools==4.47.2
# via matplotlib
importlib-resources==6.1.1
# via matplotlib
joblib==1.3.2
# via nltk
kiwisolver==1.4.5
# via matplotlib
lxml==4.9.3
lxml==5.1.0
# via
# -r requirements/edx-sandbox/py38.in
# openedx-calc
Expand Down Expand Up @@ -59,7 +59,7 @@ openedx-calc==3.0.1
# via -r requirements/edx-sandbox/py38.in
packaging==23.2
# via matplotlib
pillow==10.1.0
pillow==10.2.0
# via matplotlib
pycparser==2.21
# via cffi
Expand All @@ -71,9 +71,9 @@ pyparsing==3.1.1
# openedx-calc
python-dateutil==2.8.2
# via matplotlib
random2==1.0.1
random2==1.0.2
# via -r requirements/edx-sandbox/py38.in
regex==2023.10.3
regex==2023.12.25
# via nltk
scipy==1.7.3
# via
Expand Down
Loading

0 comments on commit 1a89c61

Please sign in to comment.