2018-09-11 19:08:34 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-20 15:41:11 +00:00
|
|
|
class MergeRequestTargetProjectFinder
|
2017-12-11 14:21:06 +00:00
|
|
|
include FinderMethods
|
|
|
|
|
2017-09-20 15:41:11 +00:00
|
|
|
attr_reader :current_user, :source_project
|
|
|
|
|
2017-09-21 16:34:32 +00:00
|
|
|
def initialize(current_user: nil, source_project:)
|
2017-09-20 15:41:11 +00:00
|
|
|
@current_user = current_user
|
|
|
|
@source_project = source_project
|
|
|
|
end
|
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2019-12-17 09:07:48 +00:00
|
|
|
def execute(include_routes: false)
|
|
|
|
if source_project.fork_network
|
|
|
|
include_routes ? projects.inc_routes : projects
|
2017-09-20 15:41:11 +00:00
|
|
|
else
|
|
|
|
Project.where(id: source_project)
|
|
|
|
end
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2019-12-17 09:07:48 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def projects
|
|
|
|
source_project
|
|
|
|
.fork_network
|
|
|
|
.projects
|
|
|
|
.public_or_visible_to_user(current_user)
|
|
|
|
.non_archived
|
|
|
|
.with_feature_available_for_user(:merge_requests, current_user)
|
|
|
|
end
|
2017-09-20 15:41:11 +00:00
|
|
|
end
|