Skip to content

Commit

Permalink
feat: replace waffle flag with setting
Browse files Browse the repository at this point in the history
  • Loading branch information
alangsto committed Feb 14, 2024
1 parent 9ed1be3 commit 267f981
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 47 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.5.0'
__version__ = '3.6.0'

default_app_config = 'learning_assistant.apps.LearningAssistantConfig' # pylint: disable=invalid-name
10 changes: 8 additions & 2 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,
traverse_block_pre_order,
)
from learning_assistant.text_utils import html_to_text
Expand Down Expand Up @@ -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.
Expand All @@ -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):
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(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
6 changes: 3 additions & 3 deletions learning_assistant/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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
19 changes: 10 additions & 9 deletions learning_assistant/plugins_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,5 @@ def root(*args):
"\""
"{% endif %}"
)

LEARNING_ASSISTANT_AVAILABLE = True
19 changes: 8 additions & 11 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
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 267f981

Please sign in to comment.