renders_notes.rb 1003 Bytes
Newer Older
1
module RendersNotes
2
  # rubocop:disable Gitlab/ModuleWithInstanceVariables
3
  def prepare_notes_for_rendering(notes, noteable = nil)
4 5
    preload_noteable_for_regular_notes(notes)
    preload_max_access_for_authors(notes, @project)
6
    preload_first_time_contribution_for_authors(noteable, notes)
7
    Notes::RenderService.new(current_user).execute(notes, @project)
8 9 10

    notes
  end
11
  # rubocop:enable Gitlab/ModuleWithInstanceVariables
12 13 14 15

  private

  def preload_max_access_for_authors(notes, project)
16 17
    return nil unless project

18 19 20 21 22 23 24
    user_ids = notes.map(&:author_id)
    project.team.max_member_access_for_user_ids(user_ids)
  end

  def preload_noteable_for_regular_notes(notes)
    ActiveRecord::Associations::Preloader.new.preload(notes.reject(&:for_commit?), :noteable)
  end
25 26 27 28 29 30

  def preload_first_time_contribution_for_authors(noteable, notes)
    return unless noteable.is_a?(Issuable) && noteable.first_contribution?

    notes.each {|n| n.specialize_for_first_contribution!(noteable)}
  end
31
end