summaryrefslogtreecommitdiff
path: root/lib/api/helpers
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2019-06-19 15:58:43 +0000
committerRobert Speicher <rspeicher@gmail.com>2019-06-19 15:58:43 +0000
commitea1b24cbe01d4d76fce693cbf329896e2203ae3d (patch)
treee47190ba7a7e6e40f690210cac1121882929b031 /lib/api/helpers
parent9fa2b6578745658c36ced14a4ad1afe75c56ecc1 (diff)
parent5469d21d02d2969f7b1c629ebd5e5696c664736c (diff)
downloadgitlab-ce-ea1b24cbe01d4d76fce693cbf329896e2203ae3d.tar.gz
Merge branch 'pderichs-52123' into 'master'
Use NotesFinder to get Noteable See merge request gitlab-org/gitlab-ce!28205
Diffstat (limited to 'lib/api/helpers')
-rw-r--r--lib/api/helpers/notes_helpers.rb21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/api/helpers/notes_helpers.rb b/lib/api/helpers/notes_helpers.rb
index a068de4361c..b03ac7deb71 100644
--- a/lib/api/helpers/notes_helpers.rb
+++ b/lib/api/helpers/notes_helpers.rb
@@ -73,14 +73,23 @@ module API
"read_#{noteable.class.to_s.underscore}".to_sym
end
- def find_noteable(parent, noteables_str, noteable_id)
- noteable = public_send("find_#{parent}_#{noteables_str.singularize}", noteable_id) # rubocop:disable GitlabSecurity/PublicSend
+ def find_noteable(parent_type, parent_id, noteable_type, noteable_id)
+ params = params_by_noteable_type_and_id(noteable_type, noteable_id)
- readable = can?(current_user, noteable_read_ability_name(noteable), noteable)
-
- return not_found!(noteables_str) unless readable
+ noteable = NotesFinder.new(user_project, current_user, params).target
+ noteable = nil unless can?(current_user, noteable_read_ability_name(noteable), noteable)
+ noteable || not_found!(noteable_type)
+ end
- noteable
+ def params_by_noteable_type_and_id(type, id)
+ target_type = type.name.underscore
+ { target_type: target_type }.tap do |h|
+ if %w(issue merge_request).include?(target_type)
+ h[:target_iid] = id
+ else
+ h[:target_id] = id
+ end
+ end
end
def noteable_parent(noteable)