Skip to content

Commit 27d9bd4

Browse files
author
Vladyslav Tymofeiev
committed
Add function add_hide_elements_cookie_to_redirect to set hideElements cookie on the backend side
1 parent 4efbe09 commit 27d9bd4

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

common/djangoapps/student/helpers.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from django.core.exceptions import PermissionDenied
2020
from django.core.validators import ValidationError
2121
from django.db import IntegrityError, transaction
22+
from django.shortcuts import redirect
2223
from django.urls import NoReverseMatch, reverse
2324
from django.utils.translation import ugettext as _
2425
from pytz import UTC
@@ -739,3 +740,16 @@ def sanitize_next_parameter(next_param):
739740
return sanitized_next_parameter
740741

741742
return next_param
743+
744+
745+
def add_hide_elements_cookie_to_redirect(redirect_to):
746+
if 'hide_elements' in redirect_to:
747+
# Perform the redirect and set the cookie only if 'hide_elements' is present
748+
response = redirect(redirect_to)
749+
750+
# Set a cookie to indicate that elements should be hidden
751+
response.set_cookie('hideElements', 'true', max_age=86400)
752+
753+
return response
754+
else:
755+
return redirect(redirect_to)

openedx/core/djangoapps/user_authn/views/login_form.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
handle_enterprise_cookies_for_logistration,
3131
update_logistration_context_for_enterprise
3232
)
33-
from student.helpers import get_next_url_for_login_page
33+
from student.helpers import get_next_url_for_login_page, add_hide_elements_cookie_to_redirect
3434
from third_party_auth import pipeline
3535
from third_party_auth.decorators import xframe_allow_whitelisted
3636
from util.password_policy_validators import DEFAULT_MAX_PASSWORD_LENGTH
@@ -146,12 +146,14 @@ def login_and_registration_form(request, initial_mode="login"):
146146
# since Django's SessionAuthentication middleware auto-updates session cookies but not
147147
# the other login-related cookies. See ARCH-282.
148148
if request.user.is_authenticated and are_logged_in_cookies_set(request):
149-
return redirect(redirect_to)
149+
response = add_hide_elements_cookie_to_redirect(redirect_to)
150+
return response
150151

151152
# Tahoe: Disable upstream login/register forms when the Tahoe Identity Provider is enabled.
152153
tahoe_idp_redirect_url = tahoe_idp_helpers.get_idp_form_url(request, initial_mode, redirect_to)
153154
if tahoe_idp_redirect_url:
154-
return redirect(tahoe_idp_redirect_url)
155+
response = add_hide_elements_cookie_to_redirect(tahoe_idp_redirect_url)
156+
return response
155157

156158
# Retrieve the form descriptions from the user API
157159
form_descriptions = _get_form_descriptions(request)

0 commit comments

Comments
 (0)