Skip to content

Commit

Permalink
chore: update event data
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanttV committed Apr 18, 2024
1 parent 8ea89ff commit 69b0051
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
26 changes: 20 additions & 6 deletions openassessment/xblock/ui_mixins/legacy/handlers_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging

from openedx_events.learning.data import ORASubmissionData
from openedx_events.learning.data import ORASubmissionAnswer, ORASubmissionData
from openedx_events.learning.signals import ORA_SUBMISSION_CREATED
from xblock.core import XBlock
from submissions import api as submissions_api
Expand Down Expand Up @@ -44,6 +44,7 @@
from openassessment.xblock.staff_area_mixin import require_course_staff
from openassessment.xblock.ui_mixins.legacy.serializers import SaveFilesDescriptionRequestSerializer
from openassessment.xblock.utils.data_conversion import verify_assessment_parameters
from openassessment.xblock.utils.user_data import get_anonymous_user_id

logger = logging.getLogger(__name__)

Expand All @@ -63,10 +64,9 @@ class LegacyHandlersMixin:
Exposes actions (@XBlock.json_handlers) used in our legacy ORA UI
"""

@staticmethod
def send_ora_submission_created_event(submission: dict) -> None:
def send_ora_submission_created_event(self, submission: dict) -> None:
"""
Send an event when a submission is created
Send an event when a submission is created.
Args:
submission (dict): The submission data
Expand All @@ -75,11 +75,25 @@ def send_ora_submission_created_event(submission: dict) -> None:
from openassessment.xblock.openassessmentblock import OpenAssessmentBlock

file_downloads = OpenAssessmentBlock.get_download_urls_from_submission(submission)
file_urls = [file_download.get("download_url") for file_download in file_downloads]
answer = submission.get("answer", {})
# .. event_implemented_name: ORA_SUBMISSION_CREATED
ORA_SUBMISSION_CREATED.send_event(
submission=ORASubmissionData(
id=submission.get("uuid"),
file_downloads=file_downloads,
uuid=submission.get("uuid"),
anonymous_user_id=get_anonymous_user_id(self.runtime.service(self, "user")),
location=str(self.location),
attempt_number=submission.get("attempt_number"),
created_at=submission.get("created_at"),
submitted_at=submission.get("submitted_at"),
answer=ORASubmissionAnswer(
parts=answer.get("parts"),
file_keys=answer.get("file_keys"),
file_descriptions=answer.get("files_descriptions"),
file_names=answer.get("files_names"),
file_sizes=answer.get("files_sizes"),
file_urls=file_urls,
),
)
)

Expand Down
9 changes: 9 additions & 0 deletions openassessment/xblock/utils/user_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ def get_user_preferences(user_service):
user_preferences['user_language'] = retrieved_preferences.get('pref-lang')

return user_preferences


def get_anonymous_user_id(user_service):
"""
Returns the anonymous user id for the current user.
:param user_service: XblockUserService
"""
return user_service.get_current_user().opt_attrs.get('edx-platform.anonymous_user_id')

0 comments on commit 69b0051

Please sign in to comment.