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
996d0518
Commit
996d0518
authored
Aug 14, 2014
by
Matt Drayer
Committed by
Jonathan Piacenti
Aug 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mattdrayer/api-workgroup-user-check: Ensure no existing workgroup assignment
parent
359d6b07
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
0 deletions
+73
-0
lms/djangoapps/projects/tests/test_workgroups.py
+59
-0
lms/djangoapps/projects/views.py
+14
-0
No files found.
lms/djangoapps/projects/tests/test_workgroups.py
View file @
996d0518
...
...
@@ -91,6 +91,11 @@ class WorkgroupsApiTests(ModuleStoreTestCase):
content_id
=
self
.
test_course_content_id
)
self
.
test_project2
=
Project
.
objects
.
create
(
course_id
=
self
.
test_course_id
,
content_id
=
unicode
(
self
.
test_group_project
.
scope_ids
.
usage_id
)
)
self
.
test_user_email
=
str
(
uuid
.
uuid4
())
self
.
test_user_username
=
str
(
uuid
.
uuid4
())
self
.
test_user
=
User
.
objects
.
create
(
...
...
@@ -275,6 +280,60 @@ class WorkgroupsApiTests(ModuleStoreTestCase):
self
.
assertIsNotNone
(
cohort
)
self
.
assertTrue
(
is_user_in_cohort
(
cohort
,
self
.
test_user
.
id
,
CourseUserGroup
.
WORKGROUP
))
def
test_workgroups_users_post_preexisting_workgroup
(
self
):
data
=
{
'name'
:
self
.
test_workgroup_name
,
'project'
:
self
.
test_project
.
id
}
response
=
self
.
do_post
(
self
.
test_workgroups_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
test_uri
=
'{}{}/'
.
format
(
self
.
test_workgroups_uri
,
str
(
response
.
data
[
'id'
]))
users_uri
=
'{}users/'
.
format
(
test_uri
)
data
=
{
"id"
:
self
.
test_user
.
id
}
response
=
self
.
do_post
(
users_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
data
=
{
'name'
:
"Workgroup 2"
,
'project'
:
self
.
test_project
.
id
}
response
=
self
.
do_post
(
self
.
test_workgroups_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
test_uri
=
'{}{}/'
.
format
(
self
.
test_workgroups_uri
,
str
(
response
.
data
[
'id'
]))
users_uri
=
'{}users/'
.
format
(
test_uri
)
data
=
{
"id"
:
self
.
test_user
.
id
}
response
=
self
.
do_post
(
users_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
400
)
def
test_workgroups_users_post_preexisting_project
(
self
):
data
=
{
'name'
:
self
.
test_workgroup_name
,
'project'
:
self
.
test_project
.
id
}
response
=
self
.
do_post
(
self
.
test_workgroups_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
test_uri
=
'{}{}/'
.
format
(
self
.
test_workgroups_uri
,
str
(
response
.
data
[
'id'
]))
users_uri
=
'{}users/'
.
format
(
test_uri
)
data
=
{
"id"
:
self
.
test_user
.
id
}
response
=
self
.
do_post
(
users_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
# Second project created in setUp, adding a new workgroup
data
=
{
'name'
:
"Workgroup 2"
,
'project'
:
self
.
test_project2
.
id
}
response
=
self
.
do_post
(
self
.
test_workgroups_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
test_uri
=
'{}{}/'
.
format
(
self
.
test_workgroups_uri
,
str
(
response
.
data
[
'id'
]))
users_uri
=
'{}users/'
.
format
(
test_uri
)
# Assign the test user to the alternate project/workgroup
data
=
{
"id"
:
self
.
test_user
.
id
}
response
=
self
.
do_post
(
users_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
400
)
def
test_workgroups_users_post_with_cohort_backfill
(
self
):
"""
This test asserts a case where a workgroup was created before the existence of a cohorted discussion
...
...
lms/djangoapps/projects/views.py
View file @
996d0518
...
...
@@ -157,7 +157,21 @@ class WorkgroupsViewSet(viewsets.ModelViewSet):
except
ObjectDoesNotExist
:
message
=
'User {} does not exist'
.
format
(
user_id
)
return
Response
({
"detail"
:
message
},
status
.
HTTP_400_BAD_REQUEST
)
workgroup
=
self
.
get_object
()
# Ensure the user is not already assigned to a workgroup for this project
existing_workgroups
=
Workgroup
.
objects
.
filter
(
users
=
user
)
.
filter
(
project
=
workgroup
.
project
)
if
len
(
existing_workgroups
):
message
=
'User {} already assigned to a workgroup for this project'
.
format
(
user_id
)
return
Response
({
"detail"
:
message
},
status
.
HTTP_400_BAD_REQUEST
)
# Ensure the user is not already assigned to a project for this course
existing_projects
=
Project
.
objects
.
filter
(
course_id
=
workgroup
.
project
.
course_id
)
.
filter
(
workgroups__users__id
=
user
.
id
)
if
len
(
existing_projects
):
message
=
'User {} already assigned to a project for this course'
.
format
(
user_id
)
return
Response
({
"detail"
:
message
},
status
.
HTTP_400_BAD_REQUEST
)
workgroup
.
users
.
add
(
user
)
workgroup
.
save
()
...
...
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