From 6b5df8931cf96134df9974dfb2f1742d6c12faa1 Mon Sep 17 00:00:00 2001 From: Moncef Abboud Date: Tue, 16 Apr 2024 17:04:12 +0200 Subject: [PATCH 1/2] feat: tpa automatic logout with a single redirect --- .../core/djangoapps/user_authn/views/logout.py | 17 ++++++----------- .../user_authn/views/tests/test_logout.py | 6 ++++-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/openedx/core/djangoapps/user_authn/views/logout.py b/openedx/core/djangoapps/user_authn/views/logout.py index 13301f5e3bb1..0e67857d91f1 100644 --- a/openedx/core/djangoapps/user_authn/views/logout.py +++ b/openedx/core/djangoapps/user_authn/views/logout.py @@ -8,7 +8,6 @@ import bleach from django.conf import settings from django.contrib.auth import logout -from django.shortcuts import redirect from django.utils.http import urlencode from django.views.generic import TemplateView from oauth2_provider.models import Application @@ -47,7 +46,13 @@ def target(self): If a redirect_url is specified in the querystring for this request, and the value is a safe url for redirect, the view will redirect to this page after rendering the template. If it is not specified, we will use the default target url. + Redirect to tpa_logout_url if TPA_AUTOMATIC_LOGOUT_ENABLED is set to True and if + tpa_logout_url is configured. """ + + if getattr(settings, 'TPA_AUTOMATIC_LOGOUT_ENABLED', False) and self.tpa_logout_url: + return self.tpa_logout_url + target_url = self.request.GET.get('redirect_url') or self.request.GET.get('next') # Some third party apps do not build URLs correctly and send next query param without URL-encoding, resulting @@ -85,16 +90,6 @@ def dispatch(self, request, *args, **kwargs): mark_user_change_as_expected(None) - # Redirect to tpa_logout_url if TPA_AUTOMATIC_LOGOUT_ENABLED is set to True and if - # tpa_logout_url is configured. - # - # NOTE: This step skips rendering logout.html, which is used to log the user out from the - # different IDAs. To ensure the user is logged out of all the IDAs be sure to redirect - # back to /logout after logging out of the TPA. - if getattr(settings, 'TPA_AUTOMATIC_LOGOUT_ENABLED', False): - if self.tpa_logout_url: - return redirect(self.tpa_logout_url) - return response def _build_logout_url(self, url): diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_logout.py b/openedx/core/djangoapps/user_authn/views/tests/test_logout.py index 7d10fe1021ef..5de084d108e6 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_logout.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_logout.py @@ -211,8 +211,10 @@ def test_automatic_tpa_logout_url_redirect(self): mock_idp_logout_url.return_value = idp_logout_url self._authenticate_with_oauth(client) response = self.client.get(reverse('logout')) - assert response.status_code == 302 - assert response.url == idp_logout_url + expected = { + 'target': idp_logout_url, + } + self.assertDictContainsSubset(expected, response.context_data) @mock.patch('django.conf.settings.TPA_AUTOMATIC_LOGOUT_ENABLED', True) def test_no_automatic_tpa_logout_without_logout_url(self): From 0e8e9f5fd6bc70402ee80bac91892b6357344e13 Mon Sep 17 00:00:00 2001 From: Maxim Beder Date: Mon, 15 Apr 2024 21:56:07 +0200 Subject: [PATCH 2/2] feat: add a feature flag to disable dates tab for all courses --- lms/djangoapps/courseware/tabs.py | 6 ++++++ lms/djangoapps/courseware/tests/test_tabs.py | 13 +++++++++++++ lms/envs/common.py | 9 +++++++++ 3 files changed, 28 insertions(+) diff --git a/lms/djangoapps/courseware/tabs.py b/lms/djangoapps/courseware/tabs.py index 2a67b6454e42..de38871832c1 100644 --- a/lms/djangoapps/courseware/tabs.py +++ b/lms/djangoapps/courseware/tabs.py @@ -315,6 +315,12 @@ def link_func(course, _reverse_func): tab_dict['link_func'] = link_func super().__init__(tab_dict) + @classmethod + def is_enabled(cls, course, user=None): + if settings.FEATURES.get('DISABLE_DATES_TAB'): + return False + return super().is_enabled(course, user) + def get_course_tab_list(user, course): """ diff --git a/lms/djangoapps/courseware/tests/test_tabs.py b/lms/djangoapps/courseware/tests/test_tabs.py index db59fa373bc5..e7a8e58c1371 100644 --- a/lms/djangoapps/courseware/tests/test_tabs.py +++ b/lms/djangoapps/courseware/tests/test_tabs.py @@ -885,3 +885,16 @@ def test_singular_dates_tab(self): if tab.type == 'dates': num_dates_tabs += 1 assert num_dates_tabs == 1 + + def test_dates_tab_is_enabled_by_default(self): + """Test dates tab is enabled by default.""" + tab = DatesTab({'type': DatesTab.type, 'name': 'dates'}) + user = self.create_mock_user() + assert self.is_tab_enabled(tab, self.course, user) + + @patch.dict("django.conf.settings.FEATURES", {"DISABLE_DATES_TAB": True}) + def test_dates_tab_disabled_by_feature_flag(self): + """Test dates tab is disabled by the feature flag.""" + tab = DatesTab({'type': DatesTab.type, 'name': 'dates'}) + user = self.create_mock_user() + assert not self.is_tab_enabled(tab, self.course, user) diff --git a/lms/envs/common.py b/lms/envs/common.py index c5870d3f1b38..2c867bc6f4f7 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1081,6 +1081,15 @@ # .. toggle_target_removal_date: None # .. toggle_tickets: 'https://github.com/open-craft/edx-platform/pull/632/files' 'ENABLE_TEACHING_ASSISTANT_ROLE': False, + + # .. toggle_name: FEATURES['DISABLE_DATES_TAB'] + # .. toggle_implementation: DjangoSetting + # .. toggle_default: False + # .. toggle_description: Disables dates tab for all courses. + # .. toggle_use_cases: open_edx + # .. toggle_creation_date: 2024-04-15 + # .. toggle_tickets: https://github.com/openedx/edx-platform/pull/34511 + 'DISABLE_DATES_TAB': False, } # Specifies extra XBlock fields that should available when requested via the Course Blocks API