Browse Source

CLDC-2863: Create 'redirect to new service' page (#2022)

* CLDC-2863: rename maintenance_mode_enabled? to service_unavailable?

* CLDC-2863: update 'maintenance' to 'service unavailable' in tests

* CLDC-2863: rename check_maintenance to check_maintenance_status

* CLDC-2863: implement service_moved functionality

* CLDC-2863: add tests for service_moved functionality

* CLDC-2863: add tests for when both feature toggles are on

* CLDC-2863: remove full stop from service moved page title

* CLDC-2863: turn on service moved feature

* CLDC-2863: turn off service moved feature
pull/2025/head v0.3.77
SamSeed-Softwire 1 year ago committed by GitHub
parent
commit
96c1c276ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      app/controllers/application_controller.rb
  2. 6
      app/controllers/maintenance_controller.rb
  3. 6
      app/services/feature_toggle.rb
  4. 2
      app/views/layouts/application.html.erb
  5. 9
      app/views/maintenance/service_moved.html.erb
  6. 2
      config/initializers/sidekiq.rb
  7. 1
      config/routes.rb
  8. 30
      spec/controllers/maintenance_controller_spec.rb
  9. 36
      spec/features/user_spec.rb
  10. 75
      spec/requests/content_controller_spec.rb
  11. 47
      spec/requests/cookies_controller_spec.rb
  12. 99
      spec/requests/maintenance_controller_spec.rb

16
app/controllers/application_controller.rb

@ -3,13 +3,19 @@ class ApplicationController < ActionController::Base
rescue_from Pundit::NotAuthorizedError, with: :render_not_authorized rescue_from Pundit::NotAuthorizedError, with: :render_not_authorized
before_action :check_maintenance before_action :check_maintenance_status
before_action :set_paper_trail_whodunnit before_action :set_paper_trail_whodunnit
def check_maintenance def check_maintenance_status
if FeatureToggle.maintenance_mode_enabled? && !%w[service-unavailable accessibility-statement privacy-notice cookies].include?(request.fullpath.split("?")[0].delete("/")) if FeatureToggle.service_moved?
redirect_to service_unavailable_path unless %w[service-moved accessibility-statement privacy-notice cookies].include?(request.fullpath.split("?")[0].delete("/"))
elsif !FeatureToggle.maintenance_mode_enabled? && request.fullpath.split("?")[0].delete("/") == "service-unavailable" redirect_to service_moved_path
end
elsif FeatureToggle.service_unavailable?
unless %w[service-unavailable accessibility-statement privacy-notice cookies].include?(request.fullpath.split("?")[0].delete("/"))
redirect_to service_unavailable_path
end
elsif %w[service-moved service-unavailable].include?(request.fullpath.split("?")[0].delete("/"))
redirect_back(fallback_location: root_path) redirect_back(fallback_location: root_path)
end end
end end

6
app/controllers/maintenance_controller.rb

@ -1,4 +1,10 @@
class MaintenanceController < ApplicationController class MaintenanceController < ApplicationController
def service_moved
if current_user
sign_out
end
end
def service_unavailable def service_unavailable
if current_user if current_user
sign_out sign_out

6
app/services/feature_toggle.rb

@ -38,7 +38,11 @@ class FeatureToggle
!Rails.env.production? !Rails.env.production?
end end
def self.maintenance_mode_enabled? def self.service_unavailable?
false
end
def self.service_moved?
false false
end end
end end

2
app/views/layouts/application.html.erb

@ -91,7 +91,7 @@
navigation_classes: "govuk-header__navigation--end", navigation_classes: "govuk-header__navigation--end",
) do |component| ) do |component|
component.product_name(name: t("service_name")) component.product_name(name: t("service_name"))
unless FeatureToggle.maintenance_mode_enabled? unless FeatureToggle.service_moved? || FeatureToggle.service_unavailable?
if current_user.nil? if current_user.nil?
component.navigation_item(text: "Sign in", href: user_session_path) component.navigation_item(text: "Sign in", href: user_session_path)
else else

