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
Léo-Paul Géneau
gitlab-ce
Commits
2036458e
Commit
2036458e
authored
Sep 14, 2018
by
Douwe Maan
Committed by
André Luís
Sep 21, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return discussion object from NotesController#create when return_discussion param is set
parent
a2936404
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
13 deletions
+44
-13
app/assets/javascripts/diffs/store/utils.js
app/assets/javascripts/diffs/store/utils.js
+1
-0
app/controllers/concerns/notes_actions.rb
app/controllers/concerns/notes_actions.rb
+35
-13
spec/controllers/projects/notes_controller_spec.rb
spec/controllers/projects/notes_controller_spec.rb
+8
-0
No files found.
app/assets/javascripts/diffs/store/utils.js
View file @
2036458e
...
@@ -55,6 +55,7 @@ export function getNoteFormData(params) {
...
@@ -55,6 +55,7 @@ export function getNoteFormData(params) {
note_project_id
:
''
,
note_project_id
:
''
,
target_type
:
noteableData
.
targetType
,
target_type
:
noteableData
.
targetType
,
target_id
:
noteableData
.
id
,
target_id
:
noteableData
.
id
,
return_discussion
:
'
true
'
,
note
:
{
note
:
{
note
,
note
,
position
,
position
,
...
...
app/controllers/concerns/notes_actions.rb
View file @
2036458e
...
@@ -43,12 +43,26 @@ module NotesActions
...
@@ -43,12 +43,26 @@ module NotesActions
@note
=
Notes
::
CreateService
.
new
(
note_project
,
current_user
,
create_params
).
execute
@note
=
Notes
::
CreateService
.
new
(
note_project
,
current_user
,
create_params
).
execute
if
@note
.
is_a?
(
Note
)
respond_to
do
|
format
|
prepare_notes_for_rendering
([
@note
],
noteable
)
format
.
json
do
json
=
{
commands_changes:
@note
.
commands_changes
}
if
@note
.
persisted?
&&
return_discussion?
json
[
:valid
]
=
true
discussion
=
@note
.
discussion
prepare_notes_for_rendering
(
discussion
.
notes
)
json
[
:discussion
]
=
discussion_serializer
.
represent
(
discussion
,
context:
self
)
else
prepare_notes_for_rendering
([
@note
])
json
.
merge!
(
note_json
(
@note
))
end
end
respond_to
do
|
format
|
render
json:
json
format
.
json
{
render
json:
note_json
(
@note
)
}
end
format
.
html
{
redirect_back_or_default
}
format
.
html
{
redirect_back_or_default
}
end
end
end
end
...
@@ -57,10 +71,7 @@ module NotesActions
...
@@ -57,10 +71,7 @@ module NotesActions
# rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def
update
def
update
@note
=
Notes
::
UpdateService
.
new
(
project
,
current_user
,
note_params
).
execute
(
note
)
@note
=
Notes
::
UpdateService
.
new
(
project
,
current_user
,
note_params
).
execute
(
note
)
if
@note
.
is_a?
(
Note
)
prepare_notes_for_rendering
([
@note
])
prepare_notes_for_rendering
([
@note
])
end
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
json
{
render
json:
note_json
(
@note
)
}
format
.
json
{
render
json:
note_json
(
@note
)
}
...
@@ -91,14 +102,17 @@ module NotesActions
...
@@ -91,14 +102,17 @@ module NotesActions
end
end
def
note_json
(
note
)
def
note_json
(
note
)
attrs
=
{
attrs
=
{}
commands_changes:
note
.
commands_changes
}
if
note
.
persisted?
if
note
.
persisted?
attrs
[
:valid
]
=
true
attrs
[
:valid
]
=
true
if
use_note_serializer?
if
return_discussion?
discussion
=
note
.
discussion
prepare_notes_for_rendering
(
discussion
.
notes
)
attrs
[
:discussion
]
=
discussion_serializer
.
represent
(
discussion
,
context:
self
)
elsif
use_note_serializer?
attrs
.
merge!
(
note_serializer
.
represent
(
note
))
attrs
.
merge!
(
note_serializer
.
represent
(
note
))
else
else
attrs
.
merge!
(
attrs
.
merge!
(
...
@@ -218,6 +232,10 @@ module NotesActions
...
@@ -218,6 +232,10 @@ module NotesActions
ProjectNoteSerializer
.
new
(
project:
project
,
noteable:
noteable
,
current_user:
current_user
)
ProjectNoteSerializer
.
new
(
project:
project
,
noteable:
noteable
,
current_user:
current_user
)
end
end
def
discussion_serializer
DiscussionSerializer
.
new
(
project:
project
,
noteable:
noteable
,
current_user:
current_user
,
note_entity:
ProjectNoteEntity
)
end
def
note_project
def
note_project
strong_memoize
(
:note_project
)
do
strong_memoize
(
:note_project
)
do
next
nil
unless
project
next
nil
unless
project
...
@@ -237,6 +255,10 @@ module NotesActions
...
@@ -237,6 +255,10 @@ module NotesActions
end
end
end
end
def
return_discussion?
Gitlab
::
Utils
.
to_boolean
(
params
[
:return_discussion
])
end
def
use_note_serializer?
def
use_note_serializer?
return
false
if
params
[
'html'
]
return
false
if
params
[
'html'
]
...
...
spec/controllers/projects/notes_controller_spec.rb
View file @
2036458e
...
@@ -207,6 +207,14 @@ describe Projects::NotesController do
...
@@ -207,6 +207,14 @@ describe Projects::NotesController do
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
it
'returns discussion JSON when the return_discussion param is set'
do
post
:create
,
request_params
.
merge
(
format: :json
,
return_discussion:
'true'
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
have_key
'discussion'
expect
(
json_response
[
'discussion'
][
'notes'
][
0
][
'note'
]).
to
eq
(
request_params
[
:note
][
:note
])
end
context
'when merge_request_diff_head_sha present'
do
context
'when merge_request_diff_head_sha present'
do
before
do
before
do
service_params
=
{
service_params
=
{
...
...
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