From 99b0195c8f32535981cf29a1c997c2a759d40156 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Mon, 26 Jun 2023 16:15:51 +0200 Subject: [PATCH] maintenance mode --- app/controllers/application_controller.rb | 1 + .../with_maintenance.rb | 16 +++++ public/maintenance.html | 65 +++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 app/controllers/application_controller/with_maintenance.rb create mode 100644 public/maintenance.html diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9a81171e5..23d8b4bec 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,6 +3,7 @@ class ApplicationController < ActionController::Base include WithErrors include WithFeatures include WithLocale + include WithMaintenance before_action :ensure_university, :authenticate_user! diff --git a/app/controllers/application_controller/with_maintenance.rb b/app/controllers/application_controller/with_maintenance.rb new file mode 100644 index 000000000..0f28e2325 --- /dev/null +++ b/app/controllers/application_controller/with_maintenance.rb @@ -0,0 +1,16 @@ +module ApplicationController::WithMaintenance + extend ActiveSupport::Concern + + included do + before_action :check_maintenance + end + + protected + + def check_maintenance + if ENV['MAINTENANCE'] && + current_user&.role != 'server_admin' + redirect_to '/maintenance' + end + end +end diff --git a/public/maintenance.html b/public/maintenance.html new file mode 100644 index 000000000..47c8b4c50 --- /dev/null +++ b/public/maintenance.html @@ -0,0 +1,65 @@ +<!DOCTYPE html> +<html> + +<head> + <title>Maintenance in progress</title> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width,initial-scale=1"> + <meta http-equiv="refresh" content="30;URL=/"> + <style> + body { + padding: 15px; + } + + * { + font-family: sans-serif; + font-size: 14px; + margin: 0; + text-align: center; + } + + .dialog { + width: 95%; + max-width: 22em; + margin: calc(50vh - 140px) auto 0; + } + + .dialog span { + font-size: 150px; + font-weight: 900; + letter-spacing: -0.04em; + display: block; + width: 100%; + line-height: 0.9; + margin-bottom: 50px + } + + img { + margin-bottom: 30px; + } + + h1 { + font-size: 14px; + line-height: 1.5em; + margin-bottom: 30px; + } + + h1 em { + font-weight: 400; + } + </style> +</head> + +<body> + <div class="dialog"> + <span> + ⌛ + </span> + <div> + <h1>Maintenance in progress</h1> + <a href="/"><img src="/logo.svg" alt="Osuny" width="100"></a> + </div> + </div> +</body> + +</html> -- GitLab