Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
f92d02fe
Commit
f92d02fe
authored
7 years ago
by
Michael Frey
Browse files
Options
Downloads
Patches
Plain Diff
catch InvalidKeyError
parent
e6c94400
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
openedx/core/djangoapps/embargo/tests/test_views.py
+5
-0
5 additions, 0 deletions
openedx/core/djangoapps/embargo/tests/test_views.py
openedx/core/djangoapps/embargo/views.py
+9
-4
9 additions, 4 deletions
openedx/core/djangoapps/embargo/views.py
with
14 additions
and
4 deletions
openedx/core/djangoapps/embargo/tests/test_views.py
+
5
−
0
View file @
f92d02fe
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
openedx/core/djangoapps/embargo/views.py
+
9
−
4
View file @
f92d02fe
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment