2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module RendersNotes
|
2018-03-17 18:26:18 +05:30
|
|
|
# rubocop:disable Gitlab/ModuleWithInstanceVariables
|
|
|
|
def prepare_notes_for_rendering(notes, noteable = nil)
|
2017-08-17 22:00:37 +05:30
|
|
|
preload_noteable_for_regular_notes(notes)
|
|
|
|
preload_max_access_for_authors(notes, @project)
|
2018-11-18 11:00:15 +05:30
|
|
|
preload_author_status(notes)
|
2018-05-09 12:01:36 +05:30
|
|
|
Notes::RenderService.new(current_user).execute(notes)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
notes
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
# rubocop:enable Gitlab/ModuleWithInstanceVariables
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def preload_max_access_for_authors(notes, project)
|
2019-07-07 11:18:12 +05:30
|
|
|
return unless project
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
user_ids = notes.map(&:author_id)
|
2020-11-24 15:15:51 +05:30
|
|
|
access = project.team.max_member_access_for_user_ids(user_ids).select { |k, v| v == Gitlab::Access::NO_ACCESS }.keys
|
|
|
|
project.team.contribution_check_for_user_ids(access)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
def preload_noteable_for_regular_notes(notes)
|
2023-05-27 22:25:52 +05:30
|
|
|
ActiveRecord::Associations::Preloader.new(records: notes.reject(&:for_commit?), associations: :noteable).call
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-11-18 11:00:15 +05:30
|
|
|
def preload_author_status(notes)
|
2023-05-27 22:25:52 +05:30
|
|
|
ActiveRecord::Associations::Preloader.new(records: notes, associations: { author: :status }).call
|
2018-11-18 11:00:15 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|