Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace waffle flag with setting #67

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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.
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
9 changes: 8 additions & 1 deletion learning_assistant/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion learning_assistant/platform_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
11 changes: 8 additions & 3 deletions learning_assistant/plugins_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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.
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
21 changes: 19 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

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 (
_extract_block_contents,
_get_children_contents,
_leaf_filter,
get_block_content,
learning_assistant_available,
learning_assistant_enabled,
render_prompt_template,
set_learning_assistant_enabled,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Loading