Commit 494cb30f authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'environments-dashboard-backend-ff' into 'master'

Add Feature Flag for Environments Dashboard Backend

See merge request gitlab-org/gitlab!18357
parents bf9732ce 4db8cec3
......@@ -2,8 +2,7 @@
class OperationsController < ApplicationController
before_action :authorize_read_operations_dashboard!
before_action :dashboard_feature_flag, only: [:environments]
before_action :environments_dashboard_feature_flag, only: %i[environments environments_list]
respond_to :json, only: [:list]
......@@ -15,10 +14,6 @@ class OperationsController < ApplicationController
def environments
end
def dashboard_feature_flag
push_frontend_feature_flag(:environments_dashboard)
end
def list
Gitlab::PollingInterval.set_header(response, interval: POLLING_INTERVAL)
projects = load_projects(current_user)
......@@ -61,6 +56,10 @@ class OperationsController < ApplicationController
render_404 unless can?(current_user, :read_operations_dashboard)
end
def environments_dashboard_feature_flag
render_404 unless Feature.enabled?(:environments_dashboard, current_user)
end
def load_projects(current_user)
Dashboard::Operations::ListService.new(current_user).execute
end
......
......@@ -39,7 +39,7 @@ module EE
links << :analytics if ::Gitlab::Analytics.any_features_enabled?
if can?(current_user, :read_operations_dashboard)
links << :environments if ::Feature.enabled?(:environments_dashboard)
links << :environments if ::Feature.enabled?(:environments_dashboard, current_user)
links << :operations
end
......
......@@ -34,6 +34,15 @@ describe OperationsController do
expect(response).to render_template(:index)
end
it 'renders regardless of the environments_dashboard feature flag' do
stub_feature_flags(environments_dashboard: { enabled: false, thing: user })
get :index
expect(response).to have_gitlab_http_status(200)
expect(response).to render_template(:index)
end
context 'with an anonymous user' do
before do
sign_out(user)
......@@ -57,6 +66,24 @@ describe OperationsController do
expect(response).to render_template(:environments)
end
it 'returns a 404 when the feature is disabled' do
stub_feature_flags(environments_dashboard: { enabled: false, thing: user })
get :environments
expect(response).to have_gitlab_http_status(:not_found)
end
it 'renders the view when the feature is disabled for a different user' do
other_user = create(:user)
stub_feature_flags(environments_dashboard: { enabled: false, thing: other_user })
get :environments
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:environments)
end
context 'with an anonymous user' do
before do
sign_out(user)
......@@ -138,6 +165,17 @@ describe OperationsController do
expect(expected_project['last_alert']['id']).to eq(last_firing_alert.id)
end
it 'returns a list of added projects regardless of the environments_dashboard feature flag' do
stub_feature_flags(environments_dashboard: { enabled: false, thing: user })
get :list
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('dashboard/operations/list', dir: 'ee')
expect(json_response['projects'].size).to eq(1)
expect(expected_project['id']).to eq(project.id)
end
context 'without sufficient access level' do
before do
project.add_reporter(user)
......@@ -226,6 +264,30 @@ describe OperationsController do
user.update!(ops_dashboard_projects: [project])
end
it 'returns a 404 when the feature is disabled' do
stub_feature_flags(environments_dashboard: { enabled: false, thing: user })
environment = create(:environment, project: project)
ci_build = create(:ci_build, project: project)
create(:deployment, :success, project: project, environment: environment, deployable: ci_build)
get :environments_list
expect(response).to have_gitlab_http_status(:not_found)
end
it 'returns a project when the feature is disabled for another user' do
other_user = create(:user)
stub_feature_flags(environments_dashboard: { enabled: false, thing: other_user })
environment = create(:environment, project: project)
ci_build = create(:ci_build, project: project)
create(:deployment, :success, project: project, environment: environment, deployable: ci_build)
get :environments_list
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('dashboard/operations/environments_list', dir: 'ee')
end
it 'returns a project without an environment' do
get :environments_list
......@@ -452,6 +514,16 @@ describe OperationsController do
expect(user.ops_dashboard_projects).to contain_exactly(project_a, project_b)
end
it 'adds projects to the dashboard regardless of the environments_dashboard feature flag' do
stub_feature_flags(environments_dashboard: { enabled: false, thing: user })
post :create, params: { project_ids: [project_a.id, project_b.id.to_s] }
expect(response).to have_gitlab_http_status(200)
expect(json_response).to match_schema('dashboard/operations/add', dir: 'ee')
expect(json_response['added']).to contain_exactly(project_a.id, project_b.id)
end
it 'cannot add a project twice' do
post :create, params: { project_ids: [project_a.id, project_a.id] }
......@@ -530,7 +602,17 @@ describe OperationsController do
expect(response).to have_gitlab_http_status(200)
user.reload
expect(user.ops_dashboard_projects).not_to eq([project])
expect(user.ops_dashboard_projects).to eq([])
end
it 'removes a project regardless of the environments_dashboard feature flag' do
stub_feature_flags(environments_dashboard: { enabled: false, thing: user })
delete :destroy, params: { project_id: project.id }
expect(response).to have_gitlab_http_status(200)
user.reload
expect(user.ops_dashboard_projects).to eq([])
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