diff --git a/authentication/pipeline/user.py b/authentication/pipeline/user.py index 4ca966802a..40f9a7a9dc 100644 --- a/authentication/pipeline/user.py +++ b/authentication/pipeline/user.py @@ -218,7 +218,7 @@ def forbid_hijack(strategy, backend, **kwargs): # pylint: disable=unused-argume backend (social_core.backends.base.BaseAuth): the backend being used to authenticate """ # As first step in pipeline, stop a hijacking admin from going any further - if strategy.session_get("is_hijacked_user"): + if bool(strategy.session_get("hijack_history")): raise AuthException("You are hijacking another user, don't try to login again") # noqa: EM101 return {} diff --git a/authentication/views.py b/authentication/views.py index 2fecc6b000..72dec89ca6 100644 --- a/authentication/views.py +++ b/authentication/views.py @@ -48,7 +48,7 @@ def get_serializer_cls(self): # pragma: no cover def post(self, request): """Processes a request""" - if request.session.get("is_hijacked_user", False): + if bool(request.session.get("hijack_history")): return Response(status=status.HTTP_403_FORBIDDEN) serializer_cls = self.get_serializer_cls() @@ -90,7 +90,7 @@ def get_serializer_cls(self): def post(self, request): """Verify recaptcha response before proceeding""" - if request.session.get("is_hijacked_user", False): + if bool(request.session.get("hijack_history")): return Response(status=status.HTTP_403_FORBIDDEN) if settings.RECAPTCHA_SITE_KEY: r = requests.post( # noqa: S113 diff --git a/authentication/views_test.py b/authentication/views_test.py index 5ed05f0797..3a89984f5d 100644 --- a/authentication/views_test.py +++ b/authentication/views_test.py @@ -589,7 +589,7 @@ def test_login_email_error(client, mocker): def test_login_email_hijacked(client, user, admin_user): """Test that a 403 response is returned for email login view if user is hijacked""" client.force_login(admin_user) - client.post(f"/hijack/{user.id}/") + client.post("/hijack/acquire/", {"user_pk": user.id}) response = client.post( reverse("psa-login-email"), {"flow": SocialAuthState.FLOW_LOGIN, "email": "anything@example.com"}, @@ -600,7 +600,7 @@ def test_login_email_hijacked(client, user, admin_user): def test_register_email_hijacked(client, user, admin_user): """Test that a 403 response is returned for email register view if user is hijacked""" client.force_login(admin_user) - client.post(f"/hijack/{user.id}/") + client.post("/hijack/acquire/", {"user_pk": user.id}) response = client.post( reverse("psa-register-email"), {"flow": SocialAuthState.FLOW_LOGIN, "email": "anything@example.com"}, diff --git a/cms/models_test.py b/cms/models_test.py index 11abe9a5d6..2ad3bf42f7 100644 --- a/cms/models_test.py +++ b/cms/models_test.py @@ -166,6 +166,7 @@ def test_course_page_context( # noqa: PLR0913 "can_access_edx_course": is_authenticated and has_relevant_run, "finaid_price": finaid_price, "product": product, + "hijack_logout_redirect_url": "/admin/users/user", "instructors": [] if not has_instructor else [ diff --git a/frontend/public/scss/common.scss b/frontend/public/scss/common.scss index 9be5a4080e..f1e2f0dc64 100644 --- a/frontend/public/scss/common.scss +++ b/frontend/public/scss/common.scss @@ -261,3 +261,18 @@ button.btn-secondary.unstyled { .display-none { display: none !important; } + +.djhj { + position: relative !important; + top: 0; + + .djhj-message, .djhj-actions { + width: fit-content; + } + + .djhj-notification { + max-width: unset; + background: $navy-blue; + margin: 0; + } +} diff --git a/main/settings.py b/main/settings.py index 6c156307ff..0552268302 100644 --- a/main/settings.py +++ b/main/settings.py @@ -200,9 +200,8 @@ # "compliance", "openedx", # must be after "users" to pick up custom user model - "compat", "hijack", - "hijack_admin", + "hijack.contrib.admin", "ecommerce", "flexiblepricing", "micromasters_import", @@ -235,6 +234,7 @@ "django.middleware.clickjacking.XFrameOptionsMiddleware", "django.contrib.sites.middleware.CurrentSiteMiddleware", "django_user_agents.middleware.UserAgentMiddleware", + "hijack.middleware.HijackUserMiddleware", "main.middleware.CachelessAPIMiddleware", "wagtail.contrib.redirects.middleware.RedirectMiddleware", ) diff --git a/main/templates/base.html b/main/templates/base.html index 7561cfecaf..6493c66a33 100644 --- a/main/templates/base.html +++ b/main/templates/base.html @@ -1,4 +1,4 @@ -{% load static hijack_tags js_interop %} +{% load static hijack js_interop %} {% load wagtailcore_tags startswith noindex_meta banner %} {% load render_bundle from webpack_loader %} @@ -33,7 +33,8 @@