move_to_project_finder.rb 609 Bytes
Newer Older
1
class MoveToProjectFinder
2 3
  PAGE_SIZE = 50

4 5 6 7 8 9 10 11
  def initialize(user)
    @user = user
  end

  def execute(from_project, search: nil, offset_id: nil)
    projects = @user.projects_where_can_admin_issues
    projects = projects.search(search) if search.present?
    projects = projects.excluding_project(from_project)
12
    projects = projects.order_id_desc
13

14 15 16 17
    # infinite scroll using offset
    projects = projects.where('projects.id < ?', offset_id) if offset_id.present?
    projects = projects.limit(PAGE_SIZE)

18 19 20 21
    # to ask for Project#name_with_namespace
    projects.includes(namespace: :owner)
  end
end