From 27d9bd4c04199947fae31c25d6c464d96b4b7ef0 Mon Sep 17 00:00:00 2001 From: Vladyslav Tymofeiev <“vladyslavty@softwareplanetgroup.com”> Date: Tue, 27 Aug 2024 15:12:50 +0300 Subject: [PATCH] Add function add_hide_elements_cookie_to_redirect to set hideElements cookie on the backend side --- common/djangoapps/student/helpers.py | 14 ++++++++++++++ .../core/djangoapps/user_authn/views/login_form.py | 8 +++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/common/djangoapps/student/helpers.py b/common/djangoapps/student/helpers.py index 354c9a328d1..a2ff280c7aa 100644 --- a/common/djangoapps/student/helpers.py +++ b/common/djangoapps/student/helpers.py @@ -19,6 +19,7 @@ from django.core.exceptions import PermissionDenied from django.core.validators import ValidationError from django.db import IntegrityError, transaction +from django.shortcuts import redirect from django.urls import NoReverseMatch, reverse from django.utils.translation import ugettext as _ from pytz import UTC @@ -739,3 +740,16 @@ def sanitize_next_parameter(next_param): return sanitized_next_parameter return next_param + + +def add_hide_elements_cookie_to_redirect(redirect_to): + if 'hide_elements' in redirect_to: + # Perform the redirect and set the cookie only if 'hide_elements' is present + response = redirect(redirect_to) + + # Set a cookie to indicate that elements should be hidden + response.set_cookie('hideElements', 'true', max_age=86400) + + return response + else: + return redirect(redirect_to) diff --git a/openedx/core/djangoapps/user_authn/views/login_form.py b/openedx/core/djangoapps/user_authn/views/login_form.py index 3292f14da64..05e6d0cebb3 100644 --- a/openedx/core/djangoapps/user_authn/views/login_form.py +++ b/openedx/core/djangoapps/user_authn/views/login_form.py @@ -30,7 +30,7 @@ handle_enterprise_cookies_for_logistration, update_logistration_context_for_enterprise ) -from student.helpers import get_next_url_for_login_page +from student.helpers import get_next_url_for_login_page, add_hide_elements_cookie_to_redirect from third_party_auth import pipeline from third_party_auth.decorators import xframe_allow_whitelisted from util.password_policy_validators import DEFAULT_MAX_PASSWORD_LENGTH @@ -146,12 +146,14 @@ def login_and_registration_form(request, initial_mode="login"): # since Django's SessionAuthentication middleware auto-updates session cookies but not # the other login-related cookies. See ARCH-282. if request.user.is_authenticated and are_logged_in_cookies_set(request): - return redirect(redirect_to) + response = add_hide_elements_cookie_to_redirect(redirect_to) + return response # Tahoe: Disable upstream login/register forms when the Tahoe Identity Provider is enabled. tahoe_idp_redirect_url = tahoe_idp_helpers.get_idp_form_url(request, initial_mode, redirect_to) if tahoe_idp_redirect_url: - return redirect(tahoe_idp_redirect_url) + response = add_hide_elements_cookie_to_redirect(tahoe_idp_redirect_url) + return response # Retrieve the form descriptions from the user API form_descriptions = _get_form_descriptions(request)