Skip to content
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

Resolve LTI-AGS grading issue #5

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lti_consumer/lti_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ class LaunchTarget:


@XBlock.needs('i18n')
@XBlock.needs('rebind_user')
@XBlock.wants('user')
@XBlock.wants('settings')
@XBlock.wants('lti-configuration')
Expand Down Expand Up @@ -1365,7 +1364,7 @@ def _result_service_get(self, lti_consumer, user):
Returns:
dict: response to this request as dictated by the LtiConsumer
"""
self.runtime.service(self, 'rebind_user').rebind_noauth_module_to_user(self, user)
self.runtime.rebind_noauth_module_to_user(self, user)
args = []
if self.module_score:
args.extend([self.module_score, self.score_comment])
Expand Down Expand Up @@ -1453,7 +1452,7 @@ def set_user_module_score(self, user, score, max_score, comment=''):
else:
scaled_score = None

self.runtime.service(self, 'rebind_user').rebind_noauth_module_to_user(self, user)
self.runtime.rebind_noauth_module_to_user(self, user)

# have to publish for the progress page...
self.runtime.publish(
Expand Down
10 changes: 6 additions & 4 deletions lti_consumer/plugin/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def load_block_as_user(location): # pragma: nocover
"""
# pylint: disable=import-error,import-outside-toplevel
from crum import get_current_user, get_current_request
from lms.djangoapps.courseware.block_render import get_block_for_descriptor_internal
from lms.djangoapps.courseware.module_render import get_module_for_descriptor_internal
from openedx.core.lib.xblock_utils import request_token

# Retrieve descriptor from modulestore
Expand All @@ -114,12 +114,13 @@ def load_block_as_user(location): # pragma: nocover
return descriptor

# If not load this block to bind it onto the user
get_block_for_descriptor_internal(
get_module_for_descriptor_internal(
user=user,
descriptor=descriptor,
student_data=None,
course_id=location.course_key,
track_function=None,
xqueue_callback_url_prefix="",
request_token=request_token(request),
)
return descriptor
Expand All @@ -138,19 +139,20 @@ def _load_block_as_anonymous_user(location, descriptor): # pragma: nocover
# pylint: disable=import-error,import-outside-toplevel
from crum import impersonate
from django.contrib.auth.models import AnonymousUser
from lms.djangoapps.courseware.block_render import get_block_for_descriptor_internal
from lms.djangoapps.courseware.module_render import get_module_for_descriptor_internal

# ensure `crum.get_current_user` returns AnonymousUser. It returns None when outside
# of request scope which causes error during block loading.
user = AnonymousUser()
with impersonate(user):
# Load block, attaching it to AnonymousUser
get_block_for_descriptor_internal(
get_module_for_descriptor_internal(
user=user,
descriptor=descriptor,
student_data=None,
course_id=location.course_key,
track_function=None,
xqueue_callback_url_prefix="",
request_token="",
)

Expand Down
Loading