9
app/views/maintenance/service_moved.html.erb

@ -0,0 +1,9 @@
<h1 class="govuk-heading-l govuk-!-width-two-thirds">
The URL for this service has changed
</h1>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<p class="govuk-body">Submit social housing lettings and sales data (CORE) can now be found at <%= govuk_link_to "https://submit-social-housing-data.levellingup.gov.uk", "https://submit-social-housing-data.levellingup.gov.uk" %>. If you have bookmarked this page, you need to update it.</p>
</div>
</div>

2
config/initializers/sidekiq.rb

@ -33,7 +33,7 @@ Redis.silence_deprecations = true
Sidekiq.configure_server do |config| Sidekiq.configure_server do |config|
config.on(:startup) do config.on(:startup) do
Sidekiq::Cron::Job.all.each(&:destroy) Sidekiq::Cron::Job.all.each(&:destroy)
unless FeatureToggle.maintenance_mode_enabled? unless FeatureToggle.service_moved? || FeatureToggle.service_unavailable?
Sidekiq::Cron::Job.load_from_hash YAML.load_file("config/sidekiq_cron_schedule.yml") Sidekiq::Cron::Job.load_from_hash YAML.load_file("config/sidekiq_cron_schedule.yml")
end end
end end

1
config/routes.rb

@ -35,6 +35,7 @@ Rails.application.routes.draw do
get "/accessibility-statement", to: "content#accessibility_statement" get "/accessibility-statement", to: "content#accessibility_statement"
get "/privacy-notice", to: "content#privacy_notice" get "/privacy-notice", to: "content#privacy_notice"
get "/data-sharing-agreement", to: "content#data_sharing_agreement" get "/data-sharing-agreement", to: "content#data_sharing_agreement"
get "/service-moved", to: "maintenance#service_moved"
get "/service-unavailable", to: "maintenance#service_unavailable" get "/service-unavailable", to: "maintenance#service_unavailable"
get "/download-23-24-lettings-form", to: "start#download_23_24_lettings_form" get "/download-23-24-lettings-form", to: "start#download_23_24_lettings_form"

30
spec/controllers/maintenance_controller_spec.rb

@ -3,10 +3,32 @@ require "rails_helper"
RSpec.describe MaintenanceController do RSpec.describe MaintenanceController do
let(:user) { FactoryBot.create(:user) } let(:user) { FactoryBot.create(:user) }
describe "GET #service_moved" do
context "when the service has moved" do
it "logs the user out" do
allow(FeatureToggle).to receive(:service_moved?).and_return(true)
sign_in user
expect(controller).to be_user_signed_in
get :service_moved
expect(controller).not_to be_user_signed_in
end
end
context "when the service hasn't moved" do
it "doesn't log the user out" do
allow(FeatureToggle).to receive(:service_moved?).and_return(false)
sign_in user
expect(controller).to be_user_signed_in
get :service_moved
expect(controller).to be_user_signed_in
end
end
end
describe "GET #service_unavailable" do describe "GET #service_unavailable" do
context "when maintenance mode is enabled" do context "when the service is unavailable" do
it "logs the user out" do it "logs the user out" do
allow(FeatureToggle).to receive(:maintenance_mode_enabled?).and_return(true) allow(FeatureToggle).to receive(:service_unavailable?).and_return(true)
sign_in user sign_in user
expect(controller).to be_user_signed_in expect(controller).to be_user_signed_in
get :service_unavailable get :service_unavailable
@ -14,9 +36,9 @@ RSpec.describe MaintenanceController do
end end
end end
context "when maintenance mode is disabled" do context "when the service is available" do
it "doesn't log the user out" do it "doesn't log the user out" do
allow(FeatureToggle).to receive(:maintenance_mode_enabled?).and_return(false) allow(FeatureToggle).to receive(:service_unavailable?).and_return(false)
sign_in user sign_in user
expect(controller).to be_user_signed_in expect(controller).to be_user_signed_in
get :service_unavailable get :service_unavailable

