Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise maintenance page feature #965

Merged
merged 11 commits into from
Nov 16, 2023
7 changes: 4 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
#
# ------------------------------------------------------------------------------

# Display console information
VERBOSE=true
# Display debugging information
DEBUG=true
# Disable service for maintenance
MAINTENANCE = true

# Development behind corporate proxy
# For example: '/Library/Application Support/Netskope/STAgent/data/nscacert.pem'
Expand Down Expand Up @@ -81,6 +85,3 @@ E2E=true

# Deployment environment
ENVIRONMENT=

# DISPLAY SERVICE_UNAVAILABLE PAGE
MAINTENANCE = true
38 changes: 19 additions & 19 deletions .github/workflows/content.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@
# https://ey-recovery-pr-123.london.cloudapps.digital
#
name: Deploy Content App
# on:
# pull_request:
# # branches:
# # - main
# types:
# - labeled
# - synchronize
# paths-ignore:
# - '**/*.md'
# - .docker*
# - .env.example
# - .gitignore
# - .pa11yci
# - .tool-versions
# - .yardopts
# - bin/*
# - docker-compose.*
# - Dockerfile
# - terraform
on:
pull_request:
# branches:
# - main
types:
- labeled
- synchronize
paths-ignore:
- '**/*.md'
- .docker*
- .env.example
- .gitignore
- .pa11yci
- .tool-versions
- .yardopts
- bin/*
- docker-compose.*
- Dockerfile
- terraform

jobs:
deploy:
Expand Down
32 changes: 16 additions & 16 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
# https://ey-recovery-dev.london.cloudapps.digital
#
name: Deploy Development App
# on:
# workflow_dispatch:
# push:
# branches:
# - main
# paths-ignore:
# - '**/*.md'
# - .docker*
# - .env.example
# - .gitignore
# - .pa11yci
# - .tool-versions
# - .yardopts
# - bin/*
# - docker-compose.*
# - uml/*
on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- '**/*.md'
- .docker*
- .env.example
- .gitignore
- .pa11yci
- .tool-versions
- .yardopts
- bin/*
- docker-compose.*
- uml/*

jobs:
deploy:
Expand Down
10 changes: 6 additions & 4 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
class ApplicationController < ActionController::Base
around_action :set_time_zone

before_action :maintenance_page, if: :maintenance?
before_action :configure_permitted_parameters, if: :devise_controller?
before_action :set_analytics_tracking_id,
:set_hotjar_site_id,
:prepare_cms

before_action :maintenance_page, if: :maintenance?

helper_method :current_user,
:timeout_timer,
:debug?

default_form_builder(EarlyYearsRecoveryFormBuilder)

include Tracking
Expand Down Expand Up @@ -68,9 +68,11 @@ def timeout_timer

private

# @return [Boolean]
# @return [Boolean] health check and landing page requests are exempt
def maintenance?
Rails.application.maintenance? && request.path != '/maintenance'
return false if %w[/maintenance /health].include?(request.path)

Rails.application.maintenance?
end

def maintenance_page
Expand Down
2 changes: 1 addition & 1 deletion app/services/content_integrity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def mod

# @return [Boolean]
def debug?
(Rails.application.debug? || Rails.application.candidate?) && !valid?
(Rails.application.debug? || Rails.application.preview?) && !valid?
end

# @return [Array<String>]
Expand Down
49 changes: 16 additions & 33 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,31 @@ class Application < Rails::Application
# @see ErrorsController
config.exceptions_app = routes

config.generators do |g|
g.test_framework :rspec
end

# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
# in config/environments, which are processed later.
#
# config.eager_load_paths << Rails.root.join("extras")

# causes log colting error when deploying a review app in GPaaS
# config.time_zone = ENV.fetch('TZ', 'Europe/London')

config.generators do |g|
g.test_framework :rspec
end

config.service_name = 'Early years child development training'
config.internal_mailbox = ENV.fetch('INTERNAL_MAILBOX', '[email protected]')
config.middleware.use Grover::Middleware
config.active_record.yaml_column_permitted_classes = [Symbol]
config.action_view.sanitized_allowed_tags = ALLOWED_TAGS

# Background Jobs
config.active_job.queue_adapter = :que
config.active_job.queue_adapter = :que
config.action_mailer.deliver_later_queue_name = :default
config.action_mailbox.queues.incineration = :default
config.action_mailbox.queues.routing = :default
config.active_storage.queues.analysis = :default
config.active_storage.queues.purge = :default
config.action_mailbox.queues.incineration = :default
config.action_mailbox.queues.routing = :default
config.active_storage.queues.analysis = :default
config.active_storage.queues.purge = :default

config.google_cloud_bucket = ENV.fetch('GOOGLE_CLOUD_BUCKET', '#GOOGLE_CLOUD_BUCKET_env_var_missing')
config.dashboard_update_interval = ENV.fetch('DASHBOARD_UPDATE_INTERVAL', '0 0 * * *') # Midnight daily
Expand All @@ -70,27 +68,7 @@ class Application < Rails::Application

# @return [Boolean]
def live?
ENV['WORKSPACE'].eql?('production')
end

# @return [Boolean]
def candidate?
ENV['WORKSPACE'].eql?('staging')
end

# @return [Boolean]
def main?
ENV['WORKSPACE'].eql?('development')
end

# @return [Boolean]
def review?
ENV['WORKSPACE'].eql?('content')
end

# @return [Boolean] Upload to CSV files to the dashboard
def dashboard?
Types::Params::Bool[ENV.fetch('DASHBOARD_UPDATE', true)]
ENV['WORKSPACE'].eql?('production') || ENV['ENVIRONMENT'].eql?('production')
end

# @see ContentfulRails.configuration.enable_preview_domain
Expand All @@ -101,14 +79,19 @@ def preview?
Dry::Types['params.bool'][ENV.fetch('CONTENTFUL_PREVIEW', false)]
end

# @return [Boolean] Upload to CSV files to the dashboard
def dashboard?
Types::Params::Bool[ENV.fetch('DASHBOARD_UPDATE', true)]
end

# @return [Boolean]
def debug?
Types::Params::Bool[ENV.fetch('DEBUG', false)]
end

# @return [Boolean]
def maintenance?
Types::Params::Bool[ENV.fetch('MAINTENANCE', true)]
Types::Params::Bool[ENV.fetch('MAINTENANCE', false)]
end

# @return [ActiveSupport::TimeWithZone]
Expand Down
47 changes: 26 additions & 21 deletions spec/system/maintenance_spec.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
require 'rails_helper'

RSpec.shared_examples 'displays service unavailable page' do
it 'displays the service unavailable message and title' do
expect(page).to have_css('h1', text: 'Sorry, the service is unavailable')
expect(page).to have_title('Early years child development training : Sorry, the service is unavailable')
RSpec.describe 'Service unavailable' do
shared_examples 'down for maintenance' do
it 'makes the service unavailable' do
expect(page).to have_title 'Early years child development training : Sorry, the service is unavailable'
expect(page).to have_content 'Sorry, the service is unavailable'
end
end
end

RSpec.describe 'Service Unavailable' do
before do
allow(Rails.application).to receive(:maintenance?).and_return(true)
visit destination
end

context 'when the service is unavailable and user navigates to home' do
before do
visit '/'
end
context 'with internal health check' do
let(:destination) { '/health' }

it_behaves_like 'displays service unavailable page'
specify { expect(destination).to be_successful }
end

context 'when the service is unavailable and user navigates to my modules page' do
before do
visit my_modules_path
end
context 'with maintenance page' do
let(:destination) { '/maintenance' }

it_behaves_like 'displays service unavailable page'
specify { expect(destination).to be_successful }
end

context 'when the service is unavailable and user is already on the service unavailable page' do
before do
visit '/maintenance'
end
context 'with a public page' do
let(:destination) { '/' }

specify { expect(destination).not_to be_successful }

it_behaves_like 'down for maintenance'
end

context 'with a private page' do
let(:destination) { '/my-account' }

specify { expect(destination).not_to be_successful }

it_behaves_like 'displays service unavailable page'
it_behaves_like 'down for maintenance'
end
end
3 changes: 2 additions & 1 deletion terraform/workspace-variables/app_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ defaults: &defaults
FEEDBACK_URL: https://forms.office.com/Pages/ResponsePage.aspx?id=yXfS-grGoU2187O4s0qC-Qjm3BfYzDVIhkQadsLBtTxUMk01Qlc1R0dKRUQ0WEpPUUFYVzdWRllXUCQlQCN0PWcu
GROVER_NO_SANDBOX: true
EDITOR: vi
# Service Down
MAINTENANCE: true

# ey-recovery
production:
Expand All @@ -22,7 +24,6 @@ production:
# jobs
GOOGLE_CLOUD_BUCKET: eyfs-recovery-production
# DASHBOARD_UPDATE: false
MAINTENANCE: true

# ey-recovery-staging
staging:
Expand Down
Loading