From a52b25779d9394219ce12655a9474ca311c677e6 Mon Sep 17 00:00:00 2001 From: polesye Date: Mon, 23 Jun 2014 18:24:53 +0300 Subject: [PATCH] Use confirm dialogue. --- lms/djangoapps/courseware/module_render.py | 4 ++-- lms/static/js/ajax-error.js | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index 880cf5d3e9..e3a7bcd8c2 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -628,13 +628,13 @@ def handle_xblock_callback(request, course_id, usage_id, handler, suffix=None): - location -- the module location. Used to look up the XModule instance - course_id -- defines the course context for this request. - Return 401 error if the user is not logged in. Raises Http404 if + Return 403 error if the user is not logged in. Raises Http404 if the location and course_id do not identify a valid module, the module is not accessible by the user, or the module raises NotFoundError. If the module raises any other error, it will escape this function. """ if not request.user.is_authenticated(): - return HttpResponse('Unauthorized', status=401) + return HttpResponse('Unauthenticated', status=403) return _invoke_xblock_handler(request, course_id, usage_id, handler, suffix, request.user) diff --git a/lms/static/js/ajax-error.js b/lms/static/js/ajax-error.js index e1d0b48f86..3e7202a156 100644 --- a/lms/static/js/ajax-error.js +++ b/lms/static/js/ajax-error.js @@ -1,6 +1,15 @@ $(document).ajaxError(function (event, jXHR) { - if (jXHR.status === 401) { - alert(gettext("You're logged out. Redirecting on login page.")); - window.location.href = '/accounts/login?next=' + window.location.href; + if (jXHR.status === 403 && jXHR.responseText === 'Unauthenticated') { + var message = gettext( + 'You have been logged out of your edX account. '+ + 'Click Okay to log in again now. '+ + 'Click Cancel to stay on this page '+ + '(you must log in again to save your work).' + ); + + if (window.confirm(message)) { + var currentLocation = window.location.href; + window.location.href = '/accounts/login?next=' + currentLocation; + }; } });