0
0
Fork 0

Migrate from ledermann/rails-settings to rails-settings-cached which allows global settings

with YAML-defined defaults. Add admin page for editing global settings. Add "site_description"
setting that would show as a paragraph on the frontpage
This commit is contained in:
Eugen Rochko 2017-01-12 20:46:24 +01:00
parent babc6a1528
commit b11fdc3ae3
20 changed files with 188 additions and 34 deletions

31
app/models/setting.rb Normal file
View file

@ -0,0 +1,31 @@
# frozen_string_literal: true
class Setting < RailsSettings::Base
source Rails.root.join('config/settings.yml')
namespace Rails.env
def to_param
var
end
class << self
def all_as_records
vars = thing_scoped
records = vars.map { |r| [r.var, r] }.to_h
default_settings.each do |key, default_value|
next if records.key?(key) || default_value.is_a?(Hash)
records[key] = Setting.new(var: key, value: default_value)
end
records
end
private
def default_settings
return {} unless RailsSettings::Default.enabled?
RailsSettings::Default.instance
end
end
end

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
class User < ApplicationRecord
include RailsSettings::Extend
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable
belongs_to :account, inverse_of: :user
@ -14,11 +16,6 @@ class User < ApplicationRecord
scope :recent, -> { order('id desc') }
scope :admins, -> { where(admin: true) }
has_settings do |s|
s.key :notification_emails, defaults: { follow: false, reblog: false, favourite: false, mention: false, follow_request: true }
s.key :interactions, defaults: { must_be_follower: false, must_be_following: false }
end
def send_devise_notification(notification, *args)
devise_mailer.send(notification, self, *args).deliver_later
end