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
a131af2f
Commit
a131af2f
authored
Apr 14, 2016
by
Zia Fazal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added user to organization link removal support
changes after feedback from reviewer
parent
1181d019
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
2 deletions
+27
-2
lms/djangoapps/organizations/tests.py
+0
-0
lms/djangoapps/organizations/views.py
+27
-2
No files found.
lms/djangoapps/organizations/tests.py
View file @
a131af2f
This diff is collapsed.
Click to expand it.
lms/djangoapps/organizations/views.py
View file @
a131af2f
...
@@ -5,6 +5,7 @@ from django.conf import settings
...
@@ -5,6 +5,7 @@ from django.conf import settings
from
django.contrib.auth.models
import
User
,
Group
from
django.contrib.auth.models
import
User
,
Group
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.db.models
import
Sum
,
F
,
Count
from
django.db.models
import
Sum
,
F
,
Count
from
django.utils.translation
import
ugettext
as
_
from
rest_framework
import
status
,
viewsets
from
rest_framework
import
status
,
viewsets
from
rest_framework.decorators
import
action
from
rest_framework.decorators
import
action
...
@@ -88,7 +89,7 @@ class OrganizationsViewSet(viewsets.ModelViewSet):
...
@@ -88,7 +89,7 @@ class OrganizationsViewSet(viewsets.ModelViewSet):
return
Response
(
response_data
,
status
=
status
.
HTTP_200_OK
)
return
Response
(
response_data
,
status
=
status
.
HTTP_200_OK
)
@action
(
methods
=
[
'get'
,
'post'
])
@action
(
methods
=
[
'get'
,
'post'
,
'delete'
])
def
users
(
self
,
request
,
pk
):
def
users
(
self
,
request
,
pk
):
"""
"""
- URI: ```/api/organizations/{org_id}/users/```
- URI: ```/api/organizations/{org_id}/users/```
...
@@ -100,7 +101,7 @@ class OrganizationsViewSet(viewsets.ModelViewSet):
...
@@ -100,7 +101,7 @@ class OrganizationsViewSet(viewsets.ModelViewSet):
* view parameter can be used to get a particular data .i.e. view=ids to
* view parameter can be used to get a particular data .i.e. view=ids to
* get list of user ids
* get list of user ids
- POST: Adds a User to an Organization
- POST: Adds a User to an Organization
- DELETE: Removes the user(s) given in the `users` param from an Organization.
"""
"""
if
request
.
method
==
'GET'
:
if
request
.
method
==
'GET'
:
include_course_counts
=
request
.
QUERY_PARAMS
.
get
(
'include_course_counts'
,
None
)
include_course_counts
=
request
.
QUERY_PARAMS
.
get
(
'include_course_counts'
,
None
)
...
@@ -152,6 +153,30 @@ class OrganizationsViewSet(viewsets.ModelViewSet):
...
@@ -152,6 +153,30 @@ class OrganizationsViewSet(viewsets.ModelViewSet):
response_data
.
append
(
user_data
)
response_data
.
append
(
user_data
)
return
Response
(
response_data
,
status
=
status
.
HTTP_200_OK
)
return
Response
(
response_data
,
status
=
status
.
HTTP_200_OK
)
elif
request
.
method
==
'DELETE'
:
user_ids
=
request
.
DATA
.
get
(
'users'
)
if
not
user_ids
:
return
Response
({
"detail"
:
_
(
'users parameter is missing.'
)},
status
.
HTTP_400_BAD_REQUEST
)
try
:
user_ids
=
[
int
(
user_id
)
for
user_id
in
filter
(
None
,
user_ids
.
split
(
','
))]
except
ValueError
:
return
Response
({
"detail"
:
_
(
'users parameter must be comma separated list of integers.'
)
},
status
.
HTTP_400_BAD_REQUEST
)
users_removed
=
0
organization
=
self
.
get_object
()
for
user_id
in
user_ids
:
try
:
user
=
User
.
objects
.
get
(
id
=
user_id
)
except
ObjectDoesNotExist
:
continue
organization
.
users
.
remove
(
user
)
users_removed
+=
1
organization
.
save
()
return
Response
({
"detail"
:
_
(
"{users_removed} users removed from organization"
)
.
format
(
users_removed
=
users_removed
)
},
status
=
status
.
HTTP_200_OK
)
else
:
else
:
user_id
=
request
.
DATA
.
get
(
'id'
)
user_id
=
request
.
DATA
.
get
(
'id'
)
try
:
try
:
...
...
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