diff options
author | Thong Kuah <tkuah@gitlab.com> | 2018-11-07 01:13:33 +1300 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2018-12-03 15:49:20 +1300 |
commit | ebbe23892cbfde6958b92ed39a20e1fc8abfabb2 (patch) | |
tree | 6b029abd75084ba7ddae2796de0eead883c14162 | |
parent | 5f5f5251e9c62b28e622e799c2248e7fac999e91 (diff) | |
download | gitlab-ce-34758-list-ancestor-clusters.tar.gz |
Show clusters of ancestors in cluster list page34758-list-ancestor-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 | 20 | ||||
-rw-r--r-- | changelogs/unreleased/34758-list-ancestor-clusters.yml | 5 | ||||
-rw-r--r-- | spec/finders/cluster_ancestors_finder_spec.rb | 61 |
4 files changed, 88 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..9f85e6e5c31 --- /dev/null +++ b/app/finders/cluster_ancestors_finder.rb @@ -0,0 +1,20 @@ +# 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 + Clusters::Cluster.ancestor_clusters_for_clusterable(clusterable) + end +end diff --git a/changelogs/unreleased/34758-list-ancestor-clusters.yml b/changelogs/unreleased/34758-list-ancestor-clusters.yml new file mode 100644 index 00000000000..8fdba7ba90a --- /dev/null +++ b/changelogs/unreleased/34758-list-ancestor-clusters.yml @@ -0,0 +1,5 @@ +--- +title: Show clusters of ancestors in cluster list page +merge_request: 22996 +author: +type: changed diff --git a/spec/finders/cluster_ancestors_finder_spec.rb b/spec/finders/cluster_ancestors_finder_spec.rb new file mode 100644 index 00000000000..c1897ef9077 --- /dev/null +++ b/spec/finders/cluster_ancestors_finder_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ClusterAncestorsFinder, '#execute' do + let(:group) { create(:group) } + let(:project) { create(:project, group: group) } + let(:user) { create(:user) } + + let!(:project_cluster) do + create(:cluster, :provided_by_user, cluster_type: :project_type, projects: [project]) + end + + let!(:group_cluster) do + create(:cluster, :provided_by_user, cluster_type: :group_type, groups: [group]) + end + + subject { described_class.new(clusterable, user).execute } + + context 'for a project' do + let(:clusterable) { project } + + it 'returns the project clusters followed by group clusters' do + is_expected.to eq([project_cluster, group_cluster]) + end + + context 'nested groups', :nested_groups do + let(:group) { create(:group, parent: parent_group) } + let(:parent_group) { create(:group) } + + let!(:parent_group_cluster) do + create(:cluster, :provided_by_user, cluster_type: :group_type, groups: [parent_group]) + end + + it 'returns the project clusters followed by group clusters ordered ascending the hierarchy' do + is_expected.to eq([project_cluster, group_cluster, parent_group_cluster]) + end + end + end + + context 'for a group' do + let(:clusterable) { group } + + it 'returns the list of group clusters' do + is_expected.to eq([group_cluster]) + end + + context 'nested groups', :nested_groups do + let(:group) { create(:group, parent: parent_group) } + let(:parent_group) { create(:group) } + + let!(:parent_group_cluster) do + create(:cluster, :provided_by_user, cluster_type: :group_type, groups: [parent_group]) + end + + it 'returns the list of group clusters ordered ascending the hierarchy' do + is_expected.to eq([group_cluster, parent_group_cluster]) + end + end + end +end |