2019-01-28 07:19:53 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UsersStarProjectsFinder
|
|
|
|
include CustomAttributesFilter
|
|
|
|
|
|
|
|
attr_accessor :params
|
|
|
|
|
2019-02-02 14:53:21 -05:00
|
|
|
def initialize(project, params = {}, current_user: nil)
|
2019-01-28 07:19:53 -05:00
|
|
|
@params = params
|
2019-02-02 14:22:19 -05:00
|
|
|
@project = project
|
|
|
|
@current_user = current_user
|
2019-01-28 07:19:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2019-08-03 06:57:33 -04:00
|
|
|
stars = UsersStarProject.all
|
2019-02-02 14:22:19 -05:00
|
|
|
stars = by_project(stars)
|
2019-01-28 07:19:53 -05:00
|
|
|
stars = by_search(stars)
|
2019-02-02 14:22:19 -05:00
|
|
|
stars = filter_visible_profiles(stars)
|
2019-01-28 07:19:53 -05:00
|
|
|
|
|
|
|
stars
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def by_search(items)
|
2019-01-28 12:51:49 -05:00
|
|
|
params[:search].present? ? items.search(params[:search]) : items
|
2019-01-28 07:19:53 -05:00
|
|
|
end
|
2019-02-02 14:22:19 -05:00
|
|
|
|
|
|
|
def by_project(items)
|
|
|
|
items.by_project(@project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def filter_visible_profiles(items)
|
|
|
|
items.with_visible_profile(@current_user)
|
|
|
|
end
|
2019-01-28 07:19:53 -05:00
|
|
|
end
|