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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
9aefaa41
Commit
9aefaa41
authored
Apr 06, 2016
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix code review issues
parent
ba21c00f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
140 additions
and
27 deletions
+140
-27
app/controllers/projects/notes_controller.rb
app/controllers/projects/notes_controller.rb
+1
-1
doc/api/notes.md
doc/api/notes.md
+113
-17
lib/api/notes.rb
lib/api/notes.rb
+2
-4
spec/requests/api/notes_spec.rb
spec/requests/api/notes_spec.rb
+19
-1
spec/services/notes/delete_service_spec.rb
spec/services/notes/delete_service_spec.rb
+5
-4
No files found.
app/controllers/projects/notes_controller.rb
View file @
9aefaa41
...
@@ -72,7 +72,7 @@ class Projects::NotesController < Projects::ApplicationController
...
@@ -72,7 +72,7 @@ class Projects::NotesController < Projects::ApplicationController
note
=
noteable
.
notes
.
find_by
(
data
)
note
=
noteable
.
notes
.
find_by
(
data
)
if
note
if
note
Notes
::
DeleteService
.
new
(
project
,
current_user
).
execute
(
note
)
note
.
destroy
else
else
Notes
::
CreateService
.
new
(
project
,
current_user
,
note_params
).
execute
Notes
::
CreateService
.
new
(
project
,
current_user
,
note_params
).
execute
end
end
...
...
doc/api/notes.md
View file @
9aefaa41
...
@@ -105,10 +105,10 @@ Parameters:
...
@@ -105,10 +105,10 @@ 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
### Delete
an
issue note
Deletes an existing note of an issue. On success, this API method returns 200
.
Deletes an existing note of an issue. On success, this API method returns 200
If the note does not exist, the API returns 404.
and the deleted note.
If the note does not exist, the API returns 404.
```
```
DELETE /projects/:id/issues/:issue_id/notes/:note_id
DELETE /projects/:id/issues/:issue_id/notes/:note_id
...
@@ -116,9 +116,41 @@ DELETE /projects/:id/issues/:issue_id/notes/:note_id
...
@@ -116,9 +116,41 @@ DELETE /projects/:id/issues/:issue_id/notes/:note_id
Parameters:
Parameters:
-
`id`
(required) - The ID of a project
| Attribute | Type | Required | Description |
-
`issue_id`
(required) - The ID of an issue
| --------- | ---- | -------- | ----------- |
-
`note_id`
(required) - The ID of a note
|
`id`
| integer | yes | The ID of a project |
|
`issue_id`
| integer | yes | The ID of an issue |
|
`note_id`
| integer | yes | The ID of a note |
```
bash
curl
-X
DELETE
-H
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v3/projects/5/issues/11/notes/636
```
Example Response:
```
json
{
"id"
:
636
,
"body"
:
"This is a good idea."
,
"attachment"
:
null
,
"author"
:
{
"id"
:
1
,
"username"
:
"pipin"
,
"email"
:
"admin@example.com"
,
"name"
:
"Pip"
,
"state"
:
"active"
,
"created_at"
:
"2013-09-30T13:46:01Z"
,
"avatar_url"
:
"http://www.gravatar.com/avatar/5224fd70153710e92fb8bcf79ac29d67?s=80&d=identicon"
,
"web_url"
:
"https://gitlab.example.com/u/pipin"
},
"created_at"
:
"2016-04-05T22:10:44.164Z"
,
"system"
:
false
,
"noteable_id"
:
11
,
"noteable_type"
:
"Issue"
,
"upvote"
:
false
,
"downvote"
:
false
}
```
## Snippets
## Snippets
...
@@ -197,10 +229,10 @@ Parameters:
...
@@ -197,10 +229,10 @@ 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
### Delete
a
snippet note
Deletes an existing note of a snippet. On success, this API method returns 200
.
Deletes an existing note of a snippet. On success, this API method returns 200
If the note does not exist, the API returns 404.
and the deleted note.
If the note does not exist, the API returns 404.
```
```
DELETE /projects/:id/snippets/:snippet_id/notes/:note_id
DELETE /projects/:id/snippets/:snippet_id/notes/:note_id
...
@@ -208,9 +240,41 @@ DELETE /projects/:id/snippets/:snippet_id/notes/:note_id
...
@@ -208,9 +240,41 @@ DELETE /projects/:id/snippets/:snippet_id/notes/:note_id
Parameters:
Parameters:
-
`id`
(required) - The ID of a project
| Attribute | Type | Required | Description |
-
`snippet_id`
(required) - The ID of a snippet
| --------- | ---- | -------- | ----------- |
-
`note_id`
(required) - The ID of a note
|
`id`
| integer | yes | The ID of a project |
|
`snippet_id`
| integer | yes | The ID of a snippet |
|
`note_id`
| integer | yes | The ID of a note |
```
bash
curl
-X
DELETE
-H
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v3/projects/5/snippets/52/notes/1659
```
Example Response:
```
json
{
"id"
:
1659
,
"body"
:
"This is a good idea."
,
"attachment"
:
null
,
"author"
:
{
"id"
:
1
,
"username"
:
"pipin"
,
"email"
:
"admin@example.com"
,
"name"
:
"Pip"
,
"state"
:
"active"
,
"created_at"
:
"2013-09-30T13:46:01Z"
,
"avatar_url"
:
"http://www.gravatar.com/avatar/5224fd70153710e92fb8bcf79ac29d67?s=80&d=identicon"
,
"web_url"
:
"https://gitlab.example.com/u/pipin"
},
"created_at"
:
"2016-04-06T16:51:53.239Z"
,
"system"
:
false
,
"noteable_id"
:
52
,
"noteable_type"
:
"Snippet"
,
"upvote"
:
false
,
"downvote"
:
false
}
```
## Merge Requests
## Merge Requests
...
@@ -293,10 +357,10 @@ Parameters:
...
@@ -293,10 +357,10 @@ 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 snippe
t note
### Delete
a merge reques
t note
Deletes an existing note of a merge request. On success, this API method returns
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.
200
and the deleted note
. If the note does not exist, the API returns 404.
```
```
DELETE /projects/:id/merge_requests/:merge_request_id/notes/:note_id
DELETE /projects/:id/merge_requests/:merge_request_id/notes/:note_id
...
@@ -304,6 +368,38 @@ DELETE /projects/:id/merge_requests/:merge_request_id/notes/:note_id
...
@@ -304,6 +368,38 @@ DELETE /projects/:id/merge_requests/:merge_request_id/notes/:note_id
Parameters:
Parameters:
-
`id`
(required) - The ID of a project
| Attribute | Type | Required | Description |
-
`merge_request_id`
(required) - The ID of a merge request
| --------- | ---- | -------- | ----------- |
-
`note_id`
(required) - The ID of a note
|
`id`
| integer | yes | The ID of a project |
|
`merge_request_id`
| integer | yes | The ID of a merge request |
|
`note_id`
| integer | yes | The ID of a note |
```
bash
curl
-X
DELETE
-H
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v3/projects/5/merge_requests/7/notes/1602
```
Example Response:
```
json
{
"id"
:
1602
,
"body"
:
"This is a good idea."
,
"attachment"
:
null
,
"author"
:
{
"id"
:
1
,
"username"
:
"pipin"
,
"email"
:
"admin@example.com"
,
"name"
:
"Pip"
,
"state"
:
"active"
,
"created_at"
:
"2013-09-30T13:46:01Z"
,
"avatar_url"
:
"http://www.gravatar.com/avatar/5224fd70153710e92fb8bcf79ac29d67?s=80&d=identicon"
,
"web_url"
:
"https://gitlab.example.com/u/pipin"
},
"created_at"
:
"2016-04-05T22:11:59.923Z"
,
"system"
:
false
,
"noteable_id"
:
7
,
"noteable_type"
:
"MergeRequest"
,
"upvote"
:
false
,
"downvote"
:
false
}
```
lib/api/notes.rb
View file @
9aefaa41
...
@@ -112,10 +112,9 @@ module API
...
@@ -112,10 +112,9 @@ module API
end
end
end
end
# Delete a +notable+ note
# Delete a +not
e
able+ note
#
#
# Parameters:
# Parameters:
# Parameters:
# id (required) - The ID of a project
# id (required) - The ID of a project
# noteable_id (required) - The ID of an issue, MR, or snippet
# noteable_id (required) - The ID of an issue, MR, or snippet
# node_id (required) - The ID of a note
# node_id (required) - The ID of a note
...
@@ -124,10 +123,9 @@ module API
...
@@ -124,10 +123,9 @@ module API
# DELETE /projects/:id/snippets/:noteable_id/notes/:node_id
# DELETE /projects/:id/snippets/:noteable_id/notes/:node_id
delete
":id/
#{
noteables_str
}
/:
#{
noteable_id_str
}
/notes/:note_id"
do
delete
":id/
#{
noteables_str
}
/:
#{
noteable_id_str
}
/notes/:note_id"
do
note
=
user_project
.
notes
.
find
(
params
[
:note_id
])
note
=
user_project
.
notes
.
find
(
params
[
:note_id
])
not_found!
(
'Note'
)
unless
note
authorize!
:admin_note
,
note
authorize!
:admin_note
,
note
::
Notes
::
DeleteService
.
new
(
user_project
,
current_user
).
execute
(
note
)
::
Notes
::
DeleteService
.
new
(
user_project
,
current_user
).
execute
(
note
)
tru
e
present
note
,
with:
Entities
::
Not
e
end
end
end
end
end
end
...
...
spec/requests/api/notes_spec.rb
View file @
9aefaa41
...
@@ -241,16 +241,22 @@ describe API::API, api: true do
...
@@ -241,16 +241,22 @@ describe API::API, api: true do
end
end
end
end
describe
'
:id/#{noteables_str}/:#{noteable_id_str}
/notes/:note_id'
do
describe
'
DELETE /projects/:id/noteable/:noteable_id
/notes/:note_id'
do
context
'when noteable is an Issue'
do
context
'when noteable is an Issue'
do
it
'should delete a note'
do
it
'should delete a note'
do
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/"
\
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/"
\
"notes/
#{
issue_note
.
id
}
"
,
user
)
"notes/
#{
issue_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
status
).
to
eq
(
200
)
# Check if note is really deleted
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/"
\
"notes/
#{
issue_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
end
end
it
'should return a 404 error when note id not found'
do
it
'should return a 404 error when note id not found'
do
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes/123"
,
user
)
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes/123"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
.
status
).
to
eq
(
404
)
end
end
end
end
...
@@ -259,12 +265,18 @@ describe API::API, api: true do
...
@@ -259,12 +265,18 @@ describe API::API, api: true do
it
'should delete a note'
do
it
'should delete a note'
do
delete
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
\
delete
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
\
"notes/
#{
snippet_note
.
id
}
"
,
user
)
"notes/
#{
snippet_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
status
).
to
eq
(
200
)
# Check if note is really deleted
delete
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
\
"notes/
#{
snippet_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
end
end
it
'should return a 404 error when note id not found'
do
it
'should return a 404 error when note id not found'
do
delete
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
\
delete
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
\
"notes/123"
,
user
)
"notes/123"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
.
status
).
to
eq
(
404
)
end
end
end
end
...
@@ -273,12 +285,18 @@ describe API::API, api: true do
...
@@ -273,12 +285,18 @@ describe API::API, api: true do
it
'should delete a note'
do
it
'should delete a note'
do
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/"
\
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/"
\
"
#{
merge_request
.
id
}
/notes/
#{
merge_request_note
.
id
}
"
,
user
)
"
#{
merge_request
.
id
}
/notes/
#{
merge_request_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
status
).
to
eq
(
200
)
# Check if note is really deleted
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/"
\
"
#{
merge_request
.
id
}
/notes/
#{
merge_request_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
end
end
it
'should return a 404 error when note id not found'
do
it
'should return a 404 error when note id not found'
do
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/"
\
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/"
\
"
#{
merge_request
.
id
}
/notes/123"
,
user
)
"
#{
merge_request
.
id
}
/notes/123"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
.
status
).
to
eq
(
404
)
end
end
end
end
...
...
spec/services/notes/delete_service_spec.rb
View file @
9aefaa41
...
@@ -3,13 +3,14 @@ require 'spec_helper'
...
@@ -3,13 +3,14 @@ require 'spec_helper'
describe
Notes
::
DeleteService
,
services:
true
do
describe
Notes
::
DeleteService
,
services:
true
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:note
)
{
create
(
:note
,
project:
project
,
noteable:
issue
)
}
let
(
:note
)
{
create
(
:note
,
project:
project
,
noteable:
issue
,
author:
user
,
note:
'Note'
)
}
describe
'#execute'
do
describe
'#execute'
do
it
'deletes a note'
do
it
'deletes a note'
do
Notes
::
DeleteService
.
new
(
project
,
user
).
execute
(
note
)
project
=
note
.
project
expect
(
project
.
issues
.
find
(
issue
.
id
).
notes
).
to_not
include
(
note
)
described_class
.
new
(
project
,
note
.
author
).
execute
(
note
)
expect
(
project
.
issues
.
find
(
issue
.
id
).
notes
).
not_to
include
(
note
)
end
end
end
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