diff options
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/discussions.rb | 18 | ||||
-rw-r--r-- | lib/api/helpers/notes_helpers.rb | 10 | ||||
-rw-r--r-- | lib/api/notes.rb | 10 | ||||
-rw-r--r-- | lib/api/resource_label_events.rb | 5 |
4 files changed, 22 insertions, 21 deletions
diff --git a/lib/api/discussions.rb b/lib/api/discussions.rb index 9125207167c..25d38615c7f 100644 --- a/lib/api/discussions.rb +++ b/lib/api/discussions.rb @@ -26,7 +26,7 @@ module API end get ":id/#{noteables_path}/:noteable_id/discussions" do - noteable = find_noteable(parent_type, params[:id], noteable_type, params[:noteable_id]) + noteable = find_noteable(noteable_type, params[:noteable_id]) notes = readable_discussion_notes(noteable) discussions = Kaminari.paginate_array(Discussion.build_collection(notes, noteable)) @@ -42,7 +42,7 @@ module API requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' end get ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id" do - noteable = find_noteable(parent_type, params[:id], noteable_type, params[:noteable_id]) + noteable = find_noteable(noteable_type, params[:noteable_id]) notes = readable_discussion_notes(noteable, params[:discussion_id]) if notes.empty? @@ -77,7 +77,7 @@ module API end end post ":id/#{noteables_path}/:noteable_id/discussions" do - noteable = find_noteable(parent_type, params[:id], noteable_type, params[:noteable_id]) + noteable = find_noteable(noteable_type, params[:noteable_id]) type = params[:position] ? 'DiffNote' : 'DiscussionNote' id_key = noteable.is_a?(Commit) ? :commit_id : :noteable_id @@ -107,7 +107,7 @@ module API requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' end get ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes" do - noteable = find_noteable(parent_type, params[:id], noteable_type, params[:noteable_id]) + noteable = find_noteable(noteable_type, params[:noteable_id]) notes = readable_discussion_notes(noteable, params[:discussion_id]) if notes.empty? @@ -127,7 +127,7 @@ module API optional :created_at, type: String, desc: 'The creation date of the note' end post ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes" do - noteable = find_noteable(parent_type, params[:id], noteable_type, params[:noteable_id]) + noteable = find_noteable(noteable_type, params[:noteable_id]) notes = readable_discussion_notes(noteable, params[:discussion_id]) first_note = notes.first @@ -161,7 +161,7 @@ module API requires :note_id, type: Integer, desc: 'The ID of a note' end get ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes/:note_id" do - noteable = find_noteable(parent_type, params[:id], noteable_type, params[:noteable_id]) + noteable = find_noteable(noteable_type, params[:noteable_id]) get_note(noteable, params[:note_id]) end @@ -178,7 +178,7 @@ module API exactly_one_of :body, :resolved end put ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes/:note_id" do - noteable = find_noteable(parent_type, params[:id], noteable_type, params[:noteable_id]) + noteable = find_noteable(noteable_type, params[:noteable_id]) if params[:resolved].nil? update_note(noteable, params[:note_id]) @@ -196,7 +196,7 @@ module API requires :note_id, type: Integer, desc: 'The ID of a note' end delete ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes/:note_id" do - noteable = find_noteable(parent_type, params[:id], noteable_type, params[:noteable_id]) + noteable = find_noteable(noteable_type, params[:noteable_id]) delete_note(noteable, params[:note_id]) end @@ -211,7 +211,7 @@ module API requires :resolved, type: Boolean, desc: 'Mark discussion resolved/unresolved' end put ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id" do - noteable = find_noteable(parent_type, params[:id], noteable_type, params[:noteable_id]) + noteable = find_noteable(noteable_type, params[:noteable_id]) resolve_discussion(noteable, params[:discussion_id], params[:resolved]) end diff --git a/lib/api/helpers/notes_helpers.rb b/lib/api/helpers/notes_helpers.rb index 2dd95aba6bc..3c453953e37 100644 --- a/lib/api/helpers/notes_helpers.rb +++ b/lib/api/helpers/notes_helpers.rb @@ -83,15 +83,15 @@ module API end end - 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) + def find_noteable(noteable_type, noteable_id) + params = finder_params_by_noteable_type_and_id(noteable_type, noteable_id) 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) + def finder_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) @@ -100,11 +100,11 @@ module API h[:target_id] = id end - add_parent_to_finder_params(h, type, parent_id) + add_parent_to_finder_params(h, type) end end - def add_parent_to_finder_params(finder_params, noteable_type, parent_id) + def add_parent_to_finder_params(finder_params, noteable_type) finder_params[:project] = user_project end diff --git a/lib/api/notes.rb b/lib/api/notes.rb index 9575e8e9f36..35eda481a4f 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -30,7 +30,7 @@ module API end # rubocop: disable CodeReuse/ActiveRecord get ":id/#{noteables_str}/:noteable_id/notes" do - noteable = find_noteable(parent_type, params[:id], noteable_type, params[:noteable_id]) + noteable = find_noteable(noteable_type, params[:noteable_id]) # We exclude notes that are cross-references and that cannot be viewed # by the current user. By doing this exclusion at this level and not @@ -58,7 +58,7 @@ module API requires :noteable_id, type: Integer, desc: 'The ID of the noteable' end get ":id/#{noteables_str}/:noteable_id/notes/:note_id" do - noteable = find_noteable(parent_type, params[:id], noteable_type, params[:noteable_id]) + noteable = find_noteable(noteable_type, params[:noteable_id]) get_note(noteable, params[:note_id]) end @@ -71,7 +71,7 @@ module API optional :created_at, type: String, desc: 'The creation date of the note' end post ":id/#{noteables_str}/:noteable_id/notes" do - noteable = find_noteable(parent_type, params[:id], noteable_type, params[:noteable_id]) + noteable = find_noteable(noteable_type, params[:noteable_id]) opts = { note: params[:body], @@ -98,7 +98,7 @@ module API requires :body, type: String, desc: 'The content of a note' end put ":id/#{noteables_str}/:noteable_id/notes/:note_id" do - noteable = find_noteable(parent_type, params[:id], noteable_type, params[:noteable_id]) + noteable = find_noteable(noteable_type, params[:noteable_id]) update_note(noteable, params[:note_id]) end @@ -111,7 +111,7 @@ module API requires :note_id, type: Integer, desc: 'The ID of a note' end delete ":id/#{noteables_str}/:noteable_id/notes/:note_id" do - noteable = find_noteable(parent_type, params[:id], noteable_type, params[:noteable_id]) + noteable = find_noteable(noteable_type, params[:noteable_id]) delete_note(noteable, params[:note_id]) end diff --git a/lib/api/resource_label_events.rb b/lib/api/resource_label_events.rb index 062115c5103..f7f7c881f4a 100644 --- a/lib/api/resource_label_events.rb +++ b/lib/api/resource_label_events.rb @@ -25,7 +25,7 @@ module API end get ":id/#{eventables_str}/:eventable_id/resource_label_events" do - eventable = find_noteable(parent_type, params[:id], eventable_type, params[:eventable_id]) + eventable = find_noteable(eventable_type, params[:eventable_id]) opts = { page: params[:page], per_page: params[:per_page] } events = ResourceLabelEventFinder.new(current_user, eventable, opts).execute @@ -42,7 +42,8 @@ module API requires :eventable_id, types: [Integer, String], desc: 'The ID of the eventable' end get ":id/#{eventables_str}/:eventable_id/resource_label_events/:event_id" do - eventable = find_noteable(parent_type, params[:id], eventable_type, params[:eventable_id]) + eventable = find_noteable(eventable_type, params[:eventable_id]) + event = eventable.resource_label_events.find(params[:event_id]) not_found!('ResourceLabelEvent') unless can?(current_user, :read_resource_label_event, event) |