Skip to content

Commit

Permalink
Merge pull request #1416 from appsembler/vladyslav/hide-html-elements…
Browse files Browse the repository at this point in the history
…-in-iframe

Add function to set hideElements cookie
  • Loading branch information
VladyslavTy authored Aug 27, 2024
2 parents a45bf9b + 27d9bd4 commit 1e3bded
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
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

0 comments on commit 1e3bded

Please sign in to comment.