Commit 675bfd50 authored by Mayra Cabrera's avatar Mayra Cabrera Committed by Thong Kuah

Adds feature flag for Group Clusters

As the frontend is still in progress and other related backend is still
in prgress we need a feature flag to turn off Group Clusters.
parent a90320f7
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
class Groups::ClustersController < Clusters::ClustersController class Groups::ClustersController < Clusters::ClustersController
include ControllerWithCrossProjectAccessCheck include ControllerWithCrossProjectAccessCheck
prepend_before_action :check_group_clusters_feature_flag!
prepend_before_action :group prepend_before_action :group
requires_cross_project_access requires_cross_project_access
...@@ -17,4 +18,8 @@ class Groups::ClustersController < Clusters::ClustersController ...@@ -17,4 +18,8 @@ class Groups::ClustersController < Clusters::ClustersController
def group def group
@group ||= find_routable!(Group, params[:group_id] || params[:id]) @group ||= find_routable!(Group, params[:group_id] || params[:id])
end end
def check_group_clusters_feature_flag!
render_404 unless Feature.enabled?(:group_clusters)
end
end end
...@@ -140,7 +140,7 @@ module GroupsHelper ...@@ -140,7 +140,7 @@ module GroupsHelper
can?(current_user, "read_group_#{resource}".to_sym, @group) can?(current_user, "read_group_#{resource}".to_sym, @group)
end end
if can?(current_user, :read_cluster, @group) if can?(current_user, :read_cluster, @group) && Feature.enabled?(:group_clusters)
links << :kubernetes links << :kubernetes
end end
......
...@@ -20,45 +20,63 @@ describe Groups::ClustersController do ...@@ -20,45 +20,63 @@ describe Groups::ClustersController do
get :index, params.reverse_merge(group_id: group) get :index, params.reverse_merge(group_id: group)
end end
describe 'functionality' do context 'when feature flag is not enabled' do
context 'when group has one or more clusters' do before do
let(:group) { create(:group) } stub_feature_flags(group_clusters: false)
let!(:enabled_cluster) { create(:cluster, :provided_by_gcp, cluster_type: :group_type, groups: [group]) } end
let!(:disabled_cluster) { create(:cluster, :disabled, :provided_by_gcp, :production_environment, cluster_type: :group_type, groups: [group]) }
it 'lists available clusters' do
go
expect(response).to have_gitlab_http_status(:ok) it 'renders 404' do
expect(response).to render_template(:index) go
expect(assigns(:clusters)).to match_array([enabled_cluster, disabled_cluster])
end
context 'when page is specified' do expect(response).to have_gitlab_http_status(404)
let(:last_page) { group.clusters.page.total_pages } end
end
before do context 'when feature flag is enabled' do
allow(Clusters::Cluster).to receive(:paginates_per).and_return(1) before do
create_list(:cluster, 2, :provided_by_gcp, :production_environment, cluster_type: :group_type, groups: [group]) stub_feature_flags(group_clusters: true)
end end
it 'redirects to the page' do describe 'functionality' do
go(page: last_page) context 'when group has one or more clusters' do
let(:group) { create(:group) }
let!(:enabled_cluster) { create(:cluster, :provided_by_gcp, cluster_type: :group_type, groups: [group]) }
let!(:disabled_cluster) { create(:cluster, :disabled, :provided_by_gcp, :production_environment, cluster_type: :group_type, groups: [group]) }
it 'lists available clusters' do
go
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(assigns(:clusters).current_page).to eq(last_page) expect(response).to render_template(:index)
expect(assigns(:clusters)).to match_array([enabled_cluster, disabled_cluster])
end
context 'when page is specified' do
let(:last_page) { group.clusters.page.total_pages }
before do
allow(Clusters::Cluster).to receive(:paginates_per).and_return(1)
create_list(:cluster, 2, :provided_by_gcp, :production_environment, cluster_type: :group_type, groups: [group])
end
it 'redirects to the page' do
go(page: last_page)
expect(response).to have_gitlab_http_status(:ok)
expect(assigns(:clusters).current_page).to eq(last_page)
end
end end
end end
end
context 'when group does not have a cluster' do context 'when group does not have a cluster' do
let(:group) { create(:group) } let(:group) { create(:group) }
it 'returns an empty state page' do it 'returns an empty state page' do
go go
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:index, partial: :empty_state) expect(response).to render_template(:index, partial: :empty_state)
expect(assigns(:clusters)).to eq([]) expect(assigns(:clusters)).to eq([])
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment