2017-01-12 19:46:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-10 20:27:03 +01:00
|
|
|
module Admin
|
|
|
|
class SettingsController < BaseController
|
2017-05-04 17:12:44 +01:00
|
|
|
ADMIN_SETTINGS = %w(
|
|
|
|
site_contact_username
|
|
|
|
site_contact_email
|
|
|
|
site_title
|
2018-07-31 17:59:34 +01:00
|
|
|
site_short_description
|
2017-05-04 17:12:44 +01:00
|
|
|
site_description
|
|
|
|
site_extended_description
|
2017-07-04 14:19:24 +01:00
|
|
|
site_terms
|
2019-03-14 04:28:30 +00:00
|
|
|
registrations_mode
|
2017-05-04 17:12:44 +01:00
|
|
|
closed_registrations_message
|
2017-07-11 14:27:59 +01:00
|
|
|
open_deletion
|
|
|
|
timeline_preview
|
2017-11-19 03:13:57 +00:00
|
|
|
show_staff_badge
|
2017-09-10 08:58:38 +01:00
|
|
|
bootstrap_timeline_accounts
|
2018-08-23 13:17:35 +01:00
|
|
|
theme
|
2017-09-13 23:04:30 +01:00
|
|
|
thumbnail
|
2018-02-22 00:03:48 +00:00
|
|
|
hero
|
2018-10-07 23:20:45 +01:00
|
|
|
mascot
|
2017-11-27 15:07:59 +00:00
|
|
|
min_invite_role
|
2017-12-29 18:52:04 +00:00
|
|
|
activity_api_enabled
|
|
|
|
peers_api_enabled
|
2018-02-04 05:00:10 +00:00
|
|
|
show_known_fediverse_at_about_page
|
2018-07-06 01:15:56 +01:00
|
|
|
preview_sensitive_media
|
2018-08-24 03:33:27 +01:00
|
|
|
custom_css
|
2018-12-11 18:18:29 +00:00
|
|
|
profile_directory
|
2017-07-11 14:27:59 +01:00
|
|
|
).freeze
|
|
|
|
|
|
|
|
BOOLEAN_SETTINGS = %w(
|
|
|
|
open_deletion
|
|
|
|
timeline_preview
|
2017-11-19 03:13:57 +00:00
|
|
|
show_staff_badge
|
2017-12-29 18:52:04 +00:00
|
|
|
activity_api_enabled
|
|
|
|
peers_api_enabled
|
2018-02-04 05:00:10 +00:00
|
|
|
show_known_fediverse_at_about_page
|
2018-07-06 01:15:56 +01:00
|
|
|
preview_sensitive_media
|
2018-12-11 18:18:29 +00:00
|
|
|
profile_directory
|
2017-05-04 17:12:44 +01:00
|
|
|
).freeze
|
2017-04-20 16:18:09 +01:00
|
|
|
|
2017-09-13 23:04:30 +01:00
|
|
|
UPLOAD_SETTINGS = %w(
|
|
|
|
thumbnail
|
2018-02-22 00:03:48 +00:00
|
|
|
hero
|
2018-10-07 23:20:45 +01:00
|
|
|
mascot
|
2017-09-13 23:04:30 +01:00
|
|
|
).freeze
|
|
|
|
|
2017-05-04 17:12:44 +01:00
|
|
|
def edit
|
2017-11-11 19:23:33 +00:00
|
|
|
authorize :settings, :show?
|
2017-07-12 02:24:04 +01:00
|
|
|
@admin_settings = Form::AdminSettings.new
|
2017-04-10 20:27:03 +01:00
|
|
|
end
|
2017-01-12 19:46:24 +00:00
|
|
|
|
2017-04-10 20:27:03 +01:00
|
|
|
def update
|
2017-11-11 19:23:33 +00:00
|
|
|
authorize :settings, :update?
|
|
|
|
|
2017-05-04 17:12:44 +01:00
|
|
|
settings_params.each do |key, value|
|
2017-09-13 23:04:30 +01: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 20:27:03 +01:00
|
|
|
end
|
2017-05-04 17:12:44 +01:00
|
|
|
|
2017-07-10 13:04:05 +01:00
|
|
|
flash[:notice] = I18n.t('generic.changes_saved_msg')
|
2017-05-04 17:12:44 +01:00
|
|
|
redirect_to edit_admin_settings_path
|
2017-01-12 19:46:24 +00:00
|
|
|
end
|
|
|
|
|
2017-04-10 20:27:03 +01:00
|
|
|
private
|
2017-04-04 14:26:57 +01:00
|
|
|
|
2017-04-10 20:27:03 +01:00
|
|
|
def settings_params
|
2017-07-12 02:24:04 +01:00
|
|
|
params.require(:form_admin_settings).permit(ADMIN_SETTINGS)
|
2017-04-10 20:27:03 +01:00
|
|
|
end
|
2017-04-20 16:18:09 +01:00
|
|
|
|
2017-05-04 17:12:44 +01:00
|
|
|
def value_for_update(key, value)
|
|
|
|
if BOOLEAN_SETTINGS.include?(key)
|
2017-07-12 02:24:04 +01:00
|
|
|
value == '1'
|
2017-04-20 16:18:09 +01:00
|
|
|
else
|
2017-05-04 17:12:44 +01:00
|
|
|
value
|
2017-04-20 16:18:09 +01:00
|
|
|
end
|
|
|
|
end
|
2017-04-04 14:26:57 +01:00
|
|
|
end
|
2017-01-12 19:46:24 +00:00
|
|
|
end
|