gitlab-org--gitlab-foss/app/finders/clusters_finder.rb
Thong Kuah 88800abcd8 Abstract out project out of ClustersController
To the extent possible swap out `project` with `clusterable`

- Abstract paths for showing cluster or clusters. This will allow us to
swap in alternative paths for group level cluster

- Push :project_id and :namespace_id params from the URL to the POST
body.

- Create a nice helper for to generate links for the destroy
action

For some reason, spec :project_id and :namespace_id param are not going
through `to_param` for a JSON format. Manually call `to_param` to fix
specs.

- Move :layout to BaseController
2018-11-01 19:36:58 +13:00

31 lines
551 B
Ruby

# frozen_string_literal: true
class ClustersFinder
def initialize(clusterable, user, scope)
@clusterable = clusterable
@user = user
@scope = scope || :active
end
def execute
clusters = clusterable.clusters
filter_by_scope(clusters)
end
private
attr_reader :clusterable, :user, :scope
def filter_by_scope(clusters)
case scope.to_sym
when :all
clusters
when :inactive
clusters.disabled
when :active
clusters.enabled
else
raise "Invalid scope #{scope}"
end
end
end