2017-01-12 14:46:24 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-10 15:27:03 -04:00
|
|
|
module Admin
|
|
|
|
class SettingsController < BaseController
|
2017-05-04 12:12:44 -04:00
|
|
|
ADMIN_SETTINGS = %w(
|
|
|
|
site_contact_username
|
|
|
|
site_contact_email
|
|
|
|
site_title
|
|
|
|
site_description
|
|
|
|
site_extended_description
|
2017-07-04 09:19:24 -04:00
|
|
|
site_terms
|
2017-05-04 12:12:44 -04:00
|
|
|
open_registrations
|
|
|
|
closed_registrations_message
|
2017-07-11 09:27:59 -04:00
|
|
|
open_deletion
|
|
|
|
timeline_preview
|
2017-11-18 22:13:57 -05:00
|
|
|
show_staff_badge
|
2017-09-10 03:58:38 -04:00
|
|
|
bootstrap_timeline_accounts
|
2017-09-13 18:04:30 -04:00
|
|
|
thumbnail
|
2017-11-27 10:07:59 -05:00
|
|
|
min_invite_role
|
2017-12-29 13:52:04 -05:00
|
|
|
activity_api_enabled
|
|
|
|
peers_api_enabled
|
2017-07-11 09:27:59 -04:00
|
|
|
).freeze
|
|
|
|
|
|
|
|
BOOLEAN_SETTINGS = %w(
|
|
|
|
open_registrations
|
|
|
|
open_deletion
|
|
|
|
timeline_preview
|
2017-11-18 22:13:57 -05:00
|
|
|
show_staff_badge
|
2017-12-29 13:52:04 -05:00
|
|
|
activity_api_enabled
|
|
|
|
peers_api_enabled
|
2017-05-04 12:12:44 -04:00
|
|
|
).freeze
|
2017-04-20 11:18:09 -04:00
|
|
|
|
2017-09-13 18:04:30 -04:00
|
|
|
UPLOAD_SETTINGS = %w(
|
|
|
|
thumbnail
|
|
|
|
).freeze
|
|
|
|
|
2017-05-04 12:12:44 -04:00
|
|
|
def edit
|
2017-11-11 14:23:33 -05:00
|
|
|
authorize :settings, :show?
|
2017-07-11 21:24:04 -04:00
|
|
|
@admin_settings = Form::AdminSettings.new
|
2017-04-10 15:27:03 -04:00
|
|
|
end
|
2017-01-12 14:46:24 -05:00
|
|
|
|
2017-04-10 15:27:03 -04:00
|
|
|
def update
|
2017-11-11 14:23:33 -05:00
|
|
|
authorize :settings, :update?
|
|
|
|
|
2017-05-04 12:12:44 -04:00
|
|
|
settings_params.each do |key, value|
|
2017-09-13 18:04:30 -04:00
|
|
|
if UPLOAD_SETTINGS.include?(key)
|
|
|
|
upload = SiteUpload.where(var: key).first_or_initialize(var: key)
|
|
|
|
upload.update(file: value)
|
|
|
|
else
|
|
|
|
setting = Setting.where(var: key).first_or_initialize(var: key)
|
|
|
|
setting.update(value: value_for_update(key, value))
|
|
|
|
end
|
2017-04-10 15:27:03 -04:00
|
|
|
end
|
2017-05-04 12:12:44 -04:00
|
|
|
|
2017-07-10 08:04:05 -04:00
|
|
|
flash[:notice] = I18n.t('generic.changes_saved_msg')
|
2017-05-04 12:12:44 -04:00
|
|
|
redirect_to edit_admin_settings_path
|
2017-01-12 14:46:24 -05:00
|
|
|
end
|
|
|
|
|
2017-04-10 15:27:03 -04:00
|
|
|
private
|
2017-04-04 09:26:57 -04:00
|
|
|
|
2017-04-10 15:27:03 -04:00
|
|
|
def settings_params
|
2017-07-11 21:24:04 -04:00
|
|
|
params.require(:form_admin_settings).permit(ADMIN_SETTINGS)
|
2017-04-10 15:27:03 -04:00
|
|
|
end
|
2017-04-20 11:18:09 -04:00
|
|
|
|
2017-05-04 12:12:44 -04:00
|
|
|
def value_for_update(key, value)
|
|
|
|
if BOOLEAN_SETTINGS.include?(key)
|
2017-07-11 21:24:04 -04:00
|
|
|
value == '1'
|
2017-04-20 11:18:09 -04:00
|
|
|
else
|
2017-05-04 12:12:44 -04:00
|
|
|
value
|
2017-04-20 11:18:09 -04:00
|
|
|
end
|
|
|
|
end
|
2017-04-04 09:26:57 -04:00
|
|
|
end
|
2017-01-12 14:46:24 -05:00
|
|
|
end
|