Add rails-settings-cached, use for initial feature flags
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
7280a4c023
commit
cd7b05e2ff
1
Gemfile
1
Gemfile
@ -38,6 +38,7 @@ gem 'net-ldap'
|
||||
|
||||
# Utilities
|
||||
gem "rqrcode", "~> 2.0"
|
||||
gem 'rails-settings-cached', '~> 2.8.3'
|
||||
|
||||
# HTTP requests
|
||||
gem 'faraday'
|
||||
|
@ -206,6 +206,9 @@ GEM
|
||||
nokogiri (>= 1.6)
|
||||
rails-html-sanitizer (1.4.3)
|
||||
loofah (~> 2.3)
|
||||
rails-settings-cached (2.8.3)
|
||||
activerecord (>= 5.0.0)
|
||||
railties (>= 5.0.0)
|
||||
railties (7.0.4)
|
||||
actionpack (= 7.0.4)
|
||||
activesupport (= 7.0.4)
|
||||
@ -327,6 +330,7 @@ DEPENDENCIES
|
||||
pg (~> 1.2.3)
|
||||
puma (~> 4.1)
|
||||
rails (~> 7.0.2)
|
||||
rails-settings-cached (~> 2.8.3)
|
||||
rqrcode (~> 2.0)
|
||||
rspec-rails
|
||||
sidekiq (< 7)
|
||||
|
@ -13,7 +13,7 @@ class Admin::LightningController < Admin::BaseController
|
||||
end
|
||||
|
||||
def check_feature_enabled
|
||||
if ENV["LNDHUB_ADMIN_UI"].empty?
|
||||
if !Setting.lndhub_admin_enabled?
|
||||
flash[:alert] = "Lightning Admin UI not enabled"
|
||||
redirect_to admin_root_path and return
|
||||
end
|
||||
|
7
app/models/setting.rb
Normal file
7
app/models/setting.rb
Normal file
@ -0,0 +1,7 @@
|
||||
# RailsSettings Model
|
||||
class Setting < RailsSettings::Base
|
||||
cache_prefix { "v1" }
|
||||
|
||||
field :lndhub_enabled, default: (ENV["LNDHUB_API_URL"].present?.to_s || "false"), type: :boolean
|
||||
field :lndhub_admin_enabled, default: (ENV["LNDHUB_ADMIN_UI"] || "false"), type: :boolean
|
||||
end
|
@ -6,7 +6,7 @@
|
||||
class: main_nav_class(@current_section, :invitations) %>
|
||||
<%= link_to "Donations", admin_donations_path,
|
||||
class: main_nav_class(@current_section, :donations) %>
|
||||
<% if ENV["LNDHUB_ADMIN_UI"] %>
|
||||
<% if Setting.lndhub_admin_enabled? %>
|
||||
<%= link_to "Lightning", admin_lightning_path,
|
||||
class: main_nav_class(@current_section, :lightning) %>
|
||||
<% end %>
|
||||
|
15
db/migrate/20230217084310_create_settings.rb
Normal file
15
db/migrate/20230217084310_create_settings.rb
Normal file
@ -0,0 +1,15 @@
|
||||
class CreateSettings < ActiveRecord::Migration[7.0]
|
||||
def self.up
|
||||
create_table :settings do |t|
|
||||
t.string :var, null: false
|
||||
t.text :value, null: true
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :settings, %i(var), unique: true
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :settings
|
||||
end
|
||||
end
|
10
db/schema.rb
10
db/schema.rb
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_01_11_113139) do
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_02_17_084310) do
|
||||
create_table "donations", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "amount_sats"
|
||||
@ -34,6 +34,14 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_11_113139) do
|
||||
t.index ["user_id"], name: "index_invitations_on_user_id"
|
||||
end
|
||||
|
||||
create_table "settings", force: :cascade do |t|
|
||||
t.string "var", null: false
|
||||
t.text "value"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["var"], name: "index_settings_on_var", unique: true
|
||||
end
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "cn"
|
||||
t.string "ou"
|
||||
|
Loading…
x
Reference in New Issue
Block a user