diff options
author | Achilleas Pipinellis <axilleas@axilleas.me> | 2016-01-21 22:59:15 +0100 |
---|---|---|
committer | Achilleas Pipinellis <axilleas@axilleas.me> | 2016-01-21 22:59:15 +0100 |
commit | 308abc8db05f75da8f1cc66facb5e85bee5c69c4 (patch) | |
tree | 6b0acf3cbcf7036fb831381cfe195ad572d6a3c8 /lib/api/notes.rb | |
parent | a42fe49c8c953c0aa8ca20c8fb5a141447128894 (diff) | |
parent | c176fb40a52d32edc54843a5b54884cbab1e67e1 (diff) | |
download | gitlab-ce-308abc8db05f75da8f1cc66facb5e85bee5c69c4.tar.gz |
Merge branch 'master' into housekeeping-doc
Diffstat (limited to 'lib/api/notes.rb')
-rw-r--r-- | lib/api/notes.rb | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/api/notes.rb b/lib/api/notes.rb index 3efdfe2d46e..174473f5371 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -20,7 +20,19 @@ module API # GET /projects/:id/snippets/:noteable_id/notes get ":id/#{noteables_str}/:#{noteable_id_str}/notes" do @noteable = user_project.send(:"#{noteables_str}").find(params[:"#{noteable_id_str}"]) - present paginate(@noteable.notes), with: Entities::Note + + # We exclude notes that are cross-references and that cannot be viewed + # by the current user. By doing this exclusion at this level and not + # at the DB query level (which we cannot in that case), the current + # page can have less elements than :per_page even if + # there's more than one page. + notes = + # paginate() only works with a relation. This could lead to a + # mismatch between the pagination headers info and the actual notes + # array returned, but this is really a edge-case. + paginate(@noteable.notes). + reject { |n| n.cross_reference_not_visible_for?(current_user) } + present notes, with: Entities::Note end # Get a single +noteable+ note @@ -35,7 +47,12 @@ module API get ":id/#{noteables_str}/:#{noteable_id_str}/notes/:note_id" do @noteable = user_project.send(:"#{noteables_str}").find(params[:"#{noteable_id_str}"]) @note = @noteable.notes.find(params[:note_id]) - present @note, with: Entities::Note + + if @note.cross_reference_not_visible_for?(current_user) + not_found!("Note") + else + present @note, with: Entities::Note + end end # Create a new +noteable+ note |