diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 122d15b..7ecd9b8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,10 @@ Change Log Unreleased ********** +3.6.0 - 2024-02-13 +****************** +* Enable backend access by course waffle flag or django setting. + 3.4.0 - 2024-01-30 ****************** * Add new GET endpoint to retrieve whether Learning Assistant is enabled in a given course. diff --git a/learning_assistant/__init__.py b/learning_assistant/__init__.py index c900846..67b85a7 100644 --- a/learning_assistant/__init__.py +++ b/learning_assistant/__init__.py @@ -2,6 +2,6 @@ Plugin for a learning assistant backend, intended for use within edx-platform. """ -__version__ = '3.5.0' +__version__ = '3.6.0' default_app_config = 'learning_assistant.apps.LearningAssistantConfig' # pylint: disable=invalid-name diff --git a/learning_assistant/api.py b/learning_assistant/api.py index b5e4a29..ed85d6c 100644 --- a/learning_assistant/api.py +++ b/learning_assistant/api.py @@ -17,7 +17,7 @@ block_leaf_filter, get_single_block, get_text_transcript, - learning_assistant_available, + learning_assistant_available_flag, traverse_block_pre_order, ) from learning_assistant.text_utils import html_to_text @@ -118,6 +118,13 @@ def render_prompt_template(request, user_id, course_id, unit_usage_key): return data +def learning_assistant_available(course_key): + """ + Return whether or not the learning assistant is available via django setting or course waffle flag. + """ + return getattr(settings, 'LEARNING_ASSISTANT_AVAILABLE', False) or learning_assistant_available_flag(course_key) + + def learning_assistant_enabled(course_key): """ Return whether the Learning Assistant is enabled in the course represented by the course_key. diff --git a/learning_assistant/platform_imports.py b/learning_assistant/platform_imports.py index d9958fd..2e18d89 100644 --- a/learning_assistant/platform_imports.py +++ b/learning_assistant/platform_imports.py @@ -59,7 +59,7 @@ def get_cache_course_run_data(course_run_id, fields): return get_course_run_data(course_run_id, fields) -def learning_assistant_available(course_key): +def learning_assistant_available_flag(course_key): """ Return whether the Learning Assistant is available in the course represented by the course_key. diff --git a/learning_assistant/plugins_api.py b/learning_assistant/plugins_api.py index eb334c9..fc03e41 100644 --- a/learning_assistant/plugins_api.py +++ b/learning_assistant/plugins_api.py @@ -7,8 +7,12 @@ imported into and used by the LearningAssistantCourseApp. This way, these implementations can be tested. """ -from learning_assistant.api import learning_assistant_enabled, set_learning_assistant_enabled -from learning_assistant.platform_imports import get_user_role, learning_assistant_available +from learning_assistant.api import ( + learning_assistant_available, + learning_assistant_enabled, + set_learning_assistant_enabled, +) +from learning_assistant.platform_imports import get_user_role from learning_assistant.utils import user_role_is_staff @@ -17,7 +21,8 @@ def is_available(course_key): Return a boolean indicating this course app's availability for a given course. If an app is not available, it will not show up in the UI at all for that course, - and it will not be possible to enable/disable/configure it. + and it will not be possible to enable/disable/configure it, unless the platform wide setting + LEARNING_ASSISTANT_AVAILABLE is set to True. Args: course_key (CourseKey): Course key for course whose availability is being checked. diff --git a/test_settings.py b/test_settings.py index f201fd2..0302e54 100644 --- a/test_settings.py +++ b/test_settings.py @@ -84,3 +84,5 @@ def root(*args): "\"" "{% endif %}" ) + +LEARNING_ASSISTANT_AVAILABLE = True diff --git a/tests/test_api.py b/tests/test_api.py index 3dbadc4..121f488 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -6,7 +6,7 @@ import ddt from django.core.cache import cache -from django.test import TestCase +from django.test import TestCase, override_settings from opaque_keys.edx.keys import CourseKey, UsageKey from learning_assistant.api import ( @@ -14,6 +14,7 @@ _get_children_contents, _leaf_filter, get_block_content, + learning_assistant_available, learning_assistant_enabled, render_prompt_template, set_learning_assistant_enabled, @@ -206,7 +207,7 @@ def test_render_prompt_template(self, unit_content, flag_enabled, mock_get_conte @ddt.ddt class LearningAssistantCourseEnabledApiTests(TestCase): """ - Test suite for the learning_assistant_enabled and set_learning_assistant_enalbed api functions. + Test suite for learning_assistant_available, learning_assistant_enabled, and set_learning_assistant_enabled. """ def setUp(self): super().setUp() @@ -266,3 +267,19 @@ def test_set_learning_assistant_enabled(self, obj_exists, obj_value): obj = LearningAssistantCourseEnabled.objects.get(course_id=self.course_key) self.assertEqual(obj.enabled, obj_value) + + @ddt.idata(itertools.product((True, False), (True, False))) + @ddt.unpack + @patch('learning_assistant.api.learning_assistant_available_flag') + def test_learning_assistant_available( + self, + learning_assistant_available_flag_value, + learning_assistant_available_setting_value, + learning_assistant_available_flag_mock + ): + learning_assistant_available_flag_mock.return_value = learning_assistant_available_flag_value + with override_settings(LEARNING_ASSISTANT_AVAILABLE=learning_assistant_available_setting_value): + return_value = learning_assistant_available(self.course_key) + + expected_value = learning_assistant_available_setting_value or learning_assistant_available_flag_value + self.assertEqual(return_value, expected_value)