Commit 79bff3ee authored by Robert Speicher's avatar Robert Speicher

Merge branch '12026-use-notes-finder-target-for-epics-ce' into 'master'

Use NotesFinder#target to find Epics

See merge request gitlab-org/gitlab-ce!31408
parents f541889f c69a4704
...@@ -74,14 +74,14 @@ module API ...@@ -74,14 +74,14 @@ module API
end end
def find_noteable(parent_type, parent_id, noteable_type, noteable_id) def find_noteable(parent_type, parent_id, noteable_type, noteable_id)
params = params_by_noteable_type_and_id(noteable_type, noteable_id) params = finder_params_by_noteable_type_and_id(noteable_type, noteable_id, parent_id)
noteable = NotesFinder.new(current_user, params.merge(project: user_project)).target noteable = NotesFinder.new(current_user, params).target
noteable = nil unless can?(current_user, noteable_read_ability_name(noteable), noteable) noteable = nil unless can?(current_user, noteable_read_ability_name(noteable), noteable)
noteable || not_found!(noteable_type) noteable || not_found!(noteable_type)
end end
def params_by_noteable_type_and_id(type, id) def finder_params_by_noteable_type_and_id(type, id, parent_id)
target_type = type.name.underscore target_type = type.name.underscore
{ target_type: target_type }.tap do |h| { target_type: target_type }.tap do |h|
if %w(issue merge_request).include?(target_type) if %w(issue merge_request).include?(target_type)
...@@ -89,9 +89,15 @@ module API ...@@ -89,9 +89,15 @@ module API
else else
h[:target_id] = id h[:target_id] = id
end end
add_parent_to_finder_params(h, type, parent_id)
end end
end end
def add_parent_to_finder_params(finder_params, noteable_type, parent_id)
finder_params[:project] = user_project
end
def noteable_parent(noteable) def noteable_parent(noteable)
public_send("user_#{noteable.class.parent_class.to_s.underscore}") # rubocop:disable GitlabSecurity/PublicSend public_send("user_#{noteable.class.parent_class.to_s.underscore}") # rubocop:disable GitlabSecurity/PublicSend
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment