diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 122d15b..73cace2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,10 @@ Change Log Unreleased ********** +3.5.0 - 2024-02-13 +****************** +* Replace course waffle flag with 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..37d9c68 100644 --- a/learning_assistant/api.py +++ b/learning_assistant/api.py @@ -17,7 +17,6 @@ block_leaf_filter, get_single_block, get_text_transcript, - learning_assistant_available, traverse_block_pre_order, ) from learning_assistant.text_utils import html_to_text @@ -118,6 +117,13 @@ def render_prompt_template(request, user_id, course_id, unit_usage_key): return data +def learning_assistant_available(): + """ + Return whether or not the LEARNING_ASSISTANT_AVAILABLE django setting is enabled. + """ + return getattr(settings, 'LEARNING_ASSISTANT_AVAILABLE', False) + + def learning_assistant_enabled(course_key): """ Return whether the Learning Assistant is enabled in the course represented by the course_key. @@ -139,7 +145,7 @@ def learning_assistant_enabled(course_key): # Currently, the Learning Assistant defaults to enabled if there is no override. enabled = True - return learning_assistant_available(course_key) and enabled + return learning_assistant_available() and enabled def set_learning_assistant_enabled(course_key, enabled): diff --git a/learning_assistant/platform_imports.py b/learning_assistant/platform_imports.py index d9958fd..1d18664 100644 --- a/learning_assistant/platform_imports.py +++ b/learning_assistant/platform_imports.py @@ -59,26 +59,6 @@ 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): - """ - Return whether the Learning Assistant is available in the course represented by the course_key. - - Note that this may be different than whether the Learning Assistant is enabled in the course. The value returned by - this fuction represents whether the Learning Assistant is available in the course and, perhaps, whether it is - enabled. Course teams can disable the Learning Assistant via the LearningAssistantCourseEnabled model, so, in those - cases, the Learning Assistant may be available and disabled. - - Arguments: - * course_key (CourseKey): the course's key - - Returns: - * bool: whether the Learning Assistant feature is available - """ - # pylint: disable=import-error, import-outside-toplevel - from lms.djangoapps.courseware.toggles import learning_assistant_is_active - return learning_assistant_is_active(course_key) - - def get_user_role(user, course_key): """ Return the role of the user on the edX platform. diff --git a/learning_assistant/plugins.py b/learning_assistant/plugins.py index c2f3bfe..c078f00 100644 --- a/learning_assistant/plugins.py +++ b/learning_assistant/plugins.py @@ -23,9 +23,9 @@ class LearningAssistantCourseApp(CourseApp): } @classmethod - def is_available(cls, course_key): + def is_available(cls, course_key): # pylint: disable=unused-argument """ - Return a boolean indicating this course app's availability for a given course. + Return a boolean indicating this course app's availability for all courses. 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. @@ -36,7 +36,7 @@ def is_available(cls, course_key): Returns: bool: Availability status of app. """ - return plugins_api.is_available(course_key) + return plugins_api.is_available() @classmethod def is_enabled(cls, course_key): diff --git a/learning_assistant/plugins_api.py b/learning_assistant/plugins_api.py index eb334c9..15e81ec 100644 --- a/learning_assistant/plugins_api.py +++ b/learning_assistant/plugins_api.py @@ -7,25 +7,26 @@ 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 -def is_available(course_key): +def is_available(): """ - Return a boolean indicating this course app's availability for a given course. + Return a boolean indicating this course app's availability for a given installation. - If an app is not available, it will not show up in the UI at all for that course, + If the app is not available, it will not show up in the UI at all for any course, and it will not be possible to enable/disable/configure it. - Args: - course_key (CourseKey): Course key for course whose availability is being checked. - Returns: bool: Availability status of app. """ - return learning_assistant_available(course_key) + return learning_assistant_available() def is_enabled(course_key): 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..477fb9c 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 ( @@ -223,24 +223,21 @@ def setUp(self): (False, False, False, False), ) @ddt.unpack - @patch('learning_assistant.api.learning_assistant_available') def test_learning_assistant_enabled( self, obj_exists, obj_value, learning_assistant_available_value, expected_value, - learning_assistant_available_mock, ): - learning_assistant_available_mock.return_value = learning_assistant_available_value + with override_settings(LEARNING_ASSISTANT_AVAILABLE=learning_assistant_available_value): + if obj_exists: + set_learning_assistant_enabled(self.course_key, obj_value) - if obj_exists: - set_learning_assistant_enabled(self.course_key, obj_value) - - self.assertEqual( - learning_assistant_enabled(self.course_key), - expected_value - ) + self.assertEqual( + learning_assistant_enabled(self.course_key), + expected_value + ) @ddt.idata(itertools.product((True, False), (True, False))) @ddt.unpack diff --git a/tests/test_plugins_api.py b/tests/test_plugins_api.py index f7f14a2..076335d 100644 --- a/tests/test_plugins_api.py +++ b/tests/test_plugins_api.py @@ -31,7 +31,7 @@ def test_is_available(self, is_available_value, learning_assistant_available_moc Test the is_available function of the plugins_api module. """ learning_assistant_available_mock.return_value = is_available_value - self.assertEqual(is_available(self.course_key), is_available_value) + self.assertEqual(is_available(), is_available_value) @ddt.data(True, False) @patch('learning_assistant.plugins_api.learning_assistant_enabled')