36
spec/features/user_spec.rb

@ -140,8 +140,21 @@ RSpec.describe "User Features" do
expect(page).to have_content("Sign in to your account to submit CORE data") expect(page).to have_content("Sign in to your account to submit CORE data")
end end
it "does not show 'Sign in' link if maintenance mode is enabled" do it "does not show 'Sign in' link when the service has moved" do
allow(FeatureToggle).to receive(:maintenance_mode_enabled?).and_return(true) allow(FeatureToggle).to receive(:service_moved?).and_return(true)
visit("/lettings-logs")
expect(page).not_to have_link("Sign in")
end
it "does not show 'Sign in' link when the service is unavailable" do
allow(FeatureToggle).to receive(:service_unavailable?).and_return(true)
visit("/lettings-logs")
expect(page).not_to have_link("Sign in")
end
it "does not show 'Sign in' link when both the service_moved? and service_unavailable? feature toggles are on" do
allow(FeatureToggle).to receive(:service_moved?).and_return(true)
allow(FeatureToggle).to receive(:service_unavailable?).and_return(true)
visit("/lettings-logs") visit("/lettings-logs")
expect(page).not_to have_link("Sign in") expect(page).not_to have_link("Sign in")
end end
@ -331,8 +344,23 @@ RSpec.describe "User Features" do
expect(page).to have_selector('[data-qa="change-key-contact"]') expect(page).to have_selector('[data-qa="change-key-contact"]')
end end
it "does not show 'Your account' or 'Sign out' links if maintenance mode is enabled" do it "does not show 'Your account' or 'Sign out' links when the service has moved" do
allow(FeatureToggle).to receive(:maintenance_mode_enabled?).and_return(true) allow(FeatureToggle).to receive(:service_moved?).and_return(true)
visit("/lettings-logs")
expect(page).not_to have_link("Your account")
expect(page).not_to have_link("Sign out")
end
it "does not show 'Your account' or 'Sign out' links when the service is unavailable" do
allow(FeatureToggle).to receive(:service_unavailable?).and_return(true)
visit("/lettings-logs")
expect(page).not_to have_link("Your account")
expect(page).not_to have_link("Sign out")
end
it "does not show 'Your account' or 'Sign out' links when both the service_moved? and service_unavailable? feature toggles are on" do
allow(FeatureToggle).to receive(:service_moved?).and_return(true)
allow(FeatureToggle).to receive(:service_unavailable?).and_return(true)
visit("/lettings-logs") visit("/lettings-logs")
expect(page).not_to have_link("Your account") expect(page).not_to have_link("Your account")
expect(page).not_to have_link("Sign out") expect(page).not_to have_link("Sign out")

75
spec/requests/content_controller_spec.rb

