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
6f60d3b9
Commit
6f60d3b9
authored
Jun 27, 2017
by
Michael Frey
Committed by
GitHub
Jun 27, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15417 from edx/mjfrey/catch-exception
catch InvalidKeyError
parents
f920493b
f92d02fe
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
4 deletions
+14
-4
openedx/core/djangoapps/embargo/tests/test_views.py
+5
-0
openedx/core/djangoapps/embargo/views.py
+9
-4
No files found.
openedx/core/djangoapps/embargo/tests/test_views.py
View file @
6f60d3b9
...
...
@@ -147,3 +147,8 @@ class CheckCourseAccessViewTest(CourseApiFactoryMixin, ModuleStoreTestCase):
def
test_course_access_endpoint_with_invalid_data
(
self
):
response
=
self
.
client
.
get
(
self
.
url
,
data
=
None
)
self
.
assertEqual
(
response
.
status_code
,
400
)
def
test_invalid_course_id
(
self
):
self
.
request_data
[
'course_ids'
]
=
[
'foo'
]
response
=
self
.
client
.
get
(
self
.
url
,
data
=
self
.
request_data
)
self
.
assertEqual
(
response
.
status_code
,
400
)
openedx/core/djangoapps/embargo/views.py
View file @
6f60d3b9
...
...
@@ -4,8 +4,10 @@ from django.contrib.auth.models import User
from
django.http
import
Http404
from
django.views.generic.base
import
View
from
edx_rest_framework_extensions.authentication
import
JwtAuthentication
from
opaque_keys
import
InvalidKeyError
from
opaque_keys.edx.keys
import
CourseKey
from
rest_framework
import
permissions
,
status
from
rest_framework.exceptions
import
ValidationError
from
rest_framework.response
import
Response
from
rest_framework.views
import
APIView
...
...
@@ -42,11 +44,14 @@ class CheckCourseAccessView(APIView):
if
course_ids
and
user
and
user_ip_address
:
for
course_id
in
course_ids
:
if
not
check_course_access
(
CourseKey
.
from_string
(
course_id
),
user
,
user_ip_address
):
response
[
'access'
]
=
False
break
try
:
if
not
check_course_access
(
CourseKey
.
from_string
(
course_id
),
user
,
user_ip_address
):
response
[
'access'
]
=
False
break
except
InvalidKeyError
:
raise
ValidationError
(
'Invalid course_ids'
)
else
:
r
eturn
Response
(
data
=
None
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
r
aise
ValidationError
(
'Missing parameters'
)
return
Response
(
response
)
...
...
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