Skip to content

Commit

Permalink
Merge pull request #9764 from alphagov/maintenance-page
Browse files Browse the repository at this point in the history
Create a maintenance page for Whitehall
  • Loading branch information
ryanb-gds authored Dec 20, 2024
2 parents 8dfee82 + fa596af commit 6d6c23c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base

before_action :set_current_user
before_action :set_authenticated_user_header
before_action :check_maintenance_mode

rescue_from Notifications::Client::BadRequestError, with: :notify_bad_request

Expand All @@ -29,6 +30,12 @@ def set_authenticated_user_header
end
end

def check_maintenance_mode
if Flipflop.maintenance_mode?
render "admin/errors/down_for_maintenance", status: :service_unavailable
end
end

def notify_bad_request(_exception)
render plain: "Error: One or more recipients not in GOV.UK Notify team (code: 400)", status: :bad_request
end
Expand Down
9 changes: 9 additions & 0 deletions app/views/admin/errors/down_for_maintenance.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% content_for :page_title, "Down for maintenance" %>
<% content_for :title, "Down for maintenance" %>
<% content_for :title_margin_bottom, 6 %>

<div class="govuk-grid-row govuk-!-margin-bottom-0">
<div class="govuk-grid-column-two-thirds">
<p class="govuk-body">Whitehall is currently down for maintenance. We'll be back soon.</p>
</div>
</div>
1 change: 1 addition & 0 deletions config/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# feature :world_domination,
# default: true,
# description: "Take over the world."
feature :maintenance_mode, description: "Put Whitehall into maintenance mode for planned downtime", default: false
feature :delete_review_reminders, description: "Enables deletion of review reminders", default: false
feature :govspeak_visual_editor, description: "Enables a visual editor for Govspeak fields", default: false
feature :override_government, description: "Enables GDS Editors and Admins to override the government associated with a document", default: false
Expand Down
12 changes: 12 additions & 0 deletions test/functional/admin/base_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ class Admin::BaseControllerTest < ActionController::TestCase
assert_not_current_item("/government/admin/organisations/my-test-org/features")
end

view_test "dashboard page is inaccessible when maintenance mode is enabled" do
test_strategy = Flipflop::FeatureSet.current.test!
test_strategy.switch!(:maintenance_mode, true)
login_as :gds_editor
@controller = Admin::DashboardController.new
get :index

assert_response :service_unavailable
assert_template "admin/errors/down_for_maintenance"
test_strategy.switch!(:maintenance_mode, false)
end

private

def assert_not_current_item(path)
Expand Down

0 comments on commit 6d6c23c

Please sign in to comment.