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
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
Hide 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) {
note_project_id
:
''
,
target_type
:
noteableData
.
targetType
,
target_id
:
noteableData
.
id
,
return_discussion
:
'
true
'
,
note
:
{
note
,
position
,
...
...
app/controllers/concerns/notes_actions.rb
View file @
2036458e
...
...
@@ -43,12 +43,26 @@ module NotesActions
@note
=
Notes
::
CreateService
.
new
(
note_project
,
current_user
,
create_params
).
execute
if
@note
.
is_a?
(
Note
)
prepare_notes_for_rendering
([
@note
],
noteable
)
end
respond_to
do
|
format
|
format
.
json
{
render
json:
note_json
(
@note
)
}
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
render
json:
json
end
format
.
html
{
redirect_back_or_default
}
end
end
...
...
@@ -57,10 +71,7 @@ module NotesActions
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def
update
@note
=
Notes
::
UpdateService
.
new
(
project
,
current_user
,
note_params
).
execute
(
note
)
if
@note
.
is_a?
(
Note
)
prepare_notes_for_rendering
([
@note
])
end
prepare_notes_for_rendering
([
@note
])
respond_to
do
|
format
|
format
.
json
{
render
json:
note_json
(
@note
)
}
...
...
@@ -91,14 +102,17 @@ module NotesActions
end
def
note_json
(
note
)
attrs
=
{
commands_changes:
note
.
commands_changes
}
attrs
=
{}
if
note
.
persisted?
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
))
else
attrs
.
merge!
(
...
...
@@ -218,6 +232,10 @@ module NotesActions
ProjectNoteSerializer
.
new
(
project:
project
,
noteable:
noteable
,
current_user:
current_user
)
end
def
discussion_serializer
DiscussionSerializer
.
new
(
project:
project
,
noteable:
noteable
,
current_user:
current_user
,
note_entity:
ProjectNoteEntity
)
end
def
note_project
strong_memoize
(
:note_project
)
do
next
nil
unless
project
...
...
@@ -237,6 +255,10 @@ module NotesActions
end
end
def
return_discussion?
Gitlab
::
Utils
.
to_boolean
(
params
[
:return_discussion
])
end
def
use_note_serializer?
return
false
if
params
[
'html'
]
...
...
spec/controllers/projects/notes_controller_spec.rb
View file @
2036458e
...
...
@@ -207,6 +207,14 @@ describe Projects::NotesController do
expect
(
response
).
to
have_gitlab_http_status
(
200
)
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
before
do
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