Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
8201c990
Commit
8201c990
authored
Jul 01, 2014
by
Anton Stupak
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4038 from edx/anton/redirect-on-error
Add 401 error handler.
parents
b989ec14
584da69b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
3 deletions
+19
-3
lms/djangoapps/courseware/module_render.py
+2
-3
lms/djangoapps/courseware/tests/test_module_render.py
+1
-0
lms/envs/common.py
+1
-0
lms/static/js/ajax-error.js
+15
-0
No files found.
lms/djangoapps/courseware/module_render.py
View file @
8201c990
...
@@ -12,7 +12,6 @@ from opaque_keys import InvalidKeyError
...
@@ -12,7 +12,6 @@ from opaque_keys import InvalidKeyError
from
django.conf
import
settings
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.cache
import
cache
from
django.core.cache
import
cache
from
django.core.exceptions
import
PermissionDenied
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.http
import
Http404
,
HttpResponse
from
django.http
import
Http404
,
HttpResponse
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.decorators.csrf
import
csrf_exempt
...
@@ -632,13 +631,13 @@ def handle_xblock_callback(request, course_id, usage_id, handler, suffix=None):
...
@@ -632,13 +631,13 @@ def handle_xblock_callback(request, course_id, usage_id, handler, suffix=None):
- location -- the module location. Used to look up the XModule instance
- location -- the module location. Used to look up the XModule instance
- course_id -- defines the course context for this request.
- course_id -- defines the course context for this request.
R
aises PermissionDenied
if the user is not logged in. Raises Http404 if
R
eturn 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
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
not accessible by the user, or the module raises NotFoundError. If the
module raises any other error, it will escape this function.
module raises any other error, it will escape this function.
"""
"""
if
not
request
.
user
.
is_authenticated
():
if
not
request
.
user
.
is_authenticated
():
r
aise
PermissionDenied
r
eturn
HttpResponse
(
'Unauthenticated'
,
status
=
403
)
return
_invoke_xblock_handler
(
request
,
course_id
,
usage_id
,
handler
,
suffix
,
request
.
user
)
return
_invoke_xblock_handler
(
request
,
course_id
,
usage_id
,
handler
,
suffix
,
request
.
user
)
...
...
lms/djangoapps/courseware/tests/test_module_render.py
View file @
8201c990
...
@@ -160,6 +160,7 @@ class ModuleRenderTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase):
...
@@ -160,6 +160,7 @@ class ModuleRenderTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase):
)
)
response
=
self
.
client
.
post
(
dispatch_url
,
{
'position'
:
2
})
response
=
self
.
client
.
post
(
dispatch_url
,
{
'position'
:
2
})
self
.
assertEquals
(
403
,
response
.
status_code
)
self
.
assertEquals
(
403
,
response
.
status_code
)
self
.
assertEquals
(
'Unauthenticated'
,
response
.
content
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
...
...
lms/envs/common.py
View file @
8201c990
...
@@ -854,6 +854,7 @@ courseware_js = (
...
@@ -854,6 +854,7 @@ courseware_js = (
'coffee/src/'
+
pth
+
'.js'
'coffee/src/'
+
pth
+
'.js'
for
pth
in
[
'courseware'
,
'histogram'
,
'navigation'
,
'time'
]
for
pth
in
[
'courseware'
,
'histogram'
,
'navigation'
,
'time'
]
]
+
]
+
[
'js/'
+
pth
+
'.js'
for
pth
in
[
'ajax-error'
]]
+
sorted
(
rooted_glob
(
PROJECT_ROOT
/
'static'
,
'coffee/src/modules/**/*.js'
))
sorted
(
rooted_glob
(
PROJECT_ROOT
/
'static'
,
'coffee/src/modules/**/*.js'
))
)
)
...
...
lms/static/js/ajax-error.js
0 → 100644
View file @
8201c990
$
(
document
).
ajaxError
(
function
(
event
,
jXHR
)
{
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
;
};
}
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment