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
Jérome Perrin
gitlab-ce
Commits
76c3d2d4
Commit
76c3d2d4
authored
Jun 09, 2017
by
Douwe Maan
Committed by
Fatih Acet
Jul 21, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add full JSON endpoints for issue notes and discussions
parent
cb2287df
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
149 additions
and
24 deletions
+149
-24
app/controllers/concerns/notes_actions.rb
app/controllers/concerns/notes_actions.rb
+30
-19
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+8
-0
app/helpers/issues_helper.rb
app/helpers/issues_helper.rb
+1
-1
app/helpers/system_note_helper.rb
app/helpers/system_note_helper.rb
+7
-1
app/models/discussion.rb
app/models/discussion.rb
+4
-0
app/serializers/award_emoji_entity.rb
app/serializers/award_emoji_entity.rb
+4
-0
app/serializers/discussion_entity.rb
app/serializers/discussion_entity.rb
+20
-0
app/serializers/discussion_serializer.rb
app/serializers/discussion_serializer.rb
+3
-0
app/serializers/note_attachment_entity.rb
app/serializers/note_attachment_entity.rb
+5
-0
app/serializers/note_entity.rb
app/serializers/note_entity.rb
+58
-0
app/serializers/note_serializer.rb
app/serializers/note_serializer.rb
+3
-0
app/serializers/user_entity.rb
app/serializers/user_entity.rb
+2
-0
app/views/discussions/_headline.html.haml
app/views/discussions/_headline.html.haml
+1
-1
config/routes/project.rb
config/routes/project.rb
+1
-0
lib/api/entities.rb
lib/api/entities.rb
+2
-2
No files found.
app/controllers/concerns/notes_actions.rb
View file @
76c3d2d4
...
@@ -11,13 +11,15 @@ module NotesActions
...
@@ -11,13 +11,15 @@ module NotesActions
notes_json
=
{
notes:
[],
last_fetched_at:
current_fetched_at
}
notes_json
=
{
notes:
[],
last_fetched_at:
current_fetched_at
}
@notes
=
notes_finder
.
execute
.
inc_relations_for_view
@notes
=
notes_finder
.
execute
.
inc_relations_for_view
.
to_a
@notes
.
reject!
{
|
n
|
n
.
cross_reference_not_visible_for?
(
current_user
)
}
@notes
=
prepare_notes_for_rendering
(
@notes
)
@notes
=
prepare_notes_for_rendering
(
@notes
)
@notes
.
each
do
|
note
|
notes_json
[
:notes
]
=
next
if
note
.
cross_reference_not_visible_for?
(
current_user
)
if
params
[
:full_data
]
note_serializer
.
represent
(
@notes
)
notes_json
[
:notes
]
<<
note_json
(
note
)
else
@notes
.
map
{
|
note
|
note_json
(
note
)
}
end
end
render
json:
notes_json
render
json:
notes_json
...
@@ -80,8 +82,12 @@ module NotesActions
...
@@ -80,8 +82,12 @@ module NotesActions
}
}
if
note
.
persisted?
if
note
.
persisted?
attrs
[
:valid
]
=
true
if
params
[
:full_data
]
attrs
.
merge!
(
note_serializer
.
represent
(
note
))
else
attrs
.
merge!
(
attrs
.
merge!
(
valid:
true
,
id:
note
.
id
,
id:
note
.
id
,
discussion_id:
note
.
discussion_id
(
noteable
),
discussion_id:
note
.
discussion_id
(
noteable
),
html:
note_html
(
note
),
html:
note_html
(
note
),
...
@@ -97,6 +103,7 @@ module NotesActions
...
@@ -97,6 +103,7 @@ module NotesActions
discussion_html:
discussion_html
(
discussion
)
discussion_html:
discussion_html
(
discussion
)
)
)
end
end
end
else
else
attrs
.
merge!
(
attrs
.
merge!
(
valid:
false
,
valid:
false
,
...
@@ -177,4 +184,8 @@ module NotesActions
...
@@ -177,4 +184,8 @@ module NotesActions
def
notes_finder
def
notes_finder
@notes_finder
||=
NotesFinder
.
new
(
project
,
current_user
,
finder_params
)
@notes_finder
||=
NotesFinder
.
new
(
project
,
current_user
,
finder_params
)
end
end
def
note_serializer
NoteSerializer
.
new
(
project:
project
,
noteable:
noteable
,
current_user:
current_user
)
end
end
end
app/controllers/projects/issues_controller.rb
View file @
76c3d2d4
...
@@ -97,6 +97,14 @@ class Projects::IssuesController < Projects::ApplicationController
...
@@ -97,6 +97,14 @@ class Projects::IssuesController < Projects::ApplicationController
end
end
end
end
def
discussions
@discussions
=
@issue
.
discussions
@discussions
.
reject!
{
|
d
|
d
.
individual_note?
&&
d
.
first_note
.
cross_reference_not_visible_for?
(
current_user
)
}
prepare_notes_for_rendering
(
@discussions
.
flat_map
(
&
:notes
))
render
json:
DiscussionSerializer
.
new
(
project:
@project
,
noteable:
@issue
,
current_user:
current_user
).
represent
(
@discussions
)
end
def
create
def
create
create_params
=
issue_params
.
merge
(
spammable_params
).
merge
(
create_params
=
issue_params
.
merge
(
spammable_params
).
merge
(
merge_request_to_resolve_discussions_of:
params
[
:merge_request_to_resolve_discussions_of
],
merge_request_to_resolve_discussions_of:
params
[
:merge_request_to_resolve_discussions_of
],
...
...
app/helpers/issues_helper.rb
View file @
76c3d2d4
...
@@ -119,7 +119,7 @@ module IssuesHelper
...
@@ -119,7 +119,7 @@ module IssuesHelper
end
end
def
awards_sort
(
awards
)
def
awards_sort
(
awards
)
awards
.
sort_by
do
|
award
,
note
s
|
awards
.
sort_by
do
|
award
,
award_emoji
s
|
if
award
==
"thumbsup"
if
award
==
"thumbsup"
0
0
elsif
award
==
"thumbsdown"
elsif
award
==
"thumbsdown"
...
...
app/helpers/system_note_helper.rb
View file @
76c3d2d4
...
@@ -21,8 +21,14 @@ module SystemNoteHelper
...
@@ -21,8 +21,14 @@ module SystemNoteHelper
'outdated'
=>
'icon_edit'
'outdated'
=>
'icon_edit'
}.
freeze
}.
freeze
def
system_note_icon_name
(
note
)
ICON_NAMES_BY_ACTION
[
note
.
system_note_metadata
&
.
action
]
end
def
icon_for_system_note
(
note
)
def
icon_for_system_note
(
note
)
icon_name
=
ICON_NAMES_BY_ACTION
[
note
.
system_note_metadata
&
.
action
]
icon_name
=
system_note_icon_name
(
note
)
custom_icon
(
icon_name
)
if
icon_name
custom_icon
(
icon_name
)
if
icon_name
end
end
extend
self
end
end
app/models/discussion.rb
View file @
76c3d2d4
...
@@ -81,6 +81,10 @@ class Discussion
...
@@ -81,6 +81,10 @@ class Discussion
last_note
.
author
last_note
.
author
end
end
def
updated?
last_updated_at
!=
created_at
end
def
id
def
id
first_note
.
discussion_id
(
context_noteable
)
first_note
.
discussion_id
(
context_noteable
)
end
end
...
...
app/serializers/award_emoji_entity.rb
0 → 100644
View file @
76c3d2d4
class
AwardEmojiEntity
<
Grape
::
Entity
expose
:name
expose
:user
,
using:
API
::
Entities
::
UserSafe
end
app/serializers/discussion_entity.rb
0 → 100644
View file @
76c3d2d4
class
DiscussionEntity
<
Grape
::
Entity
include
RequestAwareEntity
expose
:id
,
:reply_id
expose
:expanded?
,
as: :expanded
expose
:author
,
using:
UserEntity
expose
:created_at
expose
:last_updated_at
,
if:
->
(
discussion
,
_
)
{
discussion
.
updated?
}
expose
:last_updated_by
,
if:
->
(
discussion
,
_
)
{
discussion
.
updated?
},
using:
UserEntity
expose
:notes
,
using:
NoteEntity
expose
:individual_note?
,
as: :individual_note
expose
:can_reply
do
|
discussion
|
can?
(
request
.
current_user
,
:create_note
,
discussion
.
project
)
end
end
app/serializers/discussion_serializer.rb
0 → 100644
View file @
76c3d2d4
class
DiscussionSerializer
<
BaseSerializer
entity
DiscussionEntity
end
app/serializers/note_attachment_entity.rb
0 → 100644
View file @
76c3d2d4
class
NoteAttachmentEntity
<
Grape
::
Entity
expose
:url
expose
:filename
expose
:image?
,
as: :image
end
app/serializers/note_entity.rb
0 → 100644
View file @
76c3d2d4
class
NoteEntity
<
API
::
Entities
::
Note
include
RequestAwareEntity
expose
:type
expose
:author
,
using:
UserEntity
expose
:human_access
do
|
note
|
note
.
project
.
team
.
human_max_access
(
note
.
author_id
)
end
unexpose
:note
,
as: :body
expose
:note
expose
:redacted_note_html
,
as: :note_html
expose
:last_edited_at
,
if:
->
(
note
,
_
)
{
note
.
is_edited?
}
expose
:last_edited_by
,
using:
UserEntity
,
if:
->
(
note
,
_
)
{
note
.
is_edited?
}
expose
:can_edit
do
|
note
|
Ability
.
can_edit_note?
(
request
.
current_user
,
note
)
end
expose
:system_note_icon_name
,
if:
->
(
note
,
_
)
{
note
.
system?
}
do
|
note
|
SystemNoteHelper
.
system_note_icon_name
(
note
)
end
expose
:discussion_id
do
|
note
|
note
.
discussion_id
(
request
.
noteable
)
end
expose
:emoji_awardable?
,
as: :emoji_awardable
expose
:award_emoji
,
if:
->
(
note
,
_
)
{
note
.
emoji_awardable?
},
using:
AwardEmojiEntity
expose
:toggle_award_path
,
if:
->
(
note
,
_
)
{
note
.
emoji_awardable?
}
do
|
note
|
if
note
.
for_personal_snippet?
toggle_award_emoji_snippet_note_path
(
note
.
noteable
,
note
)
else
toggle_award_emoji_namespace_project_note_path
(
note
.
project
.
namespace
,
note
.
project
,
note
.
id
)
end
end
expose
:report_abuse_path
do
|
note
|
new_abuse_report_path
(
user_id:
note
.
author
.
id
,
ref_url:
Gitlab
::
UrlBuilder
.
build
(
note
))
end
expose
:path
do
|
note
|
if
note
.
for_personal_snippet?
snippet_note_path
(
note
.
noteable
,
note
)
else
namespace_project_note_path
(
note
.
project
.
namespace
,
note
.
project
,
note
)
end
end
expose
:attachment
,
using:
NoteAttachmentEntity
expose
:delete_attachment_path
,
if:
->
(
note
,
_
)
{
note
.
attachment?
}
do
|
note
|
delete_attachment_namespace_project_note_path
(
note
.
project
.
namespace
,
note
.
project
,
note
)
end
end
app/serializers/note_serializer.rb
0 → 100644
View file @
76c3d2d4
class
NoteSerializer
<
BaseSerializer
entity
NoteEntity
end
app/serializers/user_entity.rb
View file @
76c3d2d4
class
UserEntity
<
API
::
Entities
::
UserBasic
class
UserEntity
<
API
::
Entities
::
UserBasic
include
RequestAwareEntity
include
RequestAwareEntity
unexpose
:web_url
expose
:path
do
|
user
|
expose
:path
do
|
user
|
user_path
(
user
)
user_path
(
user
)
end
end
...
...
app/views/discussions/_headline.html.haml
View file @
76c3d2d4
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
by
by
=
link_to_member
(
@project
,
discussion
.
resolved_by
,
avatar:
false
)
=
link_to_member
(
@project
,
discussion
.
resolved_by
,
avatar:
false
)
=
time_ago_with_tooltip
(
discussion
.
resolved_at
,
placement:
"bottom"
)
=
time_ago_with_tooltip
(
discussion
.
resolved_at
,
placement:
"bottom"
)
-
elsif
discussion
.
last_updated_at
!=
discussion
.
created_at
-
elsif
discussion
.
updated?
.discussion-headline-light.js-discussion-headline
.discussion-headline-light.js-discussion-headline
Last updated
Last updated
-
if
discussion
.
last_updated_by
-
if
discussion
.
last_updated_by
...
...
config/routes/project.rb
View file @
76c3d2d4
...
@@ -308,6 +308,7 @@ constraints(ProjectUrlConstrainer.new) do
...
@@ -308,6 +308,7 @@ constraints(ProjectUrlConstrainer.new) do
get
:can_create_branch
get
:can_create_branch
get
:realtime_changes
get
:realtime_changes
post
:create_merge_request
post
:create_merge_request
get
:discussions
,
format: :json
end
end
collection
do
collection
do
post
:bulk_update
post
:bulk_update
...
...
lib/api/entities.rb
View file @
76c3d2d4
module
API
module
API
module
Entities
module
Entities
class
UserSafe
<
Grape
::
Entity
class
UserSafe
<
Grape
::
Entity
expose
:name
,
:username
expose
:
id
,
:
name
,
:username
end
end
class
UserBasic
<
UserSafe
class
UserBasic
<
UserSafe
expose
:
id
,
:
state
expose
:state
expose
:avatar_url
do
|
user
,
options
|
expose
:avatar_url
do
|
user
,
options
|
user
.
avatar_url
(
only_path:
false
)
user
.
avatar_url
(
only_path:
false
)
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