Skip to content

Commit 5590f1d

Browse files
committed
refactor: remove the hide dates course field
1 parent d567c5c commit 5590f1d

File tree

6 files changed

+25
-27
lines changed

6 files changed

+25
-27
lines changed

lms/djangoapps/courseware/plugins.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
from opaque_keys.edx.keys import CourseKey
99

1010
from xmodule.modulestore.django import modulestore
11+
from xmodule.tabs import CourseTabList
12+
13+
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview, CourseTab
1114

12-
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
1315
from openedx.core.djangoapps.course_apps.plugins import CourseApp
1416
from openedx.core.lib.courses import get_course_by_id
1517

@@ -87,15 +89,22 @@ def is_enabled(cls, course_key: CourseKey) -> bool:
8789
"""
8890
The dates course status is stored in the course block.
8991
"""
90-
return not CourseOverview.get_from_id(course_key).hide_dates_tab
92+
course = get_course_by_id(course_key)
93+
dates_tab = CourseTabList.get_tab_by_id(course.tabs, 'dates')
94+
return bool(dates_tab and not dates_tab.is_hidden)
9195

9296
@classmethod
9397
def set_enabled(cls, course_key: CourseKey, enabled: bool, user: 'User') -> bool:
9498
"""
9599
The dates course enabled/disabled status is stored in the course block.
96100
"""
97101
course = get_course_by_id(course_key)
98-
course.hide_dates_tab = not enabled
102+
dates_tab = CourseTabList.get_tab_by_id(course.tabs, 'dates')
103+
if enabled and dates_tab is None:
104+
dates_tab = CourseTab.load("dates")
105+
course.tabs.append(dates_tab)
106+
if dates_tab is not None:
107+
dates_tab.is_hidden = not enabled
99108
modulestore().update_item(course, user.id)
100109
return enabled
101110

lms/djangoapps/courseware/tabs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ def link_func(course, _reverse_func):
320320
def is_enabled(cls, course, user=None):
321321
if not super().is_enabled(course, user=user):
322322
return False
323-
return not getattr(course, 'hide_dates_tab', False)
324-
323+
dates_tab = CourseTabList.get_tab_by_id(course.tabs, 'dates')
324+
return bool(dates_tab and not dates_tab.is_hidden)
325325

326326
def get_course_tab_list(user, course):
327327
"""

lms/djangoapps/courseware/tests/test_tabs.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,6 @@ def test_singular_dates_tab(self):
870870
"""Test cases for making sure no persisted dates tab is surfaced"""
871871
user = self.create_mock_user()
872872
self.course.tabs = self.all_valid_tab_list
873-
self.course.hide_dates_tab = False
874873
self.course.save()
875874

876875
# Verify that there is a dates tab in the modulestore
@@ -890,13 +889,18 @@ def test_singular_dates_tab(self):
890889

891890
@patch('common.djangoapps.student.models.course_enrollment.CourseEnrollment.is_enrolled')
892891
def test_dates_tab_respects_hide_flag(self, is_enrolled):
893-
tab = DatesTab({'type': DatesTab.type, 'name': 'dates'})
894-
892+
"""Test that the dates tab respects the hide flag."""
895893
is_enrolled.return_value = True
896894
user = self.create_mock_user(is_staff=False, is_enrolled=True)
895+
self.course.tabs = self.all_valid_tab_list
896+
dates_tab = xmodule_tabs.CourseTabList.get_tab_by_id(self.course.tabs, 'dates')
897+
assert dates_tab is not None
897898

898-
self.course.hide_dates_tab = False
899-
assert self.is_tab_enabled(tab, self.course, user)
899+
dates_tab.is_hidden = False
900+
self.course.save()
901+
tabs = get_course_tab_list(user, self.course)
902+
assert any(tab.type == 'dates' for tab in tabs)
900903

901-
self.course.hide_dates_tab = True
902-
assert not self.is_tab_enabled(tab, self.course, user)
904+
dates_tab.is_hidden = True
905+
tabs = get_course_tab_list(user, self.course)
906+
assert not any(tab.type == 'dates' for tab in tabs)

lms/envs/common.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2779,7 +2779,6 @@
27792779
# .. setting_description: Content to replace spam posts with
27802780
CONTENT_FOR_SPAM_POSTS = ""
27812781

2782-
27832782
# .. toggle_name: ENABLE_AUTHN_RESET_PASSWORD_HIBP_POLICY
27842783
# .. toggle_implementation: DjangoSetting
27852784
# .. toggle_default: False

openedx/core/djangoapps/content/course_overviews/models.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -943,13 +943,6 @@ def hide_progress_tab(self):
943943
"""
944944
return self._original_course.hide_progress_tab
945945

946-
@property
947-
def hide_dates_tab(self):
948-
"""
949-
TODO: move this to the model.
950-
"""
951-
return self._original_course.hide_dates_tab
952-
953946
@property
954947
def edxnotes(self):
955948
"""

xmodule/course_block.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -727,13 +727,6 @@ class CourseFields: # lint-amnesty, pylint: disable=missing-class-docstring
727727
deprecated=True
728728
)
729729

730-
hide_dates_tab = Boolean(
731-
display_name=_("Hide Dates Tab"),
732-
help=_("Allows hiding of the dates tab."),
733-
scope=Scope.settings,
734-
deprecated=True
735-
)
736-
737730
display_organization = String(
738731
display_name=_("Course Organization Display String"),
739732
help=_(

0 commit comments

Comments
 (0)