debian-mirror-gitlab/app/finders/fork_targets_finder.rb

45 lines
1.1 KiB
Ruby
Raw Normal View History

2020-04-08 14:13:33 +05:30
# frozen_string_literal: true
class ForkTargetsFinder
def initialize(project, user)
@project = project
@user = user
end
2020-11-24 15:15:51 +05:30
def execute(options = {})
2022-08-27 11:52:29 +05:30
return previous_execute(options) unless Feature.enabled?(:searchable_fork_targets)
2020-11-24 15:15:51 +05:30
2022-08-27 11:52:29 +05:30
items = fork_targets(options)
by_search(items, options)
2020-04-08 14:13:33 +05:30
end
private
attr_reader :project, :user
2022-08-27 11:52:29 +05:30
def by_search(items, options)
return items if options[:search].blank?
items.search(options[:search])
end
def fork_targets(options)
if options[:only_groups]
user.manageable_groups(include_groups_with_developer_maintainer_access: true)
else
user.forkable_namespaces.sort_by_type
end
end
# rubocop: disable CodeReuse/ActiveRecord
def previous_execute(options = {})
return ::Namespace.where(id: user.forkable_namespaces).sort_by_type unless options[:only_groups]
::Group.where(id: user.manageable_groups(include_groups_with_developer_maintainer_access: true))
end
# rubocop: enable CodeReuse/ActiveRecord
2020-04-08 14:13:33 +05:30
end
2021-06-08 01:23:25 +05:30
ForkTargetsFinder.prepend_mod_with('ForkTargetsFinder')