Skip to content
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
3 changes: 2 additions & 1 deletion common/lib/xmodule/xmodule/lti_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@

import bleach
import oauthlib.oauth1
from django.conf import settings
from lxml import etree
from oauthlib.oauth1.rfc5849 import signature
from pkg_resources import resource_string
Expand Down Expand Up @@ -584,7 +585,7 @@ def get_resource_link_id(self):
i4x-2-3-lti-31de800015cf4afb973356dbe81496df this part of resource_link_id:
makes resource_link_id to be unique among courses inside same system.
"""
return str(parse.quote(f"{self.system.hostname}-{self.location.html_id()}")) # lint-amnesty, pylint: disable=line-too-long
return str(parse.quote(f"{settings.LMS_BASE}-{self.location.html_id()}"))

def get_lis_result_sourcedid(self):
"""
Expand Down
1 change: 0 additions & 1 deletion common/lib/xmodule/xmodule/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ def get_module(descriptor):
static_url='/static',
track_function=Mock(name='get_test_system.track_function'),
get_module=get_module,
hostname="edx.org",
services={
'user': user_service,
'mako': mako_service,
Expand Down
11 changes: 8 additions & 3 deletions common/lib/xmodule/xmodule/tests/test_lti_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@

import datetime
import textwrap
import unittest
from copy import copy
from unittest.mock import Mock, PropertyMock, patch
from urllib import parse


import pytest
from django.conf import settings
from django.test import TestCase, override_settings
from lxml import etree
from opaque_keys.edx.locator import BlockUsageLocator
from pytz import UTC
from webob.request import Request
from xblock.field_data import DictFieldData
from xblock.fields import ScopeIds


from common.djangoapps.xblock_django.constants import ATTR_KEY_ANONYMOUS_USER_ID
from xmodule.fields import Timedelta
from xmodule.lti_2_util import LTIError
Expand All @@ -25,7 +28,8 @@
from . import get_test_system


class LTIBlockTest(unittest.TestCase):
@override_settings(LMS_BASE="edx.org")
class LTIBlockTest(TestCase):
"""Logic tests for LTI module."""

def setUp(self):
Expand Down Expand Up @@ -69,8 +73,9 @@ def setUp(self):
current_user = self.system.service(self.xmodule, 'user').get_current_user()
self.user_id = current_user.opt_attrs.get(ATTR_KEY_ANONYMOUS_USER_ID)
self.lti_id = self.xmodule.lti_id

self.unquoted_resource_link_id = '{}-i4x-2-3-lti-31de800015cf4afb973356dbe81496df'.format(
self.xmodule.runtime.hostname
settings.LMS_BASE
)

sourced_id = ':'.join(parse.quote(i) for i in (self.lti_id, self.unquoted_resource_link_id, self.user_id)) # lint-amnesty, pylint: disable=line-too-long
Expand Down
31 changes: 25 additions & 6 deletions common/lib/xmodule/xmodule/x_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,19 @@ def node_path(self):
DeprecationWarning, stacklevel=3
)

@property
def hostname(self):
"""
Hostname of the site as set in the Django settings `LMS_BASE`
Deprecated in favour of direct import of `django.conf.settings`
"""
warnings.warn(
'runtime.hostname is deprecated. Please use `LMS_BASE` from `django.conf.settings`.',
DeprecationWarning, stacklevel=3,
)
from django.conf import settings
return settings.LMS_BASE


class ModuleSystem(MetricsMixin, ConfigurableFragmentWrapper, ModuleSystemShim, Runtime):
"""
Expand All @@ -1636,11 +1649,18 @@ class ModuleSystem(MetricsMixin, ConfigurableFragmentWrapper, ModuleSystemShim,
"""

def __init__(
self, static_url, track_function, get_module,
descriptor_runtime, hostname="", publish=None,
course_id=None, error_descriptor_class=None,
field_data=None, rebind_noauth_module_to_user=None,
**kwargs):
self,
static_url,
track_function,
get_module,
descriptor_runtime,
publish=None,
course_id=None,
error_descriptor_class=None,
field_data=None,
rebind_noauth_module_to_user=None,
**kwargs,
):
"""
Create a closure around the system environment.

Expand Down Expand Up @@ -1678,7 +1698,6 @@ def __init__(
self.STATIC_URL = static_url
self.track_function = track_function
self.get_module = get_module
self.HOSTNAME = self.hostname = hostname
Comment thread
tecoholic marked this conversation as resolved.
Outdated
self.course_id = course_id

if publish:
Expand Down
1 change: 0 additions & 1 deletion lms/djangoapps/courseware/module_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,6 @@ def rebind_noauth_module_to_user(module, real_user):
static_url=settings.STATIC_URL,
get_module=inner_get_module,
user=user,
hostname=settings.SITE_NAME,
publish=publish,
course_id=course_id,
# TODO: When we merge the descriptor and module systems, we can stop reaching into the mixologist (cpennington)
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/courseware/tests/test_lti_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def setUp(self):
context_id = str(self.item_descriptor.course_id)
user_service = self.item_descriptor.xmodule_runtime.service(self.item_descriptor, 'user')
user_id = str(user_service.get_current_user().opt_attrs.get(ATTR_KEY_ANONYMOUS_USER_ID))
hostname = self.item_descriptor.xmodule_runtime.hostname
hostname = settings.LMS_BASE
resource_link_id = str(urllib.parse.quote(f'{hostname}-{self.item_descriptor.location.html_id()}'))

sourcedId = "{context}:{resource_link}:{user_id}".format(
Expand Down