Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to set hideElements cookie #1416

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions common/djangoapps/student/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
8 changes: 5 additions & 3 deletions openedx/core/djangoapps/user_authn/views/login_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Loading