Class: SystemConfigController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- BarkestCore::ApplicationControllerBase
- ApplicationController
- SystemConfigController
- Defined in:
- app/controllers/system_config_controller.rb
Overview
This controller makes it easy to edit the system configuration for email, authentication, and additional database connections.
Extend this class and add additional configuration items if needed. New configuration items should be added as paired methods.
# GET: /system_config/my_config_item
def show_my_config_item
...
end
# POST: /system_config/my_config_item
def update_my_config_item
...
end
If the config item requires an ID parameter, use the requires_id helper.
requires_id :my_config_item
Class Method Summary collapse
-
.get_config_items ⇒ Object
Gets all known configuration items.
Instance Method Summary collapse
-
#index ⇒ Object
GET /system_config.
-
#restart ⇒ Object
POST /system_config/restart.
-
#show_auth ⇒ Object
GET /system_config/auth.
-
#show_database ⇒ Object
GET /system_config/database/db_name.
-
#show_email ⇒ Object
GET /system_config/email.
-
#show_self_update ⇒ Object
GET /system_config/self_update.
-
#update_auth ⇒ Object
POST /system_config/auth.
-
#update_database ⇒ Object
POST /system_config/database/db_name.
-
#update_email ⇒ Object
POST /system_config/email.
-
#update_self_update ⇒ Object
POST /system_config/self_update.
Methods inherited from BarkestCore::ApplicationControllerBase
#authorize!, #show_denial_reason?
Methods included from BarkestCore::StatusHelper
#clear_system_status, #show_system_status, #status_button_label, #status_redirect_url
Methods included from BarkestCore::RecaptchaHelper
#add_recaptcha_challenge, #verify_recaptcha_challenge
Methods included from BarkestCore::SessionsHelper
#current_user, #current_user?, #forget, #log_in, #log_out, #logged_in?, #redirect_back_or, #remember, #store_location, #store_location_and_redirect_to, #system_admin?
Class Method Details
.get_config_items ⇒ Object
Gets all known configuration items.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'app/controllers/system_config_controller.rb', line 158 def self.get_config_items ret = {} rex = /^(show|update)_/ id_config_types.each { |item, provider| ret[item] = { require_id: true, id_provider: provider } } self.instance_methods.sort.each do |meth| meth = meth.to_s if rex.match(meth) action,_,item = meth.partition('_') action = action.to_sym item = item.to_sym ret[item] ||= {} ret[item][action] = true end end ret.keep_if{ |_,v| v[:show] && v[:update] } ret.each do |k,v| ret[k][:route_name] = :"system_config_#{k}" ret[k][:path_helper] = :"system_config_#{k}_path" ret[k][:url_helper] = :"system_config_#{k}_url" end ret end |
Instance Method Details
#index ⇒ Object
GET /system_config
47 48 49 |
# File 'app/controllers/system_config_controller.rb', line 47 def index end |
#restart ⇒ Object
POST /system_config/restart
53 54 55 56 |
# File 'app/controllers/system_config_controller.rb', line 53 def restart BarkestCore.request_restart redirect_to system_config_url end |
#show_auth ⇒ Object
GET /system_config/auth
60 61 62 |
# File 'app/controllers/system_config_controller.rb', line 60 def show_auth @auth_params = BarkestCore::AuthConfig.new(BarkestCore.auth_config) end |
#show_database ⇒ Object
GET /system_config/database/db_name
110 111 112 |
# File 'app/controllers/system_config_controller.rb', line 110 def show_database @db_config = BarkestCore::DatabaseConfig.new(@db_id, BarkestCore.db_config(@db_id, nil, false)) end |
#show_email ⇒ Object
GET /system_config/email
84 85 86 |
# File 'app/controllers/system_config_controller.rb', line 84 def show_email @email_config = BarkestCore::EmailConfig.new(BarkestCore.email_config) end |
#show_self_update ⇒ Object
GET /system_config/self_update
134 135 136 |
# File 'app/controllers/system_config_controller.rb', line 134 def show_self_update @config = BarkestCore::SelfUpdateConfig.load end |
#update_auth ⇒ Object
POST /system_config/auth
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/system_config_controller.rb', line 66 def update_auth @auth_params = get_auth_params if @auth_params.valid? if @auth_params.save flash[:safe_success] = 'The configuration has been saved.<br>The app will need to be restarted to use the new configuration.' redirect_to system_config_url else flash.now[:danger] = 'Failed to save the configuration.' render 'show_auth' end else render 'show_auth' end end |
#update_database ⇒ Object
POST /system_config/database/db_name
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/controllers/system_config_controller.rb', line 116 def update_database @db_config = get_db_params if @db_config.valid? if @db_config.save flash[:safe_success] = 'The configuration has been saved.<br>The app will need to be restarted to use the new configuration.' redirect_to system_config_url else flash.now[:danger] = 'Failed to save the configuration.' render 'show_database' end else render 'show_database' end end |
#update_email ⇒ Object
POST /system_config/email
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/system_config_controller.rb', line 90 def update_email @email_config = get_email_params if @email_config.valid? if @email_config.save flash[:safe_success] = 'The configuration has been saved.<br>The app will need to be restarted to use the new configuration.' redirect_to system_config_url else flash.now[:danger] = 'Failed to save the configuration.' render 'show_email' end else render 'show_email' end end |
#update_self_update ⇒ Object
POST /system_config/self_update
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'app/controllers/system_config_controller.rb', line 140 def update_self_update @config = get_self_update_params if @config.valid? if @config.save flash[:success] = 'The configuration has been saved.' redirect_to system_config_url else flash[:danger] = 'Failed to save the configuration.' render 'show_self_update' end else render 'show_self_update' end end |