diff --git a/app/services/feature_flag.rb b/app/services/feature_flag.rb
index 2a1681916..9cd8bdaa6 100644
--- a/app/services/feature_flag.rb
+++ b/app/services/feature_flag.rb
@@ -1,6 +1,6 @@
module FeatureFlag
class << self
- delegate :disable, :enable, :enabled?, :exist?, :remove, to: Flipper
+ delegate :add, :disable, :enable, :enabled?, :exist?, :remove, to: Flipper
def accessible?(feature_flag_name, *args)
feature_flag_name.blank? || !exist?(feature_flag_name) || enabled?(feature_flag_name, *args)
diff --git a/app/views/admin/admin_portals/index.html.erb b/app/views/admin/admin_portals/index.html.erb
index 9e4da7778..6e135de45 100644
--- a/app/views/admin/admin_portals/index.html.erb
+++ b/app/views/admin/admin_portals/index.html.erb
@@ -22,19 +22,21 @@
<% end %>
-
-
-
Tech Resources
- <% AdminHelper::TECH_MENU_ITEMS.each do |tech_menu_item| %>
-
- <% end %>
+ <% if FeatureFlag.enabled?(:data_update_scripts) %>
+
+
+
Tech Resources
+ <% AdminHelper::TECH_MENU_ITEMS.each do |tech_menu_item| %>
+
+ <% end %>
+
-
+ <% end %>
diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb
index 60c75b6fb..663ccd1a6 100644
--- a/app/views/layouts/admin.html.erb
+++ b/app/views/layouts/admin.html.erb
@@ -59,8 +59,10 @@
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index f0b9858d3..80aaface0 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -63,9 +63,12 @@ Rails.application.routes.draw do
destroy], path: "listings/categories"
resources :comments, only: [:index]
- resources :data_update_scripts, only: %i[index show] do
- member do
- post :force_run
+ # We do not expose the Data Update Scripts to all Forems by default.
+ constraints(->(_request) { FeatureFlag.enabled?(:data_update_scripts) }) do
+ resources :data_update_scripts, only: %i[index show] do
+ member do
+ post :force_run
+ end
end
end
resources :events, only: %i[index create update new edit]
diff --git a/lib/data_update_scripts/20210210124346_add_data_updates_scripts_feature_flag.rb b/lib/data_update_scripts/20210210124346_add_data_updates_scripts_feature_flag.rb
new file mode 100644
index 000000000..1095ff904
--- /dev/null
+++ b/lib/data_update_scripts/20210210124346_add_data_updates_scripts_feature_flag.rb
@@ -0,0 +1,7 @@
+module DataUpdateScripts
+ class AddDataUpdatesScriptsFeatureFlag
+ def run
+ FeatureFlag.add(:data_update_scripts)
+ end
+ end
+end
diff --git a/spec/lib/data_update_scripts/add_data_updates_scripts_feature_flag_spec.rb b/spec/lib/data_update_scripts/add_data_updates_scripts_feature_flag_spec.rb
new file mode 100644
index 000000000..875546288
--- /dev/null
+++ b/spec/lib/data_update_scripts/add_data_updates_scripts_feature_flag_spec.rb
@@ -0,0 +1,24 @@
+require "rails_helper"
+require Rails.root.join(
+ "lib/data_update_scripts/20210210124346_add_data_updates_scripts_feature_flag.rb",
+)
+
+describe DataUpdateScripts::AddDataUpdatesScriptsFeatureFlag do
+ after do
+ FeatureFlag.remove(:data_update_scripts)
+ end
+
+ it "adds the :data_update_scripts flag", :aggregate_failures do
+ expect do
+ described_class.new.run
+ end.to change { FeatureFlag.exist?(:data_update_scripts) }.from(false).to(true)
+ end
+
+ it "works if the flag is already available" do
+ FeatureFlag.add(:data_update_scripts)
+
+ expect do
+ described_class.new.run
+ end.not_to change { FeatureFlag.exist?(:data_update_scripts) }
+ end
+end
diff --git a/spec/requests/admin/admin_portals_spec.rb b/spec/requests/admin/admin_portals_spec.rb
index a8dac87e6..d8c5a233f 100644
--- a/spec/requests/admin/admin_portals_spec.rb
+++ b/spec/requests/admin/admin_portals_spec.rb
@@ -3,7 +3,10 @@ require "rails_helper"
RSpec.describe "/admin", type: :request do
let(:super_admin) { create(:user, :super_admin) }
- before { sign_in super_admin }
+ before do
+ sign_in super_admin
+ allow(FeatureFlag).to receive(:enabled?).and_call_original
+ end
describe "profile admin feature flag" do
it "shows the option when the feature flag is enabled" do
@@ -40,4 +43,25 @@ RSpec.describe "/admin", type: :request do
expect(response.body).to include(ENV["HEROKU_RELEASE_CREATED_AT"])
end
end
+
+ describe "data update scripts admin feature flag" do
+ it "shows the option when the feature flag is enabled" do
+ allow(FeatureFlag).to receive(:enabled?).with(:data_update_scripts).and_return(true)
+
+ get admin_path
+
+ expect(response.body).to include("Tech Resources")
+ expect(response.body).to include("Data Update Scripts")
+ end
+
+ it "does not show the option when the feature flag is disabled" do
+ allow(FeatureFlag).to receive(:enabled?).with(:data_update_scripts).and_return(false)
+
+ get admin_path
+
+ expect(response.body).not_to include("Tech Resources")
+ expect(response.body).not_to include("Data Update Scripts")
+ end
+ end
+
end
diff --git a/spec/requests/admin/data_update_scripts_spec.rb b/spec/requests/admin/data_update_scripts_spec.rb
index 61047c865..a670d5d4d 100644
--- a/spec/requests/admin/data_update_scripts_spec.rb
+++ b/spec/requests/admin/data_update_scripts_spec.rb
@@ -6,7 +6,11 @@ RSpec.describe "/admin/data_update_scripts", type: :request do
context "when the user is not an tech admin" do
let(:user) { create(:user) }
- before { sign_in user }
+ before do
+ sign_in user
+ allow(Flipper).to receive(:enabled?).and_call_original
+ allow(Flipper).to receive(:enabled?).with(:data_update_scripts).and_return(true)
+ end
describe "GET /admin/data_update_scripts" do
it "blocks the request" do
@@ -18,7 +22,11 @@ RSpec.describe "/admin/data_update_scripts", type: :request do
context "when the user is a tech admin" do
let(:user) { create(:user, :admin, :tech_admin) }
- before { sign_in user }
+ before do
+ sign_in user
+ allow(Flipper).to receive(:enabled?).and_call_original
+ allow(Flipper).to receive(:enabled?).with(:data_update_scripts).and_return(true)
+ end
describe "GET /admin/data_update_scripts" do
it "allows the request" do
diff --git a/spec/requests/admin/profile_fields_spec.rb b/spec/requests/admin/profile_fields_spec.rb
index 01d70bb79..d010c11f2 100644
--- a/spec/requests/admin/profile_fields_spec.rb
+++ b/spec/requests/admin/profile_fields_spec.rb
@@ -5,6 +5,7 @@ RSpec.describe "/admin/profile_fields", type: :request do
before do
sign_in admin
+ allow(FeatureFlag).to receive(:enabled?).and_call_original
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true)
end
diff --git a/spec/requests/admin/sidebar_spec.rb b/spec/requests/admin/sidebar_spec.rb
index 27d559f2a..0cd629556 100644
--- a/spec/requests/admin/sidebar_spec.rb
+++ b/spec/requests/admin/sidebar_spec.rb
@@ -3,7 +3,10 @@ require "rails_helper"
RSpec.describe "admin sidebar", type: :request do
let(:super_admin) { create(:user, :super_admin) }
- before { sign_in super_admin }
+ before do
+ sign_in super_admin
+ allow(FeatureFlag).to receive(:enabled?).and_call_original
+ end
describe "profile admin feature flag" do
it "shows the option in the sidebar when the feature flag is enabled" do
@@ -22,4 +25,23 @@ RSpec.describe "admin sidebar", type: :request do
expect(response.body).not_to include("Config: Profile Setup")
end
end
+
+ describe "data update script admin feature flag" do
+ it "shows the option in the sidebar when the feature flag is enabled" do
+ allow(FeatureFlag).to receive(:enabled?).with(:data_update_scripts).and_return(true)
+
+ get admin_articles_path
+
+ expect(response.body).to include("Tech Resources")
+ expect(response.body).to include("Data Update Scripts")
+ end
+
+ it "does not show the option in the sidebar when the feature flag is disabled" do
+ allow(FeatureFlag).to receive(:enabled?).with(:data_update_scripts).and_return(false)
+
+ get admin_articles_path
+
+ expect(response.body).not_to include("Data Update Scripts")
+ end
+ end
end
diff --git a/spec/routing/data_update_scripts_admin_routes_spec.rb b/spec/routing/data_update_scripts_admin_routes_spec.rb
new file mode 100644
index 000000000..1512a113c
--- /dev/null
+++ b/spec/routing/data_update_scripts_admin_routes_spec.rb
@@ -0,0 +1,23 @@
+require "rails_helper"
+
+RSpec.describe "Data Update Scripts admin routes", type: :routing do
+ it "renders the data update scripts admin route if the feature flag is enabled" do
+ allow(FeatureFlag).to receive(:enabled?).with(:data_update_scripts).and_return(true)
+
+ expect(get: admin_data_update_scripts_path).to route_to(
+ controller: "admin/data_update_scripts",
+ action: "index",
+ locale: nil,
+ )
+ end
+
+ it "does not render the data update scripts admin route if the feature flag is disabled" do
+ allow(FeatureFlag).to receive(:enabled?).with(:data_update_scripts).and_return(false)
+
+ expect(get: admin_data_update_scripts_path).not_to route_to(
+ controller: "admin/data_update_scripts",
+ action: "index",
+ locale: nil,
+ )
+ end
+end
diff --git a/spec/system/admin/admin_manages_profile_fields_spec.rb b/spec/system/admin/admin_manages_profile_fields_spec.rb
index ca30cf21c..986e51007 100644
--- a/spec/system/admin/admin_manages_profile_fields_spec.rb
+++ b/spec/system/admin/admin_manages_profile_fields_spec.rb
@@ -8,6 +8,7 @@ RSpec.describe "Admin manages profile fields", type: :system do
before do
create(:profile_field, profile_field_group: profile_field_group, label: label)
Profile.refresh_attributes!
+ allow(FeatureFlag).to receive(:enabled?).and_call_original
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true)
sign_in admin