forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [ACADEMIC-16209] Unit summary settings (openedx#32855)
* feat: [ACADEMIC-16209] Unit summary settings [https://jira.2u.com/browse/ACADEMIC-16209](https://jira.2u.com/browse/ACADEMIC-16209) 1. Add unit xpert unit summaries settings behind flag `summaryhook_summaries_configuration` added [here](https://github.com/edx/ai-aside/pull/45/files) 2. Only show the checkbox when the value is a `boolean` otherwise the feature is considerer `disabled` by the flag. 3. Update block handler to update this value via `api` exposed [here](edx/ai-aside#43) 4. Create `AiAsideSummary` configuration class to provide access to the `ai_aside.api` endpoints.
- Loading branch information
1 parent
d60cdc2
commit 3f20c75
Showing
10 changed files
with
237 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" | ||
This file contains AiAsideSummaryConfig class that take a `course_key` and return if: | ||
* the waffle flag is enabled in ai_aside | ||
* is the summary is enabled for a given unit_key | ||
* change the settings for a given unit_key | ||
""" | ||
|
||
|
||
class AiAsideSummaryConfig: | ||
""" | ||
Configuration for the AI Aside summary configuration. | ||
""" | ||
|
||
def __init__(self, course_key): | ||
self.course_key = course_key | ||
|
||
def __str__(self): | ||
""" | ||
Return user-friendly string. | ||
""" | ||
return f"AIAside summary configuration for {self.course_key} course" | ||
|
||
def is_enabled(self): | ||
""" | ||
Define if the waffle flag is enabled for the current course_key | ||
""" | ||
try: | ||
from ai_aside.config_api.api import is_summary_config_enabled | ||
return is_summary_config_enabled(self.course_key) | ||
except (ModuleNotFoundError, ImportError): | ||
return False | ||
|
||
def is_summary_enabled(self, unit_key=None): | ||
""" | ||
Define if the summary configuration is enabled in ai_aside | ||
""" | ||
try: | ||
from ai_aside.config_api.api import is_course_settings_present, is_summary_enabled | ||
if not is_course_settings_present(self.course_key): | ||
return None | ||
return is_summary_enabled(self.course_key, unit_key) | ||
except (ModuleNotFoundError, ImportError): | ||
return None | ||
|
||
def set_summary_settings(self, unit_key, settings=None): | ||
""" | ||
Define the settings for a given unit_key in ai_aside | ||
""" | ||
if settings is None: | ||
return None | ||
|
||
try: | ||
from ai_aside.config_api.api import set_unit_settings | ||
return set_unit_settings(self.course_key, unit_key, settings) | ||
except (ModuleNotFoundError, ImportError): | ||
return None |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" | ||
Tests for AiAsideSummaryConfig class. | ||
""" | ||
|
||
|
||
import sys | ||
from unittest import TestCase | ||
from unittest.mock import Mock | ||
|
||
from opaque_keys.edx.keys import CourseKey, UsageKey | ||
|
||
from cms.lib.ai_aside_summary_config import AiAsideSummaryConfig | ||
|
||
ai_aside = Mock() | ||
sys.modules['ai_aside.config_api.api'] = ai_aside | ||
|
||
|
||
class AiAsideSummaryConfigTestCase(TestCase): | ||
""" Tests for AiAsideSummaryConfig. """ | ||
COURSE_KEY = CourseKey.from_string("course-v1:test+Test+AiAsideSummaryConfigTestCase") | ||
UNIT_KEY = UsageKey.from_string("block-v1:test+Test+AiAsideSummaryConfigTestCase+type@vertical+block@vertical_test") | ||
|
||
def test_is_enabled(self): | ||
""" | ||
Check if summary configuration is enabled using the ai_aside lib. | ||
""" | ||
ai_aside_summary_config = AiAsideSummaryConfig(self.COURSE_KEY) | ||
ai_aside.is_summary_config_enabled.return_value = True | ||
self.assertTrue(ai_aside_summary_config.is_enabled()) | ||
|
||
ai_aside.is_summary_config_enabled.return_value = False | ||
self.assertFalse(ai_aside_summary_config.is_enabled()) | ||
|
||
def test_is_summary_enabled(self): | ||
""" | ||
Check the summary configuration value for a particular course and an optional unit using the ai_aside lib. | ||
""" | ||
ai_aside_summary_config = AiAsideSummaryConfig(self.COURSE_KEY) | ||
ai_aside.is_course_settings_present.return_value = True | ||
ai_aside.is_summary_enabled.return_value = True | ||
self.assertTrue(ai_aside_summary_config.is_summary_enabled()) | ||
|
||
ai_aside.is_course_settings_present.return_value = True | ||
ai_aside.is_summary_enabled.return_value = False | ||
self.assertFalse(ai_aside_summary_config.is_summary_enabled(self.UNIT_KEY)) | ||
|
||
ai_aside.is_course_settings_present.return_value = False | ||
ai_aside.is_summary_enabled.return_value = True | ||
self.assertIsNone(ai_aside_summary_config.is_summary_enabled()) | ||
|
||
ai_aside.is_course_settings_present.return_value = False | ||
ai_aside.is_summary_enabled.return_value = False | ||
self.assertIsNone(ai_aside_summary_config.is_summary_enabled(self.UNIT_KEY)) | ||
|
||
def test_set_summary_settings(self): | ||
""" | ||
Set the summary configuration settings for a particular unit using the ai_aside lib. | ||
""" | ||
ai_aside_summary_config = AiAsideSummaryConfig(self.COURSE_KEY) | ||
ai_aside.set_unit_settings.return_value = True | ||
self.assertTrue(ai_aside_summary_config.set_summary_settings(self.UNIT_KEY, {})) | ||
self.assertIsNone(ai_aside_summary_config.set_summary_settings(self.UNIT_KEY)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<form> | ||
<h3 class="modal-section-title"> | ||
<%- gettext('Xpert unit summaries') %> | ||
</h3> | ||
<div class="modal-section-content summary-configuration"> | ||
<label class="label"> | ||
<input type="checkbox" id="summary_configuration_enabled" name="summary_configuration_enabled" class="input input-checkbox" /> | ||
<%- gettext('Enable summaries') %> | ||
</label> | ||
</div> | ||
</form> |