Skip to content

Commit

Permalink
feat: remove use of course waffle flag
Browse files Browse the repository at this point in the history
  • Loading branch information
alangsto committed Feb 21, 2024
1 parent 126ff5b commit 347892e
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 42 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Change Log
Unreleased
**********

4.0.0 - 2024-02-21
******************
* Remove use of course waffle flag. Use the django setting LEARNING_ASSISTANT_AVAILABLE
to enable the learning assistant feature.

3.6.0 - 2024-02-13
******************
* Enable backend access by course waffle flag or django setting.
Expand Down
2 changes: 1 addition & 1 deletion learning_assistant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Plugin for a learning assistant backend, intended for use within edx-platform.
"""

__version__ = '3.6.0'
__version__ = '4.0.0'

default_app_config = 'learning_assistant.apps.LearningAssistantConfig' # pylint: disable=invalid-name
7 changes: 3 additions & 4 deletions learning_assistant/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
block_leaf_filter,
get_single_block,
get_text_transcript,
learning_assistant_available_flag,
traverse_block_pre_order,
)
from learning_assistant.text_utils import html_to_text
Expand Down Expand Up @@ -118,11 +117,11 @@ def render_prompt_template(request, user_id, course_id, unit_usage_key):
return data


def learning_assistant_available(course_key):
def learning_assistant_available():
"""
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)
return getattr(settings, 'LEARNING_ASSISTANT_AVAILABLE', False)


def learning_assistant_enabled(course_key):
Expand All @@ -146,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):
Expand Down
20 changes: 0 additions & 20 deletions learning_assistant/platform_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_flag(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.
Expand Down
4 changes: 2 additions & 2 deletions learning_assistant/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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.
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions learning_assistant/plugins_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
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.
Expand All @@ -30,7 +30,7 @@ def is_available(course_key):
Returns:
bool: Availability status of app.
"""
return learning_assistant_available(course_key)
return learning_assistant_available()


def is_enabled(course_key):
Expand Down
19 changes: 7 additions & 12 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,13 @@ 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
@ddt.data(
True,
False
)
def test_learning_assistant_available(self, learning_assistant_available_setting_value):
with override_settings(LEARNING_ASSISTANT_AVAILABLE=learning_assistant_available_setting_value):
return_value = learning_assistant_available(self.course_key)
return_value = learning_assistant_available()

expected_value = learning_assistant_available_setting_value or learning_assistant_available_flag_value
expected_value = learning_assistant_available_setting_value
self.assertEqual(return_value, expected_value)
2 changes: 1 addition & 1 deletion tests/test_plugins_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 347892e

Please sign in to comment.