diff options
| author | Achilleas Pipinellis <axil@gitlab.com> | 2019-08-20 20:22:43 +0200 |
|---|---|---|
| committer | Achilleas Pipinellis <axil@gitlab.com> | 2019-08-20 20:22:43 +0200 |
| commit | e61308ce1d82e12e5087371469baea4a452875d1 (patch) | |
| tree | 62551a3ae4eab75e5af7e3b35358c07a51b2132f /lib/api/helpers/notes_helpers.rb | |
| parent | 4f323bb62fbe71a4352de25cab141f361a3fe1a6 (diff) | |
| parent | 2989ed078c1d45b0959dcecb1bc3c8f4740a3c0d (diff) | |
| download | gitlab-ce-docs-patch-71.tar.gz | |
Merge branch 'master' into docs-patch-71docs-patch-71
Diffstat (limited to 'lib/api/helpers/notes_helpers.rb')
| -rw-r--r-- | lib/api/helpers/notes_helpers.rb | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/api/helpers/notes_helpers.rb b/lib/api/helpers/notes_helpers.rb index a068de4361c..6bf9057fad7 100644 --- a/lib/api/helpers/notes_helpers.rb +++ b/lib/api/helpers/notes_helpers.rb @@ -73,14 +73,29 @@ 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 = finder_params_by_noteable_type_and_id(noteable_type, noteable_id, parent_id) - readable = can?(current_user, noteable_read_ability_name(noteable), noteable) + noteable = NotesFinder.new(current_user, params).target + noteable = nil unless can?(current_user, noteable_read_ability_name(noteable), noteable) + noteable || not_found!(noteable_type) + end + + def finder_params_by_noteable_type_and_id(type, id, parent_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 - return not_found!(noteables_str) unless readable + add_parent_to_finder_params(h, type, parent_id) + end + end - noteable + def add_parent_to_finder_params(finder_params, noteable_type, parent_id) + finder_params[:project] = user_project end def noteable_parent(noteable) |
