Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
ba21c00f
Commit
ba21c00f
authored
Apr 06, 2016
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete notes via API
parent
734df1bb
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
135 additions
and
3 deletions
+135
-3
CHANGELOG
CHANGELOG
+5
-0
app/controllers/projects/notes_controller.rb
app/controllers/projects/notes_controller.rb
+2
-3
app/services/notes/delete_service.rb
app/services/notes/delete_service.rb
+8
-0
doc/api/notes.md
doc/api/notes.md
+45
-0
lib/api/notes.rb
lib/api/notes.rb
+17
-0
spec/requests/api/notes_spec.rb
spec/requests/api/notes_spec.rb
+43
-0
spec/services/notes/delete_service_spec.rb
spec/services/notes/delete_service_spec.rb
+15
-0
No files found.
CHANGELOG
View file @
ba21c00f
...
@@ -46,6 +46,11 @@ v 8.6.5
...
@@ -46,6 +46,11 @@ v 8.6.5
- Return status code 303 after a branch DELETE operation to avoid project deletion (Stan Hu). !3583
- Return status code 303 after a branch DELETE operation to avoid project deletion (Stan Hu). !3583
- Unblock user when active_directory is disabled and it can be found !3550
- Unblock user when active_directory is disabled and it can be found !3550
- Fix a 2FA authentication spoofing vulnerability.
- Fix a 2FA authentication spoofing vulnerability.
- API: Delete notes of issues, snippets, and merge requests (Robert Schilling)
v 8.6.5 (unreleased)
- Only update repository language if it is not set to improve performance
- Check permissions when user attempts to import members from another project
v 8.6.4
v 8.6.4
- Don't attempt to fetch any tags from a forked repo (Stan Hu)
- Don't attempt to fetch any tags from a forked repo (Stan Hu)
...
...
app/controllers/projects/notes_controller.rb
View file @
ba21c00f
...
@@ -39,8 +39,7 @@ class Projects::NotesController < Projects::ApplicationController
...
@@ -39,8 +39,7 @@ class Projects::NotesController < Projects::ApplicationController
def
destroy
def
destroy
if
note
.
editable?
if
note
.
editable?
note
.
destroy
Notes
::
DeleteService
.
new
(
project
,
current_user
).
execute
(
note
)
note
.
reset_events_cache
end
end
respond_to
do
|
format
|
respond_to
do
|
format
|
...
@@ -73,7 +72,7 @@ class Projects::NotesController < Projects::ApplicationController
...
@@ -73,7 +72,7 @@ class Projects::NotesController < Projects::ApplicationController
note
=
noteable
.
notes
.
find_by
(
data
)
note
=
noteable
.
notes
.
find_by
(
data
)
if
note
if
note
note
.
destroy
Notes
::
DeleteService
.
new
(
project
,
current_user
).
execute
(
note
)
else
else
Notes
::
CreateService
.
new
(
project
,
current_user
,
note_params
).
execute
Notes
::
CreateService
.
new
(
project
,
current_user
,
note_params
).
execute
end
end
...
...
app/services/notes/delete_service.rb
0 → 100644
View file @
ba21c00f
module
Notes
class
DeleteService
<
BaseService
def
execute
(
note
)
note
.
destroy
note
.
reset_events_cache
end
end
end
doc/api/notes.md
View file @
ba21c00f
...
@@ -105,6 +105,21 @@ Parameters:
...
@@ -105,6 +105,21 @@ Parameters:
-
`note_id`
(required) - The ID of a note
-
`note_id`
(required) - The ID of a note
-
`body`
(required) - The content of a note
-
`body`
(required) - The content of a note
### Delete existing issue note
Deletes an existing note of an issue. On success, this API method returns 200.
If the note does not exist, the API returns 404.
```
DELETE /projects/:id/issues/:issue_id/notes/:note_id
```
Parameters:
-
`id`
(required) - The ID of a project
-
`issue_id`
(required) - The ID of an issue
-
`note_id`
(required) - The ID of a note
## Snippets
## Snippets
### List all snippet notes
### List all snippet notes
...
@@ -182,6 +197,21 @@ Parameters:
...
@@ -182,6 +197,21 @@ Parameters:
-
`note_id`
(required) - The ID of a note
-
`note_id`
(required) - The ID of a note
-
`body`
(required) - The content of a note
-
`body`
(required) - The content of a note
### Delete existing snippet note
Deletes an existing note of a snippet. On success, this API method returns 200.
If the note does not exist, the API returns 404.
```
DELETE /projects/:id/snippets/:snippet_id/notes/:note_id
```
Parameters:
-
`id`
(required) - The ID of a project
-
`snippet_id`
(required) - The ID of a snippet
-
`note_id`
(required) - The ID of a note
## Merge Requests
## Merge Requests
### List all merge request notes
### List all merge request notes
...
@@ -262,3 +292,18 @@ Parameters:
...
@@ -262,3 +292,18 @@ Parameters:
-
`merge_request_id`
(required) - The ID of a merge request
-
`merge_request_id`
(required) - The ID of a merge request
-
`note_id`
(required) - The ID of a note
-
`note_id`
(required) - The ID of a note
-
`body`
(required) - The content of a note
-
`body`
(required) - The content of a note
### Delete existing snippet note
Deletes an existing note of a merge request. On success, this API method returns
200.
If the note does not exist, the API returns 404.
```
DELETE /projects/:id/merge_requests/:merge_request_id/notes/:note_id
```
Parameters:
-
`id`
(required) - The ID of a project
-
`merge_request_id`
(required) - The ID of a merge request
-
`note_id`
(required) - The ID of a note
lib/api/notes.rb
View file @
ba21c00f
...
@@ -112,6 +112,23 @@ module API
...
@@ -112,6 +112,23 @@ module API
end
end
end
end
# Delete a +notable+ note
#
# Parameters:
# Parameters:
# id (required) - The ID of a project
# noteable_id (required) - The ID of an issue, MR, or snippet
# node_id (required) - The ID of a note
# Example Request:
# DELETE /projects/:id/issues/:noteable_id/notes/:note_id
# DELETE /projects/:id/snippets/:noteable_id/notes/:node_id
delete
":id/
#{
noteables_str
}
/:
#{
noteable_id_str
}
/notes/:note_id"
do
note
=
user_project
.
notes
.
find
(
params
[
:note_id
])
not_found!
(
'Note'
)
unless
note
authorize!
:admin_note
,
note
::
Notes
::
DeleteService
.
new
(
user_project
,
current_user
).
execute
(
note
)
true
end
end
end
end
end
end
end
...
...
spec/requests/api/notes_spec.rb
View file @
ba21c00f
...
@@ -241,4 +241,47 @@ describe API::API, api: true do
...
@@ -241,4 +241,47 @@ describe API::API, api: true do
end
end
end
end
describe
':id/#{noteables_str}/:#{noteable_id_str}/notes/:note_id'
do
context
'when noteable is an Issue'
do
it
'should delete a note'
do
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/"
\
"notes/
#{
issue_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
end
it
'should return a 404 error when note id not found'
do
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes/123"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
end
end
context
'when noteable is a Snippet'
do
it
'should delete a note'
do
delete
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
\
"notes/
#{
snippet_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
end
it
'should return a 404 error when note id not found'
do
delete
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
\
"notes/123"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
end
end
context
'when noteable is a Merge Request'
do
it
'should delete a note'
do
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/"
\
"
#{
merge_request
.
id
}
/notes/
#{
merge_request_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
end
it
'should return a 404 error when note id not found'
do
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/"
\
"
#{
merge_request
.
id
}
/notes/123"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
end
end
end
end
end
spec/services/notes/delete_service_spec.rb
0 → 100644
View file @
ba21c00f
require
'spec_helper'
describe
Notes
::
DeleteService
,
services:
true
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:note
)
{
create
(
:note
,
project:
project
,
noteable:
issue
,
author:
user
,
note:
'Note'
)
}
describe
'#execute'
do
it
'deletes a note'
do
Notes
::
DeleteService
.
new
(
project
,
user
).
execute
(
note
)
expect
(
project
.
issues
.
find
(
issue
.
id
).
notes
).
to_not
include
(
note
)
end
end
end
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