Skip to content

Commit e897c22

Browse files
committed
Hide state action behind feature flag
The Civic API is going to be shut down in a week or two. We need to remove the corresponding code and decide on if/how to move forward with a new service that provides representative info. In meantime this turns off the state level actions from the user interface (public and admin) and returns a 404 from the corresponding endpoint in the tools controller when STATE_ACTIONS_ENABLED is unset. In the future, we can swap out the backend logic and reenable by setting the env var to true.
1 parent af68b36 commit e897c22

File tree

7 files changed

+47
-32
lines changed

7 files changed

+47
-32
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ unthrottled_ips=
8080
# Analytics
8181
MATOMO_SITE_ID=
8282

83+
# Feature flags
84+
STATE_ACTIONS_ENABLED=true
85+
8386
#
8487
# End of application environment variables
8588
#

app/controllers/tools_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ def email
127127
# This endpoint is hit by the js for state legislator lookup-by-address actions.
128128
# It renders json containing html markup for presentation on the view
129129
def state_reps
130+
raise ActionController::RoutingError.new("Not Found") unless Rails.application.config.state_actions_enabled
131+
130132
@email_campaign = EmailCampaign.find(params[:email_campaign_id])
131133
@actionPage = @email_campaign.action_page
132134
# TODO: strong params this

app/views/admin/action_pages/_email_fields.html.erb

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,32 @@
1010
<%= sf.text_area :message %>
1111
</div>
1212

13-
<fieldset class="form-item">
14-
<legend>Select State-Level Legislators</legend>
13+
<% if Rails.application.config.state_actions_enabled %>
14+
<fieldset class="form-item">
15+
<legend>Select State-Level Legislators</legend>
1516

16-
<%= sf.label :state, class: "fancy" do %>
17-
<%= sf.select :state, options_for_select(EmailCampaign::STATES, @actionPage.email_campaign.state), include_blank: "- none -" %><span class="ui"></span>
18-
<% end %>
19-
20-
<div id="state-level-target-selection">
21-
<p>For now, please choose only one.</p>
22-
<%= sf.label :target_state_lower_chamber do %>
23-
<%= sf.check_box :target_state_lower_chamber, class: "fancy" %><span class="ui"></span>
24-
Lower Chamber
25-
<% end %>
26-
27-
<%= sf.label :target_state_upper_chamber do %>
28-
<%= sf.check_box :target_state_upper_chamber, class: "fancy" %><span class="ui"></span>
29-
Upper Chamber
17+
<%= sf.label :state, class: "fancy" do %>
18+
<%= sf.select :state, options_for_select(EmailCampaign::STATES, @actionPage.email_campaign.state), include_blank: "- none -" %><span class="ui"></span>
3019
<% end %>
3120

32-
<%= sf.label :target_governor do %>
33-
<%= sf.check_box :target_governor, class: "fancy" %><span class="ui"></span>
34-
Governor
35-
<% end %>
36-
</div>
21+
<div id="state-level-target-selection">
22+
<p>For now, please choose only one.</p>
23+
<%= sf.label :target_state_lower_chamber do %>
24+
<%= sf.check_box :target_state_lower_chamber, class: "fancy" %><span class="ui"></span>
25+
Lower Chamber
26+
<% end %>
27+
28+
<%= sf.label :target_state_upper_chamber do %>
29+
<%= sf.check_box :target_state_upper_chamber, class: "fancy" %><span class="ui"></span>
30+
Upper Chamber
31+
<% end %>
32+
33+
<%= sf.label :target_governor do %>
34+
<%= sf.check_box :target_governor, class: "fancy" %><span class="ui"></span>
35+
Governor
36+
<% end %>
37+
</div>
38+
<% end %>
3739

3840
<br></br>
3941

app/views/tools/_container.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<%= render "tools/petition" if @actionPage.enable_petition? && @actionPage.petition %>
88
<%= render "tools/call" if @actionPage.enable_call? && @actionPage.call_campaign %>
99
<% if @actionPage.enable_email? && @actionPage.email_campaign %>
10-
<% if @actionPage.email_campaign.state? %>
10+
<% if Rails.application.config.state_actions_enabled && @actionPage.email_campaign.state? %>
1111
<%= render "tools/state_leg_email" %>
1212
<% else %>
1313
<%= render "tools/email" %>

config/application.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ class Application < Rails::Application
4545
config.congress_forms_url = Rails.application.secrets.congress_forms_url
4646
config.google_civic_api_url = Rails.application.secrets.google_civic_api_url
4747
config.time_zone = Rails.application.secrets.time_zone || "Eastern Time (US & Canada)"
48-
48+
config.state_actions_enabled = Rails.application.secrets.state_actions_enabled
4949
end
5050
end

spec/requests/tools_spec.rb

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,23 @@
2121
let!(:headers) { { "CONTENT_TYPE" => "application/javascript" } }
2222

2323
describe "POST tools/state_reps" do
24-
it "returns json containing rep data for a given address" do
25-
civic_api = class_double("CivicApi")
26-
.as_stubbed_const(transfer_nested_constants: true)
27-
allow(civic_api).to receive(:state_rep_search)
28-
.with(address, campaign.leg_level)
29-
.and_return(officials)
24+
context "when state actions enabled" do
25+
before do
26+
allow(Rails.application.config).to receive(:state_actions_enabled) { "true" }
27+
end
3028

31-
post "/tools/state_reps", params: params, xhr: true
29+
it "returns json containing rep data for a given address" do
30+
civic_api = class_double("CivicApi")
31+
.as_stubbed_const(transfer_nested_constants: true)
32+
allow(civic_api).to receive(:state_rep_search)
33+
.with(address, campaign.leg_level)
34+
.and_return(officials)
3235

33-
expect(response).to have_http_status(200)
34-
expect(response.body).to include(officials.first["name"])
36+
post "/tools/state_reps", params: params, xhr: true
37+
38+
expect(response).to have_http_status(200)
39+
expect(response.body).to include(officials.first["name"])
40+
end
3541
end
3642
end
3743
end

spec/system/action_pages/state_leg_email_action_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
before do
1818
stub_request(:get, "https://civic.example.com/?address=815%20Eddy%20St%2094109&includeOffices=true&key=test-key-for-civic-api&levels=administrativeArea1&roles=legislatorUpperBody")
1919
.to_return(status: 200, body: data.to_json, headers: {})
20+
21+
allow(Rails.application.config).to receive(:state_actions_enabled) { "true" }
2022
end
2123

2224
it "allows vistors to see look up their representatives" do

0 commit comments

Comments
 (0)