@ -4,7 +4,7 @@ RSpec.describe ContentController, type: :request do
let(:headers) { { "Accept" => "text/html" } } let(:headers) { { "Accept" => "text/html" } }
let(:page) { Capybara::Node::Simple.new(response.body) } let(:page) { Capybara::Node::Simple.new(response.body) }
describe "when maintenance mode is disabled" do describe "when the service is available" do
describe "render privacy notice content page" do describe "render privacy notice content page" do
before do before do
get "/privacy-notice", headers:, params: {} get "/privacy-notice", headers:, params: {}
@ -48,9 +48,78 @@ RSpec.describe ContentController, type: :request do
end end
end end
describe "when maintenance mode is enabled" do describe "when the service has moved" do
before do before do
allow(FeatureToggle).to receive(:maintenance_mode_enabled?).and_return(true) allow(FeatureToggle).to receive(:service_moved?).and_return(true)
end
describe "render privacy notice content page" do
before do
get "/privacy-notice", headers:, params: {}
end
it "returns a 200" do
expect(response).to have_http_status(:success)
end
it "returns the page" do
expect(page).to have_title("Privacy notice")
end
end
describe "render accessibility statement content page" do
before do
get "/accessibility-statement", headers:, params: {}
end
it "returns a 200" do
expect(response).to have_http_status(:success)
end
it "returns the page" do
expect(page).to have_title("Accessibility statement")
end
end
end
describe "when the service is unavailable" do
before do
allow(FeatureToggle).to receive(:service_unavailable?).and_return(true)
end
describe "render privacy notice content page" do
before do
get "/privacy-notice", headers:, params: {}
end
it "returns a 200" do
expect(response).to have_http_status(:success)
end
it "returns the page" do
expect(page).to have_title("Privacy notice")
end
end
describe "render accessibility statement content page" do
before do
get "/accessibility-statement", headers:, params: {}
end
it "returns a 200" do
expect(response).to have_http_status(:success)
end
it "returns the page" do
expect(page).to have_title("Accessibility statement")
end
end
end
describe "when both the service_moved? and service_unavailable? feature toggles are on" do
before do
allow(FeatureToggle).to receive(:service_moved?).and_return(true)
allow(FeatureToggle).to receive(:service_unavailable?).and_return(true)
end end
describe "render privacy notice content page" do describe "render privacy notice content page" do

47
spec/requests/cookies_controller_spec.rb

@ -4,7 +4,7 @@ RSpec.describe CookiesController, type: :request do
let(:headers) { { "Accept" => "text/html" } } let(:headers) { { "Accept" => "text/html" } }
let(:page) { Capybara::Node::Simple.new(response.body) } let(:page) { Capybara::Node::Simple.new(response.body) }
describe "when maintenance mode is disabled" do describe "when the service is available" do
describe "render cookies page" do describe "render cookies page" do
before do before do
get "/cookies", headers:, params: {} get "/cookies", headers:, params: {}
@ -20,9 +20,50 @@ RSpec.describe CookiesController, type: :request do
end end
end end
describe "when maintenance mode is enabled" do describe "when the service has moved" do
before do before do
allow(FeatureToggle).to receive(:maintenance_mode_enabled?).and_return(true) allow(FeatureToggle).to receive(:service_moved?).and_return(true)
end
describe "render cookies page" do
before do
get "/cookies", headers:, params: {}
end
it "returns a 200" do
expect(response).to have_http_status(:success)
end
it "returns the page" do
expect(page).to have_title("Cookies")
end
end
end
describe "when the service is unavailable" do
before do
allow(FeatureToggle).to receive(:service_unavailable?).and_return(true)
end
describe "render cookies page" do
before do
get "/cookies", headers:, params: {}
end
it "returns a 200" do
expect(response).to have_http_status(:success)
end
it "returns the page" do
expect(page).to have_title("Cookies")
end
end
end
describe "when both the service_moved? and service_unavailable? feature toggles are on" do
before do
allow(FeatureToggle).to receive(:service_moved?).and_return(true)
allow(FeatureToggle).to receive(:service_unavailable?).and_return(true)
end end
describe "render cookies page" do describe "render cookies page" do

99
spec/requests/maintenance_controller_spec.rb

