diff options
author | Stan Hu <stanhu@gmail.com> | 2019-07-26 22:29:07 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-07-26 22:29:07 +0000 |
commit | 7dccb44448aed3227072154f2385383c54f2d4f6 (patch) | |
tree | 8018495ca105fed75101f8546182bbe0521a914e /app/finders | |
parent | e59ba979446b6c8539f3569b693fe24836fe75ac (diff) | |
parent | 355a2df560dea2719a027ada718a923ab7876ffe (diff) | |
download | gitlab-ce-7dccb44448aed3227072154f2385383c54f2d4f6.tar.gz |
Merge branch '52123-issuable-actions-notesfinder-pderichs' into 'master'
Use NotesFinder to fetch notes in module IssuableActions
Closes #52123
See merge request gitlab-org/gitlab-ce!29733
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/notes_finder.rb | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/app/finders/notes_finder.rb b/app/finders/notes_finder.rb index 8f610d7dddb..c25600221d7 100644 --- a/app/finders/notes_finder.rb +++ b/app/finders/notes_finder.rb @@ -3,6 +3,8 @@ class NotesFinder FETCH_OVERLAP = 5.seconds + attr_reader :target_type + # Used to filter Notes # When used with target_type and target_id this returns notes specifically for the controller # @@ -10,6 +12,7 @@ class NotesFinder # current_user - which user check authorizations with # project - which project to look for notes on # params: + # target: noteable # target_type: string # target_id: integer # last_fetched_at: time @@ -18,7 +21,8 @@ class NotesFinder def initialize(project, current_user, params = {}) @project = project @current_user = current_user - @params = params + @params = params.dup + @target_type = @params[:target_type] end def execute @@ -32,7 +36,27 @@ class NotesFinder def target return @target if defined?(@target) - target_type = @params[:target_type] + if target_given? + use_explicit_target + else + find_target_by_type_and_ids + end + end + + private + + def target_given? + @params.key?(:target) + end + + def use_explicit_target + @target = @params[:target] + @target_type = @target.class.name.underscore + + @target + end + + def find_target_by_type_and_ids target_id = @params[:target_id] target_iid = @params[:target_iid] @@ -45,13 +69,11 @@ class NotesFinder @project.commit(target_id) end else - noteables_for_type_by_id(target_type, target_id, target_iid) + noteable_for_type_by_id(target_type, target_id, target_iid) end end - private - - def noteables_for_type_by_id(type, id, iid) + def noteable_for_type_by_id(type, id, iid) query = if id { id: id } else @@ -77,10 +99,6 @@ class NotesFinder search(notes) end - def target_type - @params[:target_type] - end - # rubocop: disable CodeReuse/ActiveRecord def notes_of_any_type types = %w(commit issue merge_request snippet) |