-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Xq depr fc 73 add receiver #37528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Xq depr fc 73 add receiver #37528
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| """ | ||
| Score rendering when submission is evaluated for external grader and has been saved successfully | ||
| """ | ||
| import logging | ||
| from functools import partial | ||
|
|
||
| from django.http import Http404 | ||
| from edx_when.field_data import DateLookupFieldData | ||
| from opaque_keys.edx.keys import CourseKey, UsageKey | ||
| from xblock.runtime import KvsFieldData | ||
|
|
||
| from common.djangoapps.student.models import AnonymousUserId | ||
| from lms.djangoapps.courseware.block_render import prepare_runtime_for_user | ||
| from lms.djangoapps.courseware.field_overrides import OverrideFieldData | ||
| from lms.djangoapps.courseware.model_data import DjangoKeyValueStore, FieldDataCache | ||
| from lms.djangoapps.lms_xblock.field_data import LmsFieldData | ||
| from xmodule.modulestore.django import modulestore | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def load_xblock_for_external_grader( | ||
| user_id: str, | ||
| course_key: CourseKey, | ||
| usage_key: UsageKey, | ||
| course=None, | ||
| ): | ||
| """ | ||
| Load a single XBlock for external grading without user access checks. | ||
| """ | ||
|
|
||
| user = AnonymousUserId.objects.get(anonymous_user_id=user_id).user | ||
|
|
||
| # pylint: disable=broad-exception-caught | ||
| try: | ||
| block = modulestore().get_item(usage_key) | ||
| except Exception as e: | ||
| log.exception(f"Could not find block {usage_key} in modulestore: {e}") | ||
| raise Http404(f"Module {usage_key} was not found") from e | ||
|
|
||
| field_data_cache = FieldDataCache.cache_for_block_descendents( | ||
| course_key, user, block, depth=0 | ||
| ) | ||
|
|
||
| student_kvs = DjangoKeyValueStore(field_data_cache) | ||
| student_data = KvsFieldData(student_kvs) | ||
|
|
||
| instance = get_block_for_descriptor_without_access_check( | ||
| user=user, | ||
| block=block, | ||
| student_data=student_data, | ||
| course_key=course_key, | ||
| course=course | ||
| ) | ||
|
|
||
| if instance is None: | ||
| msg = f"Could not bind XBlock instance for usage key: {usage_key}" | ||
| log.error(msg) | ||
| raise Http404(msg) | ||
|
|
||
| return instance | ||
|
|
||
|
|
||
| def get_block_for_descriptor_without_access_check(user, block, student_data, course_key, course=None): | ||
| """ | ||
| Modified version of get_block_for_descriptor that skips access checks for system operations. | ||
| """ | ||
|
|
||
| prepare_runtime_for_user( | ||
| user=user, | ||
| student_data=student_data, | ||
| runtime=block.runtime, | ||
| course_id=course_key, | ||
| course=course, | ||
| track_function=lambda event_type, event: None, | ||
| request_token="external-grader-token", | ||
| position=None, | ||
| wrap_xblock_display=True, | ||
| ) | ||
|
|
||
| block.bind_for_student( | ||
| user.id, | ||
| [ | ||
| partial(DateLookupFieldData, course_id=course_key, user=user), | ||
| partial(OverrideFieldData.wrap, user, course), | ||
| partial(LmsFieldData, student_data=student_data), | ||
| ], | ||
| ) | ||
|
|
||
| return block |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Is this a case where the event itself should be defined differently (or have an alias attribute)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This event is triggered from edx-submissions and it has already been merged. For this phase, we kept the event payload aligned with the legacy XQueue structure to maintain compatibility with the existing grading flow. Once we move further in the deprecation and no longer need to mirror XQueue, we can introduce a cleaner event schema or alias fields.