@ -8,17 +8,55 @@ RSpec.describe MaintenanceController, type: :request do
sign_in user sign_in user
end end
describe "when maintenance mode is enabled" do describe "when the service has moved" do
before do before do
allow(FeatureToggle).to receive(:maintenance_mode_enabled?).and_return(true) allow(FeatureToggle).to receive(:service_moved?).and_return(true)
end end
context "when a user visits a page other than the maintenance page" do context "when a user visits a page other than the service moved page" do
before do
get "/service-unavailable"
end
it "redirects the user to the service moved page" do
expect(response).to redirect_to(service_moved_path)
follow_redirect!
expect(page).to have_content("The URL for this service has changed")
end
it "the cookie banner is visible" do
follow_redirect!
expect(page).to have_content("We’d like to use analytics cookies so we can understand how you use the service and make improvements.")
end
end
context "when a user visits the service moved page" do
before do
get "/service-moved"
end
it "keeps the user on the service moved page" do
expect(response).not_to redirect_to(service_moved_path)
expect(page).to have_content("The URL for this service has changed")
end
it "the cookie banner is visible" do
expect(page).to have_content("We’d like to use analytics cookies so we can understand how you use the service and make improvements.")
end
end
end
describe "when the service is unavailable" do
before do
allow(FeatureToggle).to receive(:service_unavailable?).and_return(true)
end
context "when a user visits a page other than the service unavailable page" do
before do before do
get "/lettings-logs" get "/lettings-logs"
end end
it "redirects the user to the maintenance page" do it "redirects the user to the service unavailable page" do
expect(response).to redirect_to(service_unavailable_path) expect(response).to redirect_to(service_unavailable_path)
follow_redirect! follow_redirect!
expect(page).to have_content("Sorry, the service is unavailable") expect(page).to have_content("Sorry, the service is unavailable")
@ -30,12 +68,12 @@ RSpec.describe MaintenanceController, type: :request do
end end
end end
context "when a user visits the maintenance page" do context "when a user visits the service unavailable page" do
before do before do
get "/service-unavailable" get "/service-unavailable"
end end
it "keeps the user on the maintenance page" do it "keeps the user on the service unavailable page" do
expect(response).not_to redirect_to(service_unavailable_path) expect(response).not_to redirect_to(service_unavailable_path)
expect(page).to have_content("Sorry, the service is unavailable") expect(page).to have_content("Sorry, the service is unavailable")
end end
@ -46,17 +84,56 @@ RSpec.describe MaintenanceController, type: :request do
end end
end end
describe "when maintenance mode is disabled" do describe "when both the service_moved? and service_unavailable? feature toggles are on" do
before do
allow(FeatureToggle).to receive(:service_moved?).and_return(true)
allow(FeatureToggle).to receive(:service_unavailable?).and_return(true)
end
context "when a user visits a page other than the service moved page" do
before do
get "/service-unavailable"
end
it "redirects the user to the service moved page" do
expect(response).to redirect_to(service_moved_path)
follow_redirect!
expect(page).to have_content("The URL for this service has changed")
end
it "the cookie banner is visible" do
follow_redirect!
expect(page).to have_content("We’d like to use analytics cookies so we can understand how you use the service and make improvements.")
end
end
context "when a user visits the service moved page" do
before do
get "/service-moved"
end
it "keeps the user on the service moved page" do
expect(response).not_to redirect_to(service_moved_path)
expect(page).to have_content("The URL for this service has changed")
end
it "the cookie banner is visible" do
expect(page).to have_content("We’d like to use analytics cookies so we can understand how you use the service and make improvements.")
end
end
end
describe "when the service is available" do
before do before do
allow(FeatureToggle).to receive(:maintenance_mode_enabled?).and_return(false) allow(FeatureToggle).to receive(:service_unavailable?).and_return(false)
end end
context "when a user visits a page other than the maintenance page" do context "when a user visits a page other than the service unavailable page" do
before do before do
get "/lettings-logs" get "/lettings-logs"
end end
it "doesn't redirect the user to the maintenance page" do it "doesn't redirect the user to the service unavailable page" do
expect(response).not_to redirect_to(service_unavailable_path) expect(response).not_to redirect_to(service_unavailable_path)
expect(page).to have_content("Create a new lettings log") expect(page).to have_content("Create a new lettings log")
end end
@ -66,7 +143,7 @@ RSpec.describe MaintenanceController, type: :request do
end end
end end
context "when a user visits the maintenance page" do context "when a user visits the service unavailable page" do
before do before do
get "/service-unavailable" get "/service-unavailable"
end end

Loading…
Cancel
Save