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 @@
class Groups::ClustersController < Clusters::ClustersController
include ControllerWithCrossProjectAccessCheck
prepend_before_action :check_group_clusters_feature_flag!
prepend_before_action :group
requires_cross_project_access
......@@ -17,4 +18,8 @@ class Groups::ClustersController < Clusters::ClustersController
def group
@group ||= find_routable!(Group, params[:group_id] || params[:id])
end
def check_group_clusters_feature_flag!
render_404 unless Feature.enabled?(:group_clusters)
end
end
......@@ -140,7 +140,7 @@ module GroupsHelper
can?(current_user, "read_group_#{resource}".to_sym, @group)
end
if can?(current_user, :read_cluster, @group)
if can?(current_user, :read_cluster, @group) && Feature.enabled?(:group_clusters)
links << :kubernetes
end
......
......@@ -20,45 +20,63 @@ describe Groups::ClustersController do
get :index, params.reverse_merge(group_id: group)
end
describe 'functionality' do
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
context 'when feature flag is not enabled' do
before do
stub_feature_flags(group_clusters: false)
end
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:index)
expect(assigns(:clusters)).to match_array([enabled_cluster, disabled_cluster])
end
it 'renders 404' do
go
context 'when page is specified' do
let(:last_page) { group.clusters.page.total_pages }
expect(response).to have_gitlab_http_status(404)
end
end
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
context 'when feature flag is enabled' do
before do
stub_feature_flags(group_clusters: true)
end
it 'redirects to the page' do
go(page: last_page)
describe 'functionality' do
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(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
context 'when group does not have a cluster' do
let(:group) { create(:group) }
context 'when group does not have a cluster' do
let(:group) { create(:group) }
it 'returns an empty state page' do
go
it 'returns an empty state page' do
go
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:index, partial: :empty_state)
expect(assigns(:clusters)).to eq([])
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:index, partial: :empty_state)
expect(assigns(:clusters)).to eq([])
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