Commit c724e74a by Carson Gee Committed by Justin Riley

Check if user is anonymous before calling PSYCHOMETRICS

LTI grade callbacks for example, come in with an anonymous user.  This causes a
stack trace in the psychometrics app that leads to the LTI service
getting a 404.  This adds a check before that callback gets registered.
parent 476b1d16
...@@ -494,7 +494,7 @@ def get_module_system_for_user(user, field_data_cache, ...@@ -494,7 +494,7 @@ def get_module_system_for_user(user, field_data_cache,
# pass position specified in URL to module through ModuleSystem # pass position specified in URL to module through ModuleSystem
system.set('position', position) system.set('position', position)
if settings.FEATURES.get('ENABLE_PSYCHOMETRICS'): if settings.FEATURES.get('ENABLE_PSYCHOMETRICS') and user.is_authenticated():
system.set( system.set(
'psychometrics_handler', # set callback for updating PsychometricsData 'psychometrics_handler', # set callback for updating PsychometricsData
make_psychometrics_data_update_handler(course_id, user, descriptor.location.url()) make_psychometrics_data_update_handler(course_id, user, descriptor.location.url())
......
...@@ -40,6 +40,8 @@ from courseware.tests.test_submitting_problems import TestSubmittingProblems ...@@ -40,6 +40,8 @@ from courseware.tests.test_submitting_problems import TestSubmittingProblems
from student.models import anonymous_id_for_user from student.models import anonymous_id_for_user
from lms.lib.xblock.runtime import quote_slashes from lms.lib.xblock.runtime import quote_slashes
FEATURES_WITH_PSYCHOMETRICS = settings.FEATURES.copy()
FEATURES_WITH_PSYCHOMETRICS['ENABLE_PSYCHOMETRICS'] = True
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class ModuleRenderTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase): class ModuleRenderTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase):
...@@ -1000,3 +1002,14 @@ class TestRebindModule(TestSubmittingProblems): ...@@ -1000,3 +1002,14 @@ class TestRebindModule(TestSubmittingProblems):
self.assertEqual(module.system.anonymous_student_id, anonymous_id_for_user(user2, self.course.id)) self.assertEqual(module.system.anonymous_student_id, anonymous_id_for_user(user2, self.course.id))
self.assertEqual(module.scope_ids.user_id, user2.id) self.assertEqual(module.scope_ids.user_id, user2.id)
self.assertEqual(module.descriptor.scope_ids.user_id, user2.id) self.assertEqual(module.descriptor.scope_ids.user_id, user2.id)
@patch('courseware.module_render.make_psychometrics_data_update_handler')
@override_settings(FEATURES=FEATURES_WITH_PSYCHOMETRICS)
def test_psychometrics_anonymous(self, psycho_handler):
"""
Make sure that noauth modules with anonymous users don't have
the psychometrics callback bound.
"""
module = self.get_module_for_user(self.anon_user)
module.system.rebind_noauth_module_to_user(module, self.anon_user)
self.assertFalse(psycho_handler.called)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment