Skip to content

Commit

Permalink
feat: [ACI-183, ACI-189] emit new grade events (#2485)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrylo-kh authored and wowkalucky committed Feb 28, 2024
1 parent e9d84d0 commit dc744ff
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 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
1 change: 1 addition & 0 deletions requirements/edx/github.in
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@
# django42 support PR merged but new release is pending.
# https://github.com/openedx/edx-platform/issues/33431
-e git+https://github.com/anupdhabarde/edx-proctoring-proctortrack.git@31c6c9923a51c903ae83760ecbbac191363aa2a2#egg=edx_proctoring_proctortrack
-e git+https://github.com/raccoongang/[email protected]#egg=openedx_events

0 comments on commit dc744ff

Please sign in to comment.