Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/finders/clusters/agents_finder.rb')
-rw-r--r--app/finders/clusters/agents_finder.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/finders/clusters/agents_finder.rb b/app/finders/clusters/agents_finder.rb
new file mode 100644
index 00000000000..136bbf16981
--- /dev/null
+++ b/app/finders/clusters/agents_finder.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+module Clusters
+ class AgentsFinder
+ def initialize(project, current_user, params: {})
+ @project = project
+ @current_user = current_user
+ @params = params
+ end
+
+ def execute
+ return ::Clusters::Agent.none unless can_read_cluster_agents?
+
+ agents = project.cluster_agents
+ agents = agents.with_name(params[:name]) if params[:name].present?
+
+ agents.ordered_by_name
+ end
+
+ private
+
+ attr_reader :project, :current_user, :params
+
+ def can_read_cluster_agents?
+ current_user.can?(:read_cluster, project)
+ end
+ end
+end