debian-mirror-gitlab/app/finders/clusters/agents_finder.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
772 B
Ruby
Raw Normal View History

2021-11-18 22:05:49 +05:30
# frozen_string_literal: true
module Clusters
class AgentsFinder
2022-07-23 23:45:48 +05:30
include FinderMethods
2022-08-13 15:12:31 +05:30
def initialize(object, current_user, params: {})
@object = object
2021-11-18 22:05:49 +05:30
@current_user = current_user
@params = params
end
def execute
return ::Clusters::Agent.none unless can_read_cluster_agents?
2022-08-13 15:12:31 +05:30
agents = filter_clusters(object.cluster_agents)
2021-11-18 22:05:49 +05:30
agents.ordered_by_name
end
private
2022-08-13 15:12:31 +05:30
attr_reader :object, :current_user, :params
def filter_clusters(agents)
agents = agents.with_name(params[:name]) if params[:name].present?
agents
end
2021-11-18 22:05:49 +05:30
def can_read_cluster_agents?
2022-08-13 15:12:31 +05:30
current_user&.can?(:read_cluster, object)
2021-11-18 22:05:49 +05:30
end
end
end
2022-08-13 15:12:31 +05:30
Clusters::AgentsFinder.prepend_mod_with('Clusters::AgentsFinder')