Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-notes-api
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-notes-api
Commits
aaa93476
Commit
aaa93476
authored
Apr 09, 2018
by
Gregory Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete all notes for user
https://openedx.atlassian.net/browse/EDUCATOR-2657
parent
a5088033
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
13 deletions
+63
-13
.gitignore
+4
-0
notesapi/v1/tests/test_views.py
+42
-7
notesapi/v1/views.py
+17
-6
No files found.
.gitignore
View file @
aaa93476
...
...
@@ -11,3 +11,7 @@ coverage/
#vim
*.swp
venv/
.idea/
notesapi/v1/tests/test_views.py
View file @
aaa93476
# -*- coding: utf-8 -*-
import
urlparse
import
jwt
import
unittest
import
ddt
from
calendar
import
timegm
from
datetime
import
datetime
,
timedelta
from
mock
import
patch
import
ddt
import
jwt
import
unittest
import
urlparse
from
django.conf
import
settings
from
django.core.management
import
call_command
from
django.core.urlresolvers
import
reverse
from
django.conf
import
settings
from
django.test.utils
import
override_settings
from
mock
import
patch
from
rest_framework
import
status
from
rest_framework.test
import
APITestCase
...
...
@@ -508,6 +507,42 @@ class AnnotationListViewTests(BaseAnnotationViewTests):
start
=
start
)
def
test_delete_all_user_annotations
(
self
,
user_id
=
TEST_USER
):
"""
Verify that deleting all user annotations works
"""
self
.
_create_annotation
(
text
=
u'Comment with foo'
,
tags
=
[
u'bar'
])
self
.
_create_annotation
(
text
=
u'Another comment'
,
tags
=
[
u'foo'
])
self
.
_create_annotation
(
text
=
u'A longer comment with bar'
,
tags
=
[
u'foo'
])
response
=
self
.
_get_search_results
()
self
.
assertEqual
(
response
[
"total"
],
3
)
url
=
reverse
(
'api:v1:annotations'
)
self
.
payload
[
"user_id"
]
=
user_id
# Delete all notes for User 1
response
=
self
.
client
.
delete
(
url
,
headers
=
self
.
headers
,
data
=
self
.
payload
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
# Verify notes are deleted for User 1
response
=
self
.
_get_search_results
()
self
.
assertEqual
(
response
[
"total"
],
0
)
# Reattempt delete for User 1
response
=
self
.
client
.
delete
(
url
,
headers
=
self
.
headers
,
data
=
self
.
payload
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
def
test_delete_all_user_annotations_no_user
(
self
):
# Delete for No User
url
=
reverse
(
'api:v1:annotations'
)
response
=
self
.
client
.
delete
(
url
,
headers
=
self
.
headers
,
data
=
self
.
payload
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
def
test_delete_all_user_annotations_other_user
(
self
):
url
=
reverse
(
'api:v1:annotations'
)
self
.
payload
[
"user_id"
]
=
TEST_OTHER_USER
response
=
self
.
client
.
delete
(
url
,
headers
=
self
.
headers
,
data
=
self
.
payload
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
@ddt.ddt
class
AnnotationDetailViewTests
(
BaseAnnotationViewTests
):
...
...
notesapi/v1/views.py
View file @
aaa93476
import
logging
import
json
import
newrelic.agent
import
logging
import
newrelic.agent
from
django.conf
import
settings
from
django.core.urlresolvers
import
reverse
from
django.core.exceptions
import
ValidationError
from
django.core.urlresolvers
import
reverse
from
django.db.models
import
Q
from
django.utils.translation
import
ugettext
as
_
from
rest_framework
import
status
from
rest_framework.generics
import
GenericAPIView
from
rest_framework.response
import
Response
from
rest_framework.views
import
APIView
from
haystack.query
import
SQ
from
notesapi.v1.models
import
Note
from
notesapi.v1.serializers
import
NoteSerializer
,
NotesElasticSearchSerializer
from
notesapi.v1.serializers
import
(
NotesElasticSearchSerializer
,
NoteSerializer
)
if
not
settings
.
ES_DISABLED
:
from
notesserver.highlight
import
SearchQuerySet
...
...
@@ -349,6 +348,18 @@ class AnnotationListView(GenericAPIView):
serializer
=
NoteSerializer
(
note
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_201_CREATED
,
headers
=
{
'Location'
:
location
})
def
delete
(
self
,
*
args
,
**
kwargs
):
# pylint: disable=unused-argument
"""
Delete all annotations for user_id
"""
params
=
self
.
request
.
data
if
'user_id'
not
in
params
:
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
)
Note
.
objects
.
filter
(
user_id
=
params
[
'user_id'
])
.
delete
()
return
Response
(
status
=
status
.
HTTP_200_OK
)
class
AnnotationDetailView
(
APIView
):
"""
...
...
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