diff options
author | Patrick Derichs <pderichs@gitlab.com> | 2019-06-15 07:10:58 +0200 |
---|---|---|
committer | Patrick Derichs <pderichs@gitlab.com> | 2019-06-19 10:56:55 +0200 |
commit | 932a9a0c77a02e1d948f45cffe5e936e915ae0bc (patch) | |
tree | cb1766d65bc00f56c83a044b6fc19712a9473f69 /app/finders | |
parent | ba952d53c5782e49b59ba3e5dd89c2c1eca02c80 (diff) | |
download | gitlab-ce-932a9a0c77a02e1d948f45cffe5e936e915ae0bc.tar.gz |
Use NotesFinder to fetch notes on API and Controllers
Fix missing iid query on NotesFinder
Changed parameters of find_noteable,
so changes across a few files were needed.
MergeRequest also requires iid instead of id query
Make NotesFinder fail with RecordNotFound again
Add specs for target_iid
Using RSpec tablesyntax for target_iid specs
Revert "Using RSpec tablesyntax for target_iid specs"
This reverts commit ba45c7f569a.
Allow find_by! here
Fix variable name
Add readable check
Revert "Add readable check"
This reverts commit 9e3a1a7aa39.
Remove unnecessary assignment
Add required changes for EE
Fix parameter count
Reduce code duplication by extracting a noteable module method
The call to find_noteable was redundant so
multiple files and lines have changed in that
commit to use the newly introduced module
method `noteable`.
Replace casecmp with include check
Add parent_type parameter
Revert "Reduce code duplication by extracting
a noteable module method"
This reverts commit 8c0923babff16.
Method is no longer needed
Check whether noteable can be read by user
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/notes_finder.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/app/finders/notes_finder.rb b/app/finders/notes_finder.rb index 817aac8b5d5..83bf015488f 100644 --- a/app/finders/notes_finder.rb +++ b/app/finders/notes_finder.rb @@ -34,8 +34,9 @@ class NotesFinder target_type = @params[:target_type] target_id = @params[:target_id] + target_iid = @params[:target_iid] - return @target = nil unless target_type && target_id + return @target = nil unless target_type && (target_id || target_iid) @target = if target_type == "commit" @@ -43,12 +44,22 @@ class NotesFinder @project.commit(target_id) end else - noteables_for_type(target_type).find(target_id) + noteables_for_type_by_id(target_type, target_id, target_iid) end end private + def noteables_for_type_by_id(type, id, iid) + query = if id + { id: id } + else + { iid: iid } + end + + noteables_for_type(type).find_by!(query) # rubocop: disable CodeReuse/ActiveRecord + end + def init_collection if target notes_on_target |