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
e9491d59
Commit
e9491d59
authored
Oct 07, 2014
by
Alan Boudreault
Committed by
Jonathan Piacenti
Aug 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix api_manager failing tests about cohorts
parent
79744b52
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
+9
-4
lms/djangoapps/api_manager/users/views.py
+9
-4
No files found.
lms/djangoapps/api_manager/users/views.py
View file @
e9491d59
...
...
@@ -20,8 +20,10 @@ from courseware.model_data import FieldDataCache
from
openedx.core.djangoapps.course_groups.models
import
CourseUserGroup
from
openedx.core.djangoapps.course_groups.cohorts
import
(
get_cohort_by_name
,
get_cohort
,
add_cohort
,
add_user_to_cohort
add_user_to_cohort
,
remove_user_from_cohort
)
from
django_comment_common.models
import
Role
,
FORUM_ROLE_MODERATOR
from
gradebook.models
import
StudentGradebook
...
...
@@ -724,14 +726,14 @@ class UsersCoursesList(SecureAPIView):
course_enrollment
=
CourseEnrollment
.
enroll
(
user
,
course_key
)
# Ensure the user is in a cohort. Add it explicitly in the default_cohort
try
:
default_cohort
=
get_cohort_by_name
(
course_
id
,
CourseUserGroup
.
default_cohort_name
)
default_cohort
=
get_cohort_by_name
(
course_
key
,
CourseUserGroup
.
default_cohort_name
)
except
CourseUserGroup
.
DoesNotExist
:
default_cohort
=
add_cohort
(
course_
id
,
CourseUserGroup
.
default_cohort_name
)
default_cohort
=
add_cohort
(
course_
key
,
CourseUserGroup
.
default_cohort_name
)
add_user_to_cohort
(
default_cohort
,
user
.
username
)
log
.
debug
(
'User "{}" has been automatically added in cohort "{}" for course "{}"'
.
format
(
user
.
username
,
default_cohort
.
name
,
course_descriptor
.
display_name
)
)
response_data
[
'uri'
]
=
'{}/{}'
.
format
(
base_uri
,
course_
id
)
response_data
[
'uri'
]
=
'{}/{}'
.
format
(
base_uri
,
course_
key
)
response_data
[
'id'
]
=
unicode
(
course_key
)
response_data
[
'name'
]
=
course_descriptor
.
display_name
response_data
[
'is_active'
]
=
course_enrollment
.
is_active
...
...
@@ -901,6 +903,9 @@ class UsersCoursesDetail(SecureAPIView):
if
not
course_exists
(
request
,
user
,
course_id
):
return
Response
({},
status
=
status
.
HTTP_204_NO_CONTENT
)
course_key
=
get_course_key
(
course_id
)
cohort
=
get_cohort
(
user
,
course_key
)
if
cohort
:
remove_user_from_cohort
(
cohort
,
user
.
username
)
CourseEnrollment
.
unenroll
(
user
,
course_key
)
return
Response
({},
status
=
status
.
HTTP_204_NO_CONTENT
)
...
...
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