Skip to content

Commit

Permalink
Merge pull request #1100 from griffithlab/maintenance-mode
Browse files Browse the repository at this point in the history
Add rudimentary maintenance toggle admin utility
  • Loading branch information
acoffman authored Aug 21, 2024
2 parents d87f723 + 4d7d408 commit b83d0c3
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 3 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions server/app/admin/utilities_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ def show

def perform_action
@util = ActionWrapper::AVAILABLE_ACTIONS.find { |x| params[:name] == x.name }
util_params = params.permit(@util.inputs.keys).to_h
util_params = params.permit(@util.inputs.keys).to_h.symbolize_keys
#checkbox will come in as 0 or 1
#cast it to a boolean here so utilities dont have to worry about that
util_params.each do |key, val|
if @util.inputs[key] == :boolean
util_params[key] = ActiveRecord::Type::Boolean.new.cast(val)
end
end
action = @util.new
res = action.perform(util_params.symbolize_keys)
res = action.perform(util_params)

if res.errors.any?
flash[:error] = res.errors.join("\n")
Expand Down
53 changes: 53 additions & 0 deletions server/app/models/actions/toggle_maintenance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require 'fileutils'

module Actions
class ToggleMaintenance
include Actions::Transactional

attr_reader :maintenance_mode_enabled, :maintenance_page, :backed_up_index_page, :index_file_path

def initialize(maintenance_mode_enabled:)
@maintenance_mode_enabled = maintenance_mode_enabled

base_path = File.join(Rails.root, 'public')

@maintenance_page = File.join(base_path, 'maintenance.html')
@backed_up_index_page = File.join(base_path, 'index.html.actual')
@index_file_path = File.join(base_path, 'index.html')
end

def execute
if !File.exist?(index_file_path)
raise StandardError.new("index.html does not exist. Unknown state.")
end

if maintenance_mode_enabled
put_in_maintenance_mode
else
restore_production_mode
end
end

private
def put_in_maintenance_mode
if !File.exist?(maintenance_page)
raise StandardError.new("There doesn't seem to be a maintenance page available to use.")
end
if File.exist?(backed_up_index_page)
raise StandardError.new("Site appears to already be in maintenance mode.")
end

FileUtils.mv(index_file_path, backed_up_index_page)
FileUtils.cp(maintenance_page, index_file_path)
end

def restore_production_mode
if !File.exist?(backed_up_index_page)
raise StandardError.new("No backed up index.html found. Either the site is already live or we cannot restore.")
end

FileUtils.rm(index_file_path)
FileUtils.mv(backed_up_index_page, index_file_path)
end
end
end
3 changes: 2 additions & 1 deletion server/app/utilities/action_wrapper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class ActionWrapper
AVAILABLE_ACTIONS = [
MergeAccounts
MergeAccounts,
ToggleMaintenanceMode
]

def self.name
Expand Down
20 changes: 20 additions & 0 deletions server/app/utilities/toggle_maintenance_mode.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class ToggleMaintenanceMode < ActionWrapper

def self.name
"Toggle Maintenance Mode"
end

def self.description
"Turn on or off the maintenance page. Please do not touch this unless you're a developer. It will take down the site temporarily."
end

def self.inputs
{
maintenance_mode_enabled: :boolean
}
end

def action_class
Actions::ToggleMaintenance
end
end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions server/public/maintenance.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!doctype html>
<html class="no-js" lang="EN">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>Maintenance Page</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
html {
background: linear-gradient(
to bottom,
#1b072e 0%,
#370e5f 100%
); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
background-repeat: no-repeat;
min-height: 100%;
min-width: 600px;
width: 100%;
height: auto;
}

a {
color: white;
}

.logo {
width: 100%;
margin: 8em auto 0 auto;
text-align: center;
}

.notice {
margin: 5em auto;
width: 100%;
}
.notice p {
text-align: center;
color: white;
font-family:
Segoe UI,
Roboto,
Helvetica Neue,
Arial,
Noto Sans,
sans-serif;
}
</style>
</head>
<body>
<div class="logo">
<img
src="assets/images/CIViC_logo_for-dark-bg_LG_v5a.png"
width="350"
alt="CIViC - Clinical Interpretation of Variants in Cancer"
/>
</div>
<div class="notice">
<p style="font-size: 150%; font-weight: bold">
CIViC is temporarily down for Maintenance. It will be back up shortly.
</p>
</div>
</body>
</html>

0 comments on commit b83d0c3

Please sign in to comment.