Skip to content

Commit

Permalink
Fix the enable_fullscreen XBlock attribute override
Browse files Browse the repository at this point in the history
  • Loading branch information
Maari Tamm committed Dec 15, 2023
1 parent a39313e commit 5fe4d6a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Unreleased
-------------------------
* [Bug fix] Fix `enable_fullscreen` setting overrides via the XBlock
attribute.

Version 7.8.0 (2023-12-13)
-------------------------
* [Enhancement] Add an option to launch the lab in a new window.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ The following are optional:
the lab environment in the background. Default is `False`.

* `enable_fullscreen`: An option to allow learners to launch a lab in fullsceen mode,
in a separate browser window. Overrides the globally defined setting.
Default is `False`.
in a separate browser window. If used, overrides the globally defined setting.
Options are "true", "false" and "inherit". Default is "inherit" (to use global value).

* `progress_check_label`: Set a label for the progress check button.
For example: `Submit Answer` or `Check Progress` (Default).
Expand Down
22 changes: 15 additions & 7 deletions hastexo/hastexo.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ class HastexoXBlock(XBlock,
"not display hints and feedback. Default is \"Progress check "
"result\"."
)
enable_fullscreen = Boolean(
default=False,
enable_fullscreen = String(
values=["true", "false", "inherit"],
default="inherit",
scope=Scope.settings,
help="Enable the learners to launch a lab in fulscreen mode on a "
"separate browser window. Overrides the globally defined setting."
Expand Down Expand Up @@ -549,6 +550,17 @@ def get_delete_age(self, settings):
# delete_age value in settings is in days, convert to seconds
return settings.get("delete_age", 14) * 86400

def get_enable_fullscreen(self, settings):
"""
Return 'enable_fullscreen' mode value. XBlock attribute
overrides the global setting, if not set to inherit the global setting.
"""
enable_fullscreen = settings.get("enable_fullscreen", False)
if self.enable_fullscreen != "inherit":
enable_fullscreen = bool(strtobool(self.enable_fullscreen))

return enable_fullscreen

def get_suspend_timeout(self):
"""
Return 'suspend_timeout' in seconds.
Expand Down Expand Up @@ -675,11 +687,7 @@ def student_view(self, context=None):
self.stack_run = "%s_%s" % (course_id.course, course_id.run)
self.stack_name = self.get_stack_name()

# Fullscreen mode: if the XBlock attribute does not match the global
# setting, allow it override the value per instance
enable_fullscreen = settings.get("enable_fullscreen")
if enable_fullscreen != self.enable_fullscreen:
enable_fullscreen = self.enable_fullscreen
enable_fullscreen = self.get_enable_fullscreen(settings)

frag = Fragment()

Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_hastexo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1658,3 +1658,22 @@ def test_launch_new_window(self):
response = self.block.launch_new_window(request)

self.assertEqual("200 OK", response.status)

def test_fullscreen_setting(self):
self.init_block()
settings = get_xblock_settings()
enable_fullscreen = self.block.get_enable_fullscreen(settings)

# by default the setting is to be inherited from global settings
self.assertEqual("inherit", self.block.enable_fullscreen)
self.assertEqual(settings.get("enable_fullscreen"), enable_fullscreen)

# If the XBlock attribute is used to enable/disable the feature
# the attribute value is used
self.block.enable_fullscreen = "true"
enable_fullscreen = self.block.get_enable_fullscreen(settings)
self.assertEqual(True, enable_fullscreen)

self.block.enable_fullscreen = "false"
enable_fullscreen = self.block.get_enable_fullscreen(settings)
self.assertEqual(False, enable_fullscreen)

0 comments on commit 5fe4d6a

Please sign in to comment.