mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 08:19:53 +01:00
move site config from initialiser to own module for potential improvements in how to access common configs when needed ... way better than using .dig
by hand everywhere i'd say
This commit is contained in:
parent
076f71860f
commit
ca98b9dd7f
6 changed files with 36 additions and 26 deletions
|
@ -35,6 +35,6 @@ class User::RegistrationsController < Devise::RegistrationsController
|
|||
end
|
||||
|
||||
def redirect_if_registrations_disabled!
|
||||
redirect_to root_path unless APP_CONFIG.dig(:features, :registration, :enabled)
|
||||
redirect_to root_path unless Retrospring::Config.registrations_enabled?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
= render "layouts/messages"
|
||||
%h1= APP_CONFIG["site_name"]
|
||||
%p= t(".subtitle")
|
||||
- if APP_CONFIG.dig(:features, :registration, :enabled)
|
||||
- if Retrospring::Config.registrations_enabled?
|
||||
%p
|
||||
%a.btn.btn-outline-light.btn-lg{ href: url_for(new_user_registration_path) }
|
||||
= t(".register")
|
||||
|
|
|
@ -40,11 +40,11 @@
|
|||
%input{ name: "qb-to", type: "hidden", value: user.id }/
|
||||
%button.btn.btn-primary{ name: "qb-ask",
|
||||
type: :button,
|
||||
data: { loading_text: t(".load"), promote: user_signed_in? || !user_signed_in? && !APP_CONFIG.dig(:features, :registration, :enabled) ? "false" : "true", "character-count-target": "action" } }
|
||||
data: { loading_text: t(".load"), promote: user_signed_in? || !user_signed_in? && !Retrospring::Config.registrations_enabled ? "false" : "true", "character-count-target": "action" } }
|
||||
Ask
|
||||
- unless user_signed_in?
|
||||
- if user.privacy_allow_anonymous_questions?
|
||||
- if APP_CONFIG.dig(:features, :registration, :enabled)
|
||||
- if Retrospring::Config.registrations_enabled?
|
||||
.d-none#question-box-promote
|
||||
.row
|
||||
.col-12.text-center
|
||||
|
@ -61,7 +61,7 @@
|
|||
%small= t(".promote.join", app_title: APP_CONFIG["site_name"])
|
||||
- else
|
||||
.text-center
|
||||
- if APP_CONFIG.dig(:features, :registration, :enabled)
|
||||
- if Retrospring::Config.registrations_enabled?
|
||||
%strong= t(".status.non_anonymous_html", sign_in: link_to(t("voc.login"), new_user_session_path), sign_up: link_to(t("voc.register"), new_user_registration_path))
|
||||
- else
|
||||
%strong= t(".status.non_anonymous_no_registration_html", sign_in: link_to(t("voc.login"), new_user_session_path))
|
||||
|
|
|
@ -14,5 +14,5 @@
|
|||
.collapse.navbar-collapse#j2-main-navbar-collapse
|
||||
%ul.nav.navbar-nav.ms-auto
|
||||
= nav_entry t("voc.login"), new_user_session_path
|
||||
- if APP_CONFIG.dig(:features, :registration, :enabled)
|
||||
- if Retrospring::Config.registrations_enabled?
|
||||
= nav_entry t("voc.register"), new_user_registration_path
|
||||
|
|
|
@ -1,23 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Auxiliary config
|
||||
|
||||
APP_CONFIG = {}.with_indifferent_access
|
||||
|
||||
# load yml config if it's present
|
||||
justask_yml_path = Rails.root.join("config/justask.yml")
|
||||
APP_CONFIG.merge!(YAML.load_file(justask_yml_path)) if File.exist?(justask_yml_path)
|
||||
|
||||
# load config from ENV where possible
|
||||
env_config = {
|
||||
# The site name, shown everywhere
|
||||
site_name: ENV.fetch("SITE_NAME", nil),
|
||||
|
||||
hostname: ENV.fetch("HOSTNAME", nil),
|
||||
}.compact
|
||||
APP_CONFIG.merge!(env_config)
|
||||
|
||||
# Update rails config for mail
|
||||
Rails.application.config.action_mailer.default_url_options = {
|
||||
host: APP_CONFIG["hostname"],
|
||||
}
|
||||
APP_CONFIG = Retrospring::Config.config_hash
|
||||
|
|
29
lib/retrospring/config.rb
Normal file
29
lib/retrospring/config.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Retrospring
|
||||
module Config
|
||||
module_function
|
||||
|
||||
def config_hash = {}.with_indifferent_access.tap do |hash|
|
||||
# load yml config if it's present
|
||||
justask_yml_path = Rails.root.join("config/justask.yml")
|
||||
hash.merge!(YAML.load_file(justask_yml_path)) if File.exist?(justask_yml_path)
|
||||
|
||||
# load config from ENV where possible
|
||||
env_config = {
|
||||
# The site name, shown everywhere
|
||||
site_name: ENV.fetch("SITE_NAME", nil),
|
||||
|
||||
hostname: ENV.fetch("HOSTNAME", nil),
|
||||
}.compact
|
||||
hash.merge!(env_config)
|
||||
|
||||
# Update rails config for mail
|
||||
Rails.application.config.action_mailer.default_url_options = {
|
||||
host: hash["hostname"],
|
||||
}
|
||||
end
|
||||
|
||||
def registrations_enabled? = APP_CONFIG.dig(:features, :registration, :enabled)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue