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
005e07cb
Commit
005e07cb
authored
Dec 09, 2015
by
Bill DeRusha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove default course mode setting in enrollment api
parent
a30f7656
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
14 deletions
+23
-14
common/djangoapps/enrollment/api.py
+4
-3
common/djangoapps/enrollment/tests/test_api.py
+11
-6
common/djangoapps/enrollment/views.py
+2
-2
common/djangoapps/student/models.py
+5
-2
lms/djangoapps/instructor/enrollment.py
+1
-1
No files found.
common/djangoapps/enrollment/api.py
View file @
005e07cb
...
@@ -7,6 +7,8 @@ import importlib
...
@@ -7,6 +7,8 @@ import importlib
import
logging
import
logging
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.cache
import
cache
from
django.core.cache
import
cache
from
opaque_keys.edx.keys
import
CourseKey
from
course_modes.models
import
CourseMode
from
course_modes.models
import
CourseMode
from
enrollment
import
errors
from
enrollment
import
errors
...
@@ -372,9 +374,8 @@ def _default_course_mode(course_id):
...
@@ -372,9 +374,8 @@ def _default_course_mode(course_id):
Returns:
Returns:
str
str
"""
"""
course_enrollment_info
=
_data_api
()
.
get_course_enrollment_info
(
course_id
,
include_expired
=
False
)
course_modes
=
CourseMode
.
modes_for_course
(
CourseKey
.
from_string
(
course_id
))
course_modes
=
course_enrollment_info
[
"course_modes"
]
available_modes
=
[
m
.
slug
for
m
in
course_modes
]
available_modes
=
[
m
[
'slug'
]
for
m
in
course_modes
]
if
CourseMode
.
DEFAULT_MODE_SLUG
in
available_modes
:
if
CourseMode
.
DEFAULT_MODE_SLUG
in
available_modes
:
return
CourseMode
.
DEFAULT_MODE_SLUG
return
CourseMode
.
DEFAULT_MODE_SLUG
...
...
common/djangoapps/enrollment/tests/test_api.py
View file @
005e07cb
"""
"""
Tests for student enrollment.
Tests for student enrollment.
"""
"""
from
mock
import
patch
,
Mock
import
ddt
import
ddt
from
django.core.cache
import
cache
from
django.core.cache
import
cache
from
nose.tools
import
raises
from
nose.tools
import
raises
...
@@ -67,12 +69,15 @@ class EnrollmentTest(TestCase):
...
@@ -67,12 +69,15 @@ class EnrollmentTest(TestCase):
def
test_enroll_no_mode_success
(
self
,
course_modes
,
expected_mode
):
def
test_enroll_no_mode_success
(
self
,
course_modes
,
expected_mode
):
# Add a fake course enrollment information to the fake data API
# Add a fake course enrollment information to the fake data API
fake_data_api
.
add_course
(
self
.
COURSE_ID
,
course_modes
=
course_modes
)
fake_data_api
.
add_course
(
self
.
COURSE_ID
,
course_modes
=
course_modes
)
# Enroll in the course and verify the URL we get sent to
with
patch
(
'enrollment.api.CourseMode.modes_for_course'
)
as
mock_modes_for_course
:
result
=
api
.
add_enrollment
(
self
.
USERNAME
,
self
.
COURSE_ID
)
mock_course_modes
=
[
Mock
(
slug
=
mode
)
for
mode
in
course_modes
]
self
.
assertIsNotNone
(
result
)
mock_modes_for_course
.
return_value
=
mock_course_modes
self
.
assertEquals
(
result
[
'student'
],
self
.
USERNAME
)
# Enroll in the course and verify the URL we get sent to
self
.
assertEquals
(
result
[
'course'
][
'course_id'
],
self
.
COURSE_ID
)
result
=
api
.
add_enrollment
(
self
.
USERNAME
,
self
.
COURSE_ID
)
self
.
assertEquals
(
result
[
'mode'
],
expected_mode
)
self
.
assertIsNotNone
(
result
)
self
.
assertEquals
(
result
[
'student'
],
self
.
USERNAME
)
self
.
assertEquals
(
result
[
'course'
][
'course_id'
],
self
.
COURSE_ID
)
self
.
assertEquals
(
result
[
'mode'
],
expected_mode
)
@ddt.data
(
@ddt.data
(
[
'professional'
],
[
'professional'
],
...
...
common/djangoapps/enrollment/views.py
View file @
005e07cb
...
@@ -520,7 +520,7 @@ class EnrollmentListView(APIView, ApiKeyPermissionMixIn):
...
@@ -520,7 +520,7 @@ class EnrollmentListView(APIView, ApiKeyPermissionMixIn):
}
}
)
)
mode
=
request
.
data
.
get
(
'mode'
,
CourseMode
.
DEFAULT_MODE_SLUG
)
mode
=
request
.
data
.
get
(
'mode'
)
has_api_key_permissions
=
self
.
has_api_key_permissions
(
request
)
has_api_key_permissions
=
self
.
has_api_key_permissions
(
request
)
...
@@ -532,7 +532,7 @@ class EnrollmentListView(APIView, ApiKeyPermissionMixIn):
...
@@ -532,7 +532,7 @@ class EnrollmentListView(APIView, ApiKeyPermissionMixIn):
# other users, do not let them deduce the existence of an enrollment.
# other users, do not let them deduce the existence of an enrollment.
return
Response
(
status
=
status
.
HTTP_404_NOT_FOUND
)
return
Response
(
status
=
status
.
HTTP_404_NOT_FOUND
)
if
mode
!=
CourseMode
.
DEFAULT_MODE_SLUG
and
not
has_api_key_permissions
:
if
mode
not
in
(
CourseMode
.
AUDIT
,
CourseMode
.
HONOR
,
None
)
and
not
has_api_key_permissions
:
return
Response
(
return
Response
(
status
=
status
.
HTTP_403_FORBIDDEN
,
status
=
status
.
HTTP_403_FORBIDDEN
,
data
=
{
data
=
{
...
...
common/djangoapps/student/models.py
View file @
005e07cb
...
@@ -47,6 +47,7 @@ from xmodule_django.models import CourseKeyField, NoneToEmptyManager
...
@@ -47,6 +47,7 @@ from xmodule_django.models import CourseKeyField, NoneToEmptyManager
from
certificates.models
import
GeneratedCertificate
from
certificates.models
import
GeneratedCertificate
from
course_modes.models
import
CourseMode
from
course_modes.models
import
CourseMode
from
enrollment.api
import
_default_course_mode
import
lms.lib.comment_client
as
cc
import
lms.lib.comment_client
as
cc
from
openedx.core.djangoapps.commerce.utils
import
ecommerce_api_client
,
ECOMMERCE_DATE_FORMAT
from
openedx.core.djangoapps.commerce.utils
import
ecommerce_api_client
,
ECOMMERCE_DATE_FORMAT
from
openedx.core.djangoapps.content.course_overviews.models
import
CourseOverview
from
openedx.core.djangoapps.content.course_overviews.models
import
CourseOverview
...
@@ -1090,7 +1091,7 @@ class CourseEnrollment(models.Model):
...
@@ -1090,7 +1091,7 @@ class CourseEnrollment(models.Model):
)
)
@classmethod
@classmethod
def
enroll
(
cls
,
user
,
course_key
,
mode
=
CourseMode
.
DEFAULT_MODE_SLUG
,
check_access
=
False
):
def
enroll
(
cls
,
user
,
course_key
,
mode
=
None
,
check_access
=
False
):
"""
"""
Enroll a user in a course. This saves immediately.
Enroll a user in a course. This saves immediately.
...
@@ -1124,6 +1125,8 @@ class CourseEnrollment(models.Model):
...
@@ -1124,6 +1125,8 @@ class CourseEnrollment(models.Model):
Also emits relevant events for analytics purposes.
Also emits relevant events for analytics purposes.
"""
"""
if
mode
is
None
:
mode
=
_default_course_mode
(
unicode
(
course_key
))
# All the server-side checks for whether a user is allowed to enroll.
# All the server-side checks for whether a user is allowed to enroll.
try
:
try
:
course
=
CourseOverview
.
get_from_id
(
course_key
)
course
=
CourseOverview
.
get_from_id
(
course_key
)
...
@@ -1165,7 +1168,7 @@ class CourseEnrollment(models.Model):
...
@@ -1165,7 +1168,7 @@ class CourseEnrollment(models.Model):
return
enrollment
return
enrollment
@classmethod
@classmethod
def
enroll_by_email
(
cls
,
email
,
course_id
,
mode
=
CourseMode
.
DEFAULT_MODE_SLUG
,
ignore_errors
=
True
):
def
enroll_by_email
(
cls
,
email
,
course_id
,
mode
=
None
,
ignore_errors
=
True
):
"""
"""
Enroll a user in a course given their email. This saves immediately.
Enroll a user in a course given their email. This saves immediately.
...
...
lms/djangoapps/instructor/enrollment.py
View file @
005e07cb
...
@@ -119,7 +119,7 @@ def enroll_email(course_id, student_email, auto_enroll=False, email_students=Fal
...
@@ -119,7 +119,7 @@ def enroll_email(course_id, student_email, auto_enroll=False, email_students=Fal
if
CourseMode
.
is_white_label
(
course_id
):
if
CourseMode
.
is_white_label
(
course_id
):
course_mode
=
CourseMode
.
DEFAULT_SHOPPINGCART_MODE_SLUG
course_mode
=
CourseMode
.
DEFAULT_SHOPPINGCART_MODE_SLUG
else
:
else
:
course_mode
=
CourseMode
.
DEFAULT_MODE_SLUG
course_mode
=
None
if
previous_state
.
enrollment
:
if
previous_state
.
enrollment
:
course_mode
=
previous_state
.
mode
course_mode
=
previous_state
.
mode
...
...
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