docbrown/app/controllers/concerns/verify_setup_completed.rb
Michael Kohl 6dfabd578f
Rename SiteConfig to Settings::General (#13573)
* Rename SiteConfig

* More renaming

* Update spec

* Update mandatory settings mapping

* More renaming

* e2e test fixes

* You have a rename, and you have a rename

* Spec fix

* More changes

* Temporarily disable specs

* After-merge update

* Undo rename for migration

* undo rename of DUS

* Fix DUS

* Fix merge problem

* Remove redundant DUS

* Fix specs

* Remove unused code

* Change wrong class name

* More cleanup

* Re-add missing values to constant

* Fix constant

* Fix spec

* Remove obsolete fields

* Add accidentally removed field

* Update spec

* Move methods from Settings::General to ForemInstance

* Remove unneeded model

* Change mentions of 'site config'
2021-05-21 14:45:37 +02:00

44 lines
1.4 KiB
Ruby

# Included in the ApplicationController to assist with creator onboarding
module VerifySetupCompleted
extend ActiveSupport::Concern
module_function
included do
# rubocop:disable Rails/LexicallyScopedActionFilter
before_action :verify_setup_completed, only: %i[index new edit show]
# rubocop:enable Rails/LexicallyScopedActionFilter
end
def setup_completed?
missing_configs.empty?
end
def missing_configs
@missing_configs ||= Settings::Mandatory.missing
end
private
def missing_configs_text
display_missing = missing_configs.size > 3 ? missing_configs.first(3) + ["others"] : missing_configs
display_missing.map { |config| config.to_s.tr("_", " ") }.to_sentence
end
def verify_setup_completed
# This is the only flash in our application layout, don't override it if
# there's already another message.
return if flash[:global_notice].present?
return if config_path? || setup_completed? || Settings::General.waiting_on_first_user
link = helpers.tag.a("the configuration page", href: admin_config_path, data: { "no-instant" => true })
flash[:global_notice] = helpers.safe_join(["Setup not completed yet, missing ",
missing_configs_text,
". Please visit ", link, "."])
end
def config_path?
request.env["PATH_INFO"] == admin_config_path
end
end