Skip to content

Commit

Permalink
2113: Redirect to root if staff portal is disabled (#383)
Browse files Browse the repository at this point in the history
* Redirect if portal is disabled

* Default staff protal to true

* Add test

* Revert schema

* Disable and move copy to dictionary

* Move to base controller

* Update tests to reflect disabled portal

* Enable portals for their respective test suites

* Avoid should

* Update app/spec/controllers/caseworker/entries_controller_spec.rb

Co-authored-by: Tom Dooner <[email protected]>

* Better assertion

---------

Co-authored-by: Tom Dooner <[email protected]>
  • Loading branch information
allthesignals and tdooner authored Dec 17, 2024
1 parent ca2bd9a commit 87e9343
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 4 deletions.
10 changes: 10 additions & 0 deletions app/app/controllers/caseworker/base_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Caseworker::BaseController < ApplicationController
before_action :redirect_if_disabled

def authenticate_user!
super

Expand All @@ -8,4 +10,12 @@ def authenticate_user!
}
end
end

def redirect_if_disabled
unless current_site.staff_portal_enabled
redirect_to root_url, flash: {
slim_alert: { message: I18n.t("caseworker.entries.disabled"), type: "error" }
}
end
end
end
1 change: 1 addition & 0 deletions app/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ en:
reminder_3: For security reasons, you'll be logged out after 30 minutes of inactivity.
reminder_4: If you encounter any issues with the tool, please use the Report feedback or bugs link.
entries:
disabled: Staff portal disabled
index:
continue_to_login:
ma: Continue to DTA log in page
Expand Down
3 changes: 3 additions & 0 deletions app/config/site-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
transmission_method: shared_email
transmission_method_configuration:
email: <%= ENV['NYC_HRA_EMAIL'] %>
staff_portal_enabled: true
sso:
client_id: <%= ENV["AZURE_NYC_DSS_CLIENT_ID"] %>
client_secret: <%= ENV["AZURE_NYC_DSS_CLIENT_SECRET"] %>
Expand All @@ -31,6 +32,7 @@
transmission_method_configuration:
bucket: <%= ENV['MA_DTA_S3_BUCKET'] %>
public_key: <%= ENV['MA_DTA_S3_PUBLIC_KEY'].inspect %>
staff_portal_enabled: false
sso:
client_id: <%= ENV["AZURE_MA_DTA_CLIENT_ID"] %>
client_secret: <%= ENV["AZURE_MA_DTA_CLIENT_SECRET"] %>
Expand All @@ -54,6 +56,7 @@
transmission_method: shared_email
transmission_method_configuration:
email: <%= ENV['SLACK_TEST_EMAIL'] %>
staff_portal_enabled: true
sso:
client_id: <%= ENV["AZURE_SANDBOX_CLIENT_ID"] %>
client_secret: <%= ENV["AZURE_SANDBOX_CLIENT_SECRET"] %>
Expand Down
2 changes: 2 additions & 0 deletions app/lib/site_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Site
pay_income_days
pinwheel_api_token
pinwheel_environment
staff_portal_enabled
sso
transmission_method
transmission_method_configuration
Expand All @@ -51,6 +52,7 @@ def initialize(yaml)
@pinwheel_environment = yaml["pinwheel"]["environment"] || "sandbox"
@transmission_method = yaml["transmission_method"]
@transmission_method_configuration = yaml["transmission_method_configuration"]
@staff_portal_enabled = yaml["staff_portal_enabled"]
@sso = yaml["sso"]
@weekly_report = yaml["weekly_report"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
let(:site_id) { "ma" }

before do
stub_site_config_value("ma", "staff_portal_enabled", true)
sign_in ma_user
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
let(:ma_params) { { site_id: "ma" } }

before do
stub_site_config_value("ma", "staff_portal_enabled", true)
sign_in user
end

Expand Down
17 changes: 13 additions & 4 deletions app/spec/controllers/caseworker/entries_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
it "should show ma specific copy with a link to /sso/ma" do
agency_short_name = site_config["ma"].agency_short_name
get :index, params: { site_id: "ma" }
expect(response).to be_successful
unescaped_body = CGI.unescapeHTML(response.body)
expect(unescaped_body).to include(I18n.t("caseworker.entries.index.header.ma", agency_short_name: agency_short_name))
expect(unescaped_body).to include("Continue to #{agency_short_name} log in page")
expect(response).to redirect_to(root_url)
end
end

Expand All @@ -27,5 +24,17 @@
expect(unescaped_body).to include("Log in with your LAN ID")
end
end

context "when state is disabled" do
before do
stub_site_config_value("sandbox", "staff_portal_enabled", false)
end

it "redirect to the root page" do
agency_short_name = site_config["sandbox"].agency_short_name
get :index, params: { site_id: "sandbox" }
expect(response).to redirect_to(root_url)
end
end
end
end
5 changes: 5 additions & 0 deletions app/spec/support/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,9 @@ def stub_identities(account_id = SecureRandom.uuid)
}
end
end

def stub_site_config_value(site, key, value)
site_config = Rails.application.config.sites[site]
allow(site_config).to receive(key.to_sym).and_return(value)
end
end

0 comments on commit 87e9343

Please sign in to comment.