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
d9e21cf1
Commit
d9e21cf1
authored
Jun 24, 2014
by
Matt Drayer
Committed by
Jonathan Piacenti
Aug 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mattdrayer/api-groups-organizations-list: Support for viewing related orgs
parent
c676eeb1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
3 deletions
+60
-3
lms/djangoapps/api_manager/groups/tests.py
+28
-0
lms/djangoapps/api_manager/groups/urls.py
+1
-0
lms/djangoapps/api_manager/groups/views.py
+31
-3
No files found.
lms/djangoapps/api_manager/groups/tests.py
View file @
d9e21cf1
...
...
@@ -14,6 +14,7 @@ from django.test.utils import override_settings
from
api_manager.models
import
GroupRelationship
,
GroupProfile
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
api_manager.models
import
GroupRelationship
,
GroupProfile
,
Organization
from
xmodule.modulestore.tests.factories
import
CourseFactory
TEST_API_KEY
=
str
(
uuid
.
uuid4
())
...
...
@@ -45,6 +46,14 @@ class GroupsApiTests(ModuleStoreTestCase):
self
.
course
=
CourseFactory
.
create
()
self
.
test_course_id
=
self
.
course
.
id
self
.
test_organization
=
Organization
.
objects
.
create
(
name
=
"Test Organization"
,
display_name
=
'Test Org'
,
contact_name
=
'John Org'
,
contact_email
=
'john@test.org'
,
contact_phone
=
'+1 332 232 24234'
)
self
.
client
=
SecureClient
()
cache
.
clear
()
...
...
@@ -911,3 +920,22 @@ class GroupsApiTests(ModuleStoreTestCase):
test_uri
=
'{}/courses/{}'
.
format
(
response
.
data
[
'uri'
],
self
.
course
.
id
)
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_group_organizations_list_get
(
self
):
data
=
{
'name'
:
self
.
test_group_name
,
'type'
:
'test'
}
response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
group_id
=
response
.
data
[
'id'
]
self
.
test_organization
.
groups
.
add
(
group_id
)
test_uri
=
response
.
data
[
'uri'
]
+
'/organizations/'
confirm_uri
=
test_uri
+
'/'
+
str
(
self
.
test_organization
.
id
)
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
len
(
response
.
data
),
1
)
self
.
assertEqual
(
response
.
data
[
0
][
'id'
],
self
.
test_organization
.
id
)
self
.
assertEqual
(
response
.
data
[
0
][
'name'
],
self
.
test_organization
.
name
)
def
test_group_courses_list_get_invalid_group
(
self
):
test_uri
=
self
.
base_groups_uri
+
'/1231241/organizations/'
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
404
)
lms/djangoapps/api_manager/groups/urls.py
View file @
d9e21cf1
...
...
@@ -11,6 +11,7 @@ urlpatterns = patterns(
url
(
r'^(?P<group_id>[0-9]+)$'
,
groups_views
.
GroupsDetail
.
as_view
()),
url
(
r'^(?P<group_id>[0-9]+)/courses/*$'
,
groups_views
.
GroupsCoursesList
.
as_view
()),
url
(
r'^(?P<group_id>[0-9]+)/courses/(?P<course_id>[a-zA-Z0-9/_:]+)$'
,
groups_views
.
GroupsCoursesDetail
.
as_view
()),
url
(
r'^(?P<group_id>[0-9]+)/organizations/*$'
,
groups_views
.
GroupsOrganizationsList
.
as_view
()),
url
(
r'^(?P<group_id>[0-9]+)/users/*$'
,
groups_views
.
GroupsUsersList
.
as_view
()),
url
(
r'^(?P<group_id>[0-9]+)/users/(?P<user_id>[0-9]+)$'
,
groups_views
.
GroupsUsersDetail
.
as_view
()),
url
(
r'^(?P<group_id>[0-9]+)/groups/*$'
,
groups_views
.
GroupsGroupsList
.
as_view
()),
...
...
lms/djangoapps/api_manager/groups/views.py
View file @
d9e21cf1
...
...
@@ -11,10 +11,12 @@ from rest_framework import status
from
rest_framework.response
import
Response
from
api_manager.models
import
GroupRelationship
,
CourseGroupRelationship
,
GroupProfile
,
APIUser
as
User
from
xmodule.modulestore.django
import
modulestore
from
api_manager.permissions
import
SecureAPIView
from
xmodule.modulestore
import
Location
,
InvalidLocationError
from
api_manager.utils
import
str2bool
,
generate_base_uri
from
api_manager.organizations
import
serializers
from
xmodule.modulestore
import
Location
,
InvalidLocationError
from
xmodule.modulestore.django
import
modulestore
RELATIONSHIP_TYPES
=
{
'hierarchical'
:
'h'
,
'graph'
:
'g'
}
...
...
@@ -547,7 +549,7 @@ class GroupsCoursesList(SecureAPIView):
def
get
(
self
,
request
,
group_id
):
"""
GET /api/groups/{group_id}/courses/
{course_id}
GET /api/groups/{group_id}/courses/
"""
response_data
=
{}
try
:
...
...
@@ -614,3 +616,29 @@ class GroupsCoursesDetail(SecureAPIView):
except
ObjectDoesNotExist
:
pass
return
Response
({},
status
=
status
.
HTTP_204_NO_CONTENT
)
class
GroupsOrganizationsList
(
SecureAPIView
):
"""
### The GroupsOrganizationsList view allows clients to interact with the set of Organizations related to the specified Group
- URI: ```/api/groups/{group_id}/organizations/```
- GET: Returns a JSON representation (array) of the set of related Organization entities
### Use Cases/Notes:
* View all of the Organizations related to a particular Program (currently modeled as a Group entity)
"""
def
get
(
self
,
request
,
group_id
):
"""
GET /api/groups/{group_id}/organizations/
"""
response_data
=
{}
try
:
existing_group
=
Group
.
objects
.
get
(
id
=
group_id
)
except
ObjectDoesNotExist
:
return
Response
({},
status
.
HTTP_404_NOT_FOUND
)
response_data
=
[]
for
org
in
existing_group
.
organizations
.
all
():
serializer
=
serializers
.
OrganizationSerializer
(
org
)
response_data
.
append
(
serializer
.
data
)
return
Response
(
response_data
,
status
=
status
.
HTTP_200_OK
)
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