Skip to content

Commit a831d74

Browse files
Feat: web console (#58)
* feat: add web console * feat: add staging env * fix: user email seed * fix: move web-console * fix: rubocop
1 parent 8de83f2 commit a831d74

File tree

6 files changed

+133
-2
lines changed

6 files changed

+133
-2
lines changed

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ gem 'stackprof'
4646
gem 'sentry-ruby'
4747
gem 'sentry-rails'
4848

49+
gem 'web-console'
50+
4951
group :development, :test do
5052
gem 'brakeman', require: false
5153
gem 'debug', platforms: %i[mri windows], require: 'debug/prelude'
@@ -66,7 +68,6 @@ group :development do
6668
gem 'rubocop-rails', '>= 2.22.0', require: false
6769
gem 'ruby-lsp'
6870
gem 'ruby-lsp-rails'
69-
gem 'web-console'
7071
gem 'bullet'
7172
gem 'rails-mermaid_erd'
7273
gem 'i18n-tasks'
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# This controller help run console commands in the admin app only develop and staging
2+
# rubocop:disable Rails/RenderInline
3+
4+
module Admin
5+
class ConsoleController < BaseController
6+
def index
7+
console
8+
render inline: <<~HTML
9+
<div style="position: fixed; top: 0; left: 0; width: 100%; background-color: #fff; z-index: 1000; border-bottom: 1px solid #ddd; padding: 20px 0;">
10+
<div style="font-family: Arial, sans-serif; text-align: center;">
11+
<h1 style="font-size: 36px; font-weight: bold; margin: 0;">
12+
Web Console
13+
</h1>
14+
<p style="font-size: 16px; color: #FF5722; margin: 10px 0; font-weight: bold;">
15+
Please use this console with caution! It provides direct access to the database.
16+
<br>
17+
Any changes made here will take immediate effect and may be irreversible.
18+
</p>
19+
<a href="/admin" style="font-size: 16px; color: #007BFF; text-decoration: none;">
20+
&larr; Back to Home
21+
</a>
22+
</div>
23+
</div>
24+
<div class="console" style="margin-top: 150px; padding: 15px;">
25+
<!-- The console content goes here -->
26+
</div>
27+
<style>
28+
.console {
29+
height: calc(100% - 180px);
30+
}
31+
</style>
32+
HTML
33+
end
34+
end
35+
end
36+
37+
# rubocop:enable Rails/RenderInline

config/application.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,9 @@ class Application < Rails::Application
5252
config.i18n.default_locale = :en
5353
config.i18n.load_path += Rails.root.glob('config/locales/**/*.{rb, yml}')
5454
config.i18n.fallbacks = [I18n.default_locale]
55+
56+
# Enable web console in browser - protected by devise
57+
config.web_console.development_only = false
58+
config.web_console.permissions = '0.0.0.0/0'
5559
end
5660
end

config/environments/staging.rb

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# frozen_string_literal: true
2+
3+
require 'active_support/core_ext/integer/time'
4+
5+
Rails.application.configure do
6+
# Settings specified here will take precedence over those in config/application.rb.
7+
8+
# Code is not reloaded between requests.
9+
config.enable_reloading = false
10+
11+
# Eager load code on boot. This eager loads most of Rails and
12+
# your application in memory, allowing both threaded web servers
13+
# and those relying on copy on write to perform better.
14+
# Rake tasks automatically ignore this option for performance.
15+
config.eager_load = true
16+
17+
# Full error reports are disabled and caching is turned on.
18+
config.consider_all_requests_local = false
19+
config.action_controller.perform_caching = true
20+
21+
# Ensures that a master key has been made available in ENV["RAILS_MASTER_KEY"], config/master.key, or an environment
22+
# key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files).
23+
# config.require_master_key = true
24+
25+
# Disable serving static files from `public/`, relying on NGINX/Apache to do so instead.
26+
# config.public_file_server.enabled = false
27+
28+
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
29+
# config.asset_host = "http://assets.example.com"
30+
31+
# Specifies the header that your server uses for sending files.
32+
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache
33+
# config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX
34+
35+
# Mount Action Cable outside main process or domain.
36+
# config.action_cable.mount_path = nil
37+
# config.action_cable.url = "wss://example.com/cable"
38+
# config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ]
39+
40+
# Assume all access to the app is happening through a SSL-terminating reverse proxy.
41+
# Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies.
42+
# config.assume_ssl = true
43+
44+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
45+
config.force_ssl = ENV['RAILS_DISABLE_SSL'].blank?
46+
47+
# Skip http-to-https redirect for the default health check endpoint.
48+
# config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } }
49+
50+
# Log to STDOUT by default
51+
config.logger = ActiveSupport::Logger.new($stdout)
52+
.tap { |logger| logger.formatter = Logger::Formatter.new }
53+
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
54+
55+
# Prepend all log lines with the following tags.
56+
config.log_tags = [:request_id]
57+
58+
# "info" includes generic and useful information about system operation, but avoids logging too much
59+
# information to avoid inadvertent exposure of personally identifiable information (PII). If you
60+
# want to log everything, set the level to "debug".
61+
config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info')
62+
63+
# Use a different cache store in production.
64+
# config.cache_store = :mem_cache_store
65+
66+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
67+
# the I18n.default_locale when a translation cannot be found).
68+
config.i18n.fallbacks = true
69+
70+
# Don't log any deprecations.
71+
config.active_support.report_deprecations = false
72+
73+
# Do not dump schema after migrations.
74+
config.active_record.dump_schema_after_migration = false
75+
76+
# Store files locally.
77+
config.active_storage.service = :amazon
78+
79+
# Enable DNS rebinding protection and other `Host` header attacks.
80+
# config.hosts = [
81+
# "example.com", # Allow requests from example.com
82+
# /.*\.example\.com/ # Allow requests from subdomains like `www.example.com`
83+
# ]
84+
# Skip DNS rebinding protection for the default health check endpoint.
85+
# config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
86+
end

config/routes.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
authenticate :user, lambda { |u| u.has_role?(:super_admin) } do
99
mount Sidekiq::Web => '/sidekiq'
10+
unless Rails.env.production?
11+
get 'admin/console', to: 'admin/console#index'
12+
end
1013
end
1114

1215
devise_for :users,

db/seeds/01_users.seeds.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
puts '===> create users'
22

33
puts '---- super admin'
4-
super_admin_email = 'super_admin.gos@rails_boilerplate.com'
4+
super_admin_email = 'super_admin.gos@rails.boilerplate.com'
55
if User.find_by(email: super_admin_email).blank?
66
super_admin = User.create!(
77
email: super_admin_email,

0 commit comments

Comments
 (0)