From 69a5bbcb0d209c6bbe9853ab5c1f31ceeb525ec6 Mon Sep 17 00:00:00 2001 From: Daniyal Arshad Date: Mon, 7 Apr 2025 22:57:00 -0400 Subject: [PATCH] Remove workspaces feature flag controller --- .../gitlab/feature_flag_key_dynamic.yml | 1 - .../workspaces_feature_flag_controller.rb | 38 ------- ee/config/routes/remote_development.rb | 1 - ...workspaces_feature_flag_controller_spec.rb | 99 ------------------- 4 files changed, 139 deletions(-) delete mode 100644 ee/app/controllers/remote_development/workspaces_feature_flag_controller.rb delete mode 100644 ee/spec/controllers/remote_development/workspaces_feature_flag_controller_spec.rb diff --git a/.rubocop_todo/gitlab/feature_flag_key_dynamic.yml b/.rubocop_todo/gitlab/feature_flag_key_dynamic.yml index 448af455330c46..46582ec62f02d0 100644 --- a/.rubocop_todo/gitlab/feature_flag_key_dynamic.yml +++ b/.rubocop_todo/gitlab/feature_flag_key_dynamic.yml @@ -12,7 +12,6 @@ Gitlab/FeatureFlagKeyDynamic: - 'app/services/service_desk_settings/update_service.rb' - 'app/workers/concerns/worker_attributes.rb' - 'app/workers/loose_foreign_keys/cleanup_worker.rb' - - 'ee/app/controllers/remote_development/workspaces_feature_flag_controller.rb' - 'ee/app/graphql/resolvers/ai/user_available_features_resolver.rb' - 'ee/app/graphql/resolvers/ai/user_code_suggestions_contexts_resolver.rb' - 'ee/app/models/concerns/geo/verifiable_replicator.rb' diff --git a/ee/app/controllers/remote_development/workspaces_feature_flag_controller.rb b/ee/app/controllers/remote_development/workspaces_feature_flag_controller.rb deleted file mode 100644 index 507bad2bf4bcc1..00000000000000 --- a/ee/app/controllers/remote_development/workspaces_feature_flag_controller.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -module RemoteDevelopment - # This controller exists because the actor for the feature flag is determined on the client side - # based on what choices a user makes on the page. As such, we cannot rely on the normal approach - # of passing the flag's state in the original body of the page, rather we would need to query - # it in realtime based on the current selected actor. In this case, it is the namespace. - # TODO: this will be cleaned up as part of gitlab-org/gitlab#482814+ - class WorkspacesFeatureFlagController < ApplicationController - feature_category :workspaces - urgency :low - - ALLOWED_FLAGS = [].freeze - - def show - flag = permitted_params[:flag] - - return render json: { enabled: false } unless ALLOWED_FLAGS.include?(flag.to_s) - - namespace_id = permitted_params[:namespace_id] - namespace = ::Namespace.find_by_id(namespace_id) - - return render json: { enabled: false } unless namespace - - begin - render json: { enabled: Feature.enabled?(flag.to_sym, namespace.root_ancestor) } - rescue Feature::InvalidFeatureFlagError - render json: { enabled: false } - end - end - - private - - def permitted_params - params.permit(:flag, :namespace_id) - end - end -end diff --git a/ee/config/routes/remote_development.rb b/ee/config/routes/remote_development.rb index 088d57cf5295a6..cc564a6a953185 100644 --- a/ee/config/routes/remote_development.rb +++ b/ee/config/routes/remote_development.rb @@ -4,5 +4,4 @@ resources :workspaces, path: 'workspaces(/*vueroute)' do resources :workspaces, only: [:index, :new], controller: :workspaces, action: :index end - get :workspaces_feature_flag, format: :json, to: "workspaces_feature_flag#show" end diff --git a/ee/spec/controllers/remote_development/workspaces_feature_flag_controller_spec.rb b/ee/spec/controllers/remote_development/workspaces_feature_flag_controller_spec.rb deleted file mode 100644 index 246a72c6231ae8..00000000000000 --- a/ee/spec/controllers/remote_development/workspaces_feature_flag_controller_spec.rb +++ /dev/null @@ -1,99 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -RSpec.describe RemoteDevelopment::WorkspacesFeatureFlagController, feature_category: :workspaces do - let_it_be(:user) { create(:user) } - let_it_be(:namespace) { create(:group, :nested) } - let(:flag) { "the_flag" } - let(:allowed_flag) { flag } - - describe "GET #show" do - before do - stub_const("#{described_class}::ALLOWED_FLAGS", [allowed_flag]) - sign_in(user) - end - - context "when namespace is not found" do - let(:non_existing_namespace_id) { -1 } - let(:namespace_id) { non_existing_namespace_id } - - it "returns enabled as false" do - get :show, params: { flag: flag, namespace_id: namespace_id } - - expect(response).to have_gitlab_http_status(:ok) - expect(json_response["enabled"]).to be false - end - end - - context "when namespace is found" do - let(:namespace_id) { namespace.id } - - before do - allow(Feature).to receive(:enabled?).and_call_original - allow(Feature).to receive(:enabled?).with(flag.to_sym, namespace.root_ancestor).and_return(enabled) - end - - context "when flag does not exist in the allow-list" do - let(:enabled) { false } - - it "returns enabled as false" do - get :show, params: { flag: "INVALID_FLAG", namespace_id: namespace_id } - - expect(response).to have_gitlab_http_status(:ok) - expect(json_response["enabled"]).to eq enabled - end - end - - context "when flag exists in the allow-list but is not a known feature flag" do - let(:enabled) { false } - - before do - allow(Feature).to receive(:enabled?) - .with(flag.to_sym, namespace.root_ancestor) - .and_raise(Feature::InvalidFeatureFlagError) - end - - it "returns enabled as false" do - get :show, params: { flag: flag, namespace_id: namespace_id } - - expect(response).to have_gitlab_http_status(:ok) - expect(json_response["enabled"]).to eq enabled - end - end - - context "when feature flag is enabled" do - let(:enabled) { true } - - it "returns enabled as true" do - get :show, params: { flag: flag, namespace_id: namespace_id } - - expect(response).to have_gitlab_http_status(:ok) - expect(json_response["enabled"]).to eq enabled - end - - context "when flag is not allowed" do - let(:allowed_flag) { "a_different_flag" } - - it "returns enabled as false" do - get :show, params: { flag: flag, namespace_id: namespace_id } - - expect(response).to have_gitlab_http_status(:ok) - expect(json_response["enabled"]).to be false - end - end - end - - context "when feature flag is disabled" do - let(:enabled) { false } - - it "returns enabled as false" do - get :show, params: { flag: flag, namespace_id: namespace_id } - - expect(response).to have_gitlab_http_status(:ok) - expect(json_response["enabled"]).to eq enabled - end - end - end - end -end -- GitLab