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
048984ba
Commit
048984ba
authored
Aug 27, 2014
by
Waheed Ahmed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed InvalidKeyError on change enrollment.
LMS-11132
parent
8a7fef07
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
1 deletions
+13
-1
common/djangoapps/student/tests/test_enrollment.py
+5
-0
common/djangoapps/student/views.py
+8
-1
No files found.
common/djangoapps/student/tests/test_enrollment.py
View file @
048984ba
...
...
@@ -142,6 +142,11 @@ class EnrollmentTest(ModuleStoreTestCase):
resp
=
self
.
_change_enrollment
(
'not_an_action'
)
self
.
assertEqual
(
resp
.
status_code
,
400
)
def
test_with_invalid_course_id
(
self
):
CourseEnrollment
.
enroll
(
self
.
user
,
self
.
course
.
id
,
mode
=
"honor"
)
resp
=
self
.
_change_enrollment
(
'unenroll'
,
course_id
=
"edx/"
)
self
.
assertEqual
(
resp
.
status_code
,
400
)
def
_change_enrollment
(
self
,
action
,
course_id
=
None
,
auto_reg
=
False
):
"""
Change the student's enrollment status in a course.
...
...
common/djangoapps/student/views.py
View file @
048984ba
...
...
@@ -56,6 +56,7 @@ from dark_lang.models import DarkLangConfig
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
from
xmodule.modulestore.django
import
modulestore
from
opaque_keys
import
InvalidKeyError
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
xmodule.modulestore
import
ModuleStoreEnum
...
...
@@ -625,7 +626,13 @@ def change_enrollment(request, auto_register=False):
if
'course_id'
not
in
request
.
POST
:
return
HttpResponseBadRequest
(
_
(
"Course id not specified"
))
course_id
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
request
.
POST
.
get
(
"course_id"
))
try
:
course_id
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
request
.
POST
.
get
(
"course_id"
))
except
InvalidKeyError
:
log
.
warning
(
"User {username} tried to {action} with invalid course id: {course_id}"
.
format
(
username
=
user
.
username
,
action
=
action
,
course_id
=
request
.
POST
.
get
(
"course_id"
)
))
return
HttpResponseBadRequest
(
_
(
"Invalid course id"
))
if
not
user
.
is_authenticated
():
return
HttpResponseForbidden
()
...
...
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