diff options
author | Thong Kuah <tkuah@gitlab.com> | 2018-11-07 01:13:33 +1300 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2018-11-12 21:59:20 +1300 |
commit | e109b6f4aebe76151025ec94fd6b03e334fe4472 (patch) | |
tree | e00ed0c54d337d88edf3a6dfe8025ad704e58e68 | |
parent | f69f7a6702f68a14cb29b2686b030f36711cef7f (diff) | |
download | gitlab-ce-34758-list-group-clusters.tar.gz |
Show clusters of ancestors in cluster list page34758-list-group-clusters
Show both the cluster(s) of the clusterable, and the cluster(s) of
ancestor groups.
-rw-r--r-- | app/controllers/clusters/clusters_controller.rb | 4 | ||||
-rw-r--r-- | app/finders/cluster_ancestors_finder.rb | 31 | ||||
-rw-r--r-- | spec/finders/cluster_ancestors_finder_spec.rb | 8 |
3 files changed, 41 insertions, 2 deletions
diff --git a/app/controllers/clusters/clusters_controller.rb b/app/controllers/clusters/clusters_controller.rb index 2e9c77ae55c..a6d40062c46 100644 --- a/app/controllers/clusters/clusters_controller.rb +++ b/app/controllers/clusters/clusters_controller.rb @@ -18,8 +18,8 @@ class Clusters::ClustersController < Clusters::BaseController STATUS_POLLING_INTERVAL = 10_000 def index - clusters = ClustersFinder.new(clusterable, current_user, :all).execute - @clusters = clusters.page(params[:page]).per(20) + clusters = ClusterAncestorsFinder.new(clusterable.subject, current_user).execute + @clusters = Kaminari.paginate_array(clusters).page(params[:page]).per(20) end def new diff --git a/app/finders/cluster_ancestors_finder.rb b/app/finders/cluster_ancestors_finder.rb new file mode 100644 index 00000000000..0d23599459f --- /dev/null +++ b/app/finders/cluster_ancestors_finder.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class ClusterAncestorsFinder + def initialize(clusterable, user) + @clusterable = clusterable + @user = user + end + + def execute + clusterable.clusters + ancestor_clusters + end + + private + + attr_reader :clusterable, :user + + def ancestor_clusters + Gitlab::GroupHierarchy.new(base_query).base_and_ancestors.flat_map do |group| + group.clusters + end + end + + def base_query + case clusterable + when Project + Group.joins(:projects).where(projects: { id: clusterable.id }) + when Group + Group.where(id: clusterable.parent_id) + end + end +end diff --git a/spec/finders/cluster_ancestors_finder_spec.rb b/spec/finders/cluster_ancestors_finder_spec.rb new file mode 100644 index 00000000000..d421fe23c27 --- /dev/null +++ b/spec/finders/cluster_ancestors_finder_spec.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ClusterAncestorsFinder do + let(:group) { create(:group) } + let(:project) { create(:project, group: group) } +end |