diff --git a/.env.example b/.env.example
index 5d7963ff..7fa6a1b0 100644
--- a/.env.example
+++ b/.env.example
@@ -80,6 +80,9 @@ unthrottled_ips=
# Analytics
MATOMO_SITE_ID=
+# Feature flags
+STATE_ACTIONS_ENABLED=true
+
#
# End of application environment variables
#
diff --git a/app/controllers/tools_controller.rb b/app/controllers/tools_controller.rb
index 5266f6e5..556dabd1 100644
--- a/app/controllers/tools_controller.rb
+++ b/app/controllers/tools_controller.rb
@@ -127,6 +127,8 @@ def email
# This endpoint is hit by the js for state legislator lookup-by-address actions.
# It renders json containing html markup for presentation on the view
def state_reps
+ raise ActionController::RoutingError.new("Not Found") unless Rails.application.config.state_actions_enabled
+
@email_campaign = EmailCampaign.find(params[:email_campaign_id])
@actionPage = @email_campaign.action_page
# TODO: strong params this
diff --git a/app/views/admin/action_pages/_email_fields.html.erb b/app/views/admin/action_pages/_email_fields.html.erb
index 0a0c98ab..bfaf759e 100644
--- a/app/views/admin/action_pages/_email_fields.html.erb
+++ b/app/views/admin/action_pages/_email_fields.html.erb
@@ -1,4 +1,15 @@
<%= f.fields_for(:email_campaign) do |sf| %>
+ <% if Rails.application.config.state_actions_enabled %>
+ <%= render partial: "state_level_fields", locals: { sf: sf } %>
+ <% else %>
+
+ <%= sf.label :email_addresses do %>
+ Target email(s)
+ (Separate multiple addresses with commas, e.g. "dax@eff.org,kira@eff.org")
+ <% end %>
+ <%= sf.text_field :email_addresses %>
+
+ <% end %>
<%= sf.label :subject %>
@@ -9,36 +20,4 @@
<%= sf.label :message %>
<%= sf.text_area :message %>
-
-
-
<% end %>
diff --git a/app/views/admin/action_pages/_state_level_fields.html.erb b/app/views/admin/action_pages/_state_level_fields.html.erb
new file mode 100644
index 00000000..000ac169
--- /dev/null
+++ b/app/views/admin/action_pages/_state_level_fields.html.erb
@@ -0,0 +1,30 @@
+
diff --git a/app/views/tools/_container.html.erb b/app/views/tools/_container.html.erb
index cd027b00..1a5e5d9f 100644
--- a/app/views/tools/_container.html.erb
+++ b/app/views/tools/_container.html.erb
@@ -7,7 +7,7 @@
<%= render "tools/petition" if @actionPage.enable_petition? && @actionPage.petition %>
<%= render "tools/call" if @actionPage.enable_call? && @actionPage.call_campaign %>
<% if @actionPage.enable_email? && @actionPage.email_campaign %>
- <% if @actionPage.email_campaign.state? %>
+ <% if Rails.application.config.state_actions_enabled && @actionPage.email_campaign.state? %>
<%= render "tools/state_leg_email" %>
<% else %>
<%= render "tools/email" %>
diff --git a/config/application.rb b/config/application.rb
index d95c7f6e..42965d15 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -45,6 +45,6 @@ class Application < Rails::Application
config.congress_forms_url = Rails.application.secrets.congress_forms_url
config.google_civic_api_url = Rails.application.secrets.google_civic_api_url
config.time_zone = Rails.application.secrets.time_zone || "Eastern Time (US & Canada)"
-
+ config.state_actions_enabled = Rails.application.secrets.state_actions_enabled
end
end
diff --git a/spec/requests/tools_spec.rb b/spec/requests/tools_spec.rb
index eeedfae6..60f1fa90 100644
--- a/spec/requests/tools_spec.rb
+++ b/spec/requests/tools_spec.rb
@@ -21,17 +21,23 @@
let!(:headers) { { "CONTENT_TYPE" => "application/javascript" } }
describe "POST tools/state_reps" do
- it "returns json containing rep data for a given address" do
- civic_api = class_double("CivicApi")
- .as_stubbed_const(transfer_nested_constants: true)
- allow(civic_api).to receive(:state_rep_search)
- .with(address, campaign.leg_level)
- .and_return(officials)
+ context "when state actions enabled" do
+ before do
+ allow(Rails.application.config).to receive(:state_actions_enabled) { "true" }
+ end
- post "/tools/state_reps", params: params, xhr: true
+ it "returns json containing rep data for a given address" do
+ civic_api = class_double("CivicApi")
+ .as_stubbed_const(transfer_nested_constants: true)
+ allow(civic_api).to receive(:state_rep_search)
+ .with(address, campaign.leg_level)
+ .and_return(officials)
- expect(response).to have_http_status(200)
- expect(response.body).to include(officials.first["name"])
+ post "/tools/state_reps", params: params, xhr: true
+
+ expect(response).to have_http_status(200)
+ expect(response.body).to include(officials.first["name"])
+ end
end
end
end
diff --git a/spec/support/javascript_helpers.rb b/spec/support/javascript_helpers.rb
index 611d3946..d10d6e06 100644
--- a/spec/support/javascript_helpers.rb
+++ b/spec/support/javascript_helpers.rb
@@ -12,6 +12,9 @@ def fill_in_editor(locator, with:)
end
end
+ # TODO: fix? this did not work for action filters, but those also live in
+ # a sidebar and this isn't breaking elsewhere
+ # but this does not fill in every select2 correctly
def fill_in_select2(locator, with:)
find(locator).sibling(".select2-container").click
find("li.select2-results__option[role=option]", text: with).click
diff --git a/spec/system/action_pages/state_leg_email_action_spec.rb b/spec/system/action_pages/state_leg_email_action_spec.rb
index 622522b2..562df889 100644
--- a/spec/system/action_pages/state_leg_email_action_spec.rb
+++ b/spec/system/action_pages/state_leg_email_action_spec.rb
@@ -17,6 +17,8 @@
before do
stub_request(:get, "https://civic.example.com/?address=815%20Eddy%20St%2094109&includeOffices=true&key=test-key-for-civic-api&levels=administrativeArea1&roles=legislatorUpperBody")
.to_return(status: 200, body: data.to_json, headers: {})
+
+ allow(Rails.application.config).to receive(:state_actions_enabled) { "true" }
end
it "allows vistors to see look up their representatives" do
diff --git a/spec/system/admin/action_creation_spec.rb b/spec/system/admin/action_creation_spec.rb
index 9d789cab..f3640a97 100644
--- a/spec/system/admin/action_creation_spec.rb
+++ b/spec/system/admin/action_creation_spec.rb
@@ -51,7 +51,7 @@
select_action_type("email")
fill_in "Subject", with: "Subject"
fill_in "Message", with: "An email"
- fill_in "Or enter custom email addresses below:", with: "test@gmail.com"
+ fill_in "Target email(s)", with: "test@gmail.com"
next_section
skip_banner_selection
@@ -61,27 +61,46 @@
expect(page).to have_content("Very Important Action", wait: 10)
end
- it "can create state-level email actions" do
- visit new_admin_action_page_path
- fill_in_basic_info(title: "State-Level Leg Action",
- summary: "A summary",
- description: "A description")
- click_on "Next"
+ context "when state-level email actions enabled" do
+ it "can create state-level email actions" do
+ allow(Rails.application.config).to receive(:state_actions_enabled) { "true" }
- select_action_type("email")
- fill_in "Subject", with: "Subject"
- fill_in "Message", with: "An email"
+ visit new_admin_action_page_path
+ fill_in_basic_info(title: "State-Level Leg Action",
+ summary: "A summary",
+ description: "A description")
+ click_on "Next"
- select("CA", from: "action_page_email_campaign_attributes_state")
- find("#action_page_email_campaign_attributes_target_state_upper_chamber").ancestor("label").click
+ select_action_type("email")
+ fill_in "Subject", with: "Subject"
+ fill_in "Message", with: "An email"
- click_on "Next"
+ expect(page).to have_content("Select State-Level Legislators")
+ select("CA", from: "action_page_email_campaign_attributes_state")
+ find("#action_page_email_campaign_attributes_target_state_upper_chamber").ancestor("label").click
- skip_banner_selection
- fill_in_social_media
+ click_on "Next"
- click_button "Save"
- expect(page).to have_content("State-Level Leg Action", wait: 10)
+ skip_banner_selection
+ fill_in_social_media
+
+ click_button "Save"
+ expect(page).to have_content("State-Level Leg Action", wait: 10)
+ end
+ end
+
+ context "when state-levle email actions are not enabled" do
+ it "does not show the option to create a state-level campaign" do
+ visit new_admin_action_page_path
+ fill_in_basic_info(title: "State-Level Leg Action",
+ summary: "A summary",
+ description: "A description")
+ click_on "Next"
+
+ select_action_type("email")
+
+ expect(page).to_not have_content("Select State-Level Legislators")
+ end
end
it "can create congress actions" do
diff --git a/spec/system/admin/action_index_spec.rb b/spec/system/admin/action_index_spec.rb
index ba4accf9..132ac32a 100644
--- a/spec/system/admin/action_index_spec.rb
+++ b/spec/system/admin/action_index_spec.rb
@@ -8,7 +8,8 @@
email_action = FactoryBot.create(:action_page, enable_email: true)
visit admin_action_pages_path
- fill_in_select2("#action_filters_type", with: "email")
+ find("#action_filters_type").sibling(".select2-container").click
+ find("ul#select2-action_filters_type-results li", text: "email").click
click_on "Search"
expect(page).to have_content(email_action.title)