2021-09-21 06:08:55 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Clusters
|
|
|
|
class AgentsFinder
|
2022-06-07 12:08:05 +00:00
|
|
|
include FinderMethods
|
|
|
|
|
2022-06-23 21:09:13 +00:00
|
|
|
def initialize(object, current_user, params: {})
|
|
|
|
@object = object
|
2021-09-21 06:08:55 +00:00
|
|
|
@current_user = current_user
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
return ::Clusters::Agent.none unless can_read_cluster_agents?
|
|
|
|
|
2022-06-23 21:09:13 +00:00
|
|
|
agents = object.cluster_agents
|
2021-09-21 06:08:55 +00:00
|
|
|
agents = agents.with_name(params[:name]) if params[:name].present?
|
|
|
|
|
|
|
|
agents.ordered_by_name
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-06-23 21:09:13 +00:00
|
|
|
attr_reader :object, :current_user, :params
|
2021-09-21 06:08:55 +00:00
|
|
|
|
|
|
|
def can_read_cluster_agents?
|
2022-06-23 21:09:13 +00:00
|
|
|
current_user&.can?(:read_cluster, object)
|
2021-09-21 06:08:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|