diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-01-14 10:36:39 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-01-14 10:36:39 +0000 |
commit | 9f8c38bdac3d6f532b50ecab1d769652ffb5acc3 (patch) | |
tree | 4ed39c5ad4d840d3852836efafbd1dd6b59ee50b /lib/api | |
parent | 54734fa6132de6ba2430cba6b279723d1aec8c19 (diff) | |
parent | e918493f55eb27cdb779f0bc2d8cbbace8b69aa9 (diff) | |
download | gitlab-ce-9f8c38bdac3d6f532b50ecab1d769652ffb5acc3.tar.gz |
Merge branch 'fix/private-references' into 'master'
Show referenced MRs & Issues only when the current viewer can access them
This addresses both issues identified in #6066.
## The private MR by user `remy2` with a note referencing to a public issue

---
## The public issue viewed by user `remy` **who doesn't have access to `remy2/private-project`** before the fix

---
## The public issue viewed by user `remy` **who doesn't have access to `remy2/private-project`** with the fix

---
## The public issue viewed by user `remy2` with the fix (no change)

See merge request !2405
Diffstat (limited to 'lib/api')
-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 |