2017-01-13 06:46:24 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-11 05:27:03 +10:00
|
|
|
module Admin
|
|
|
|
class SettingsController < BaseController
|
2017-05-05 02:12:44 +10:00
|
|
|
ADMIN_SETTINGS = %w(
|
|
|
|
site_contact_username
|
|
|
|
site_contact_email
|
|
|
|
site_title
|
|
|
|
site_description
|
|
|
|
site_extended_description
|
2017-07-04 23:19:24 +10:00
|
|
|
site_terms
|
2017-05-05 02:12:44 +10:00
|
|
|
open_registrations
|
|
|
|
closed_registrations_message
|
|
|
|
).freeze
|
2017-04-21 01:18:09 +10:00
|
|
|
BOOLEAN_SETTINGS = %w(open_registrations).freeze
|
|
|
|
|
2017-05-05 02:12:44 +10:00
|
|
|
def edit
|
2017-04-11 05:27:03 +10:00
|
|
|
@settings = Setting.all_as_records
|
|
|
|
end
|
2017-01-13 06:46:24 +11:00
|
|
|
|
2017-04-11 05:27:03 +10:00
|
|
|
def update
|
2017-05-05 02:12:44 +10:00
|
|
|
settings_params.each do |key, value|
|
|
|
|
setting = Setting.where(var: key).first_or_initialize(var: key)
|
|
|
|
setting.update(value: value_for_update(key, value))
|
2017-04-11 05:27:03 +10:00
|
|
|
end
|
2017-05-05 02:12:44 +10:00
|
|
|
|
|
|
|
flash[:notice] = 'Success!'
|
|
|
|
redirect_to edit_admin_settings_path
|
2017-01-13 06:46:24 +11:00
|
|
|
end
|
|
|
|
|
2017-04-11 05:27:03 +10:00
|
|
|
private
|
2017-04-04 23:26:57 +10:00
|
|
|
|
2017-04-11 05:27:03 +10:00
|
|
|
def settings_params
|
2017-05-05 02:12:44 +10:00
|
|
|
params.permit(ADMIN_SETTINGS)
|
2017-04-11 05:27:03 +10:00
|
|
|
end
|
2017-04-21 01:18:09 +10:00
|
|
|
|
2017-05-05 02:12:44 +10:00
|
|
|
def value_for_update(key, value)
|
|
|
|
if BOOLEAN_SETTINGS.include?(key)
|
|
|
|
value == 'true'
|
2017-04-21 01:18:09 +10:00
|
|
|
else
|
2017-05-05 02:12:44 +10:00
|
|
|
value
|
2017-04-21 01:18:09 +10:00
|
|
|
end
|
|
|
|
end
|
2017-04-04 23:26:57 +10:00
|
|
|
end
|
2017-01-13 06:46:24 +11:00
|
|
|
end
|