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