diff options
Diffstat (limited to 'app/models/form')
-rw-r--r-- | app/models/form/admin_settings.rb | 29 | ||||
-rw-r--r-- | app/models/form/domain_block_batch.rb | 35 |
2 files changed, 62 insertions, 2 deletions
diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index 431d33bcd..b53a82db2 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -14,20 +14,28 @@ class Form::AdminSettings closed_registrations_message timeline_preview bootstrap_timeline_accounts - theme + flavour + skin activity_api_enabled peers_api_enabled preview_sensitive_media custom_css profile_directory + hide_followers_count + flavour_and_skin thumbnail mascot + show_reblogs_in_public_timelines + show_replies_in_public_timelines trends trendable_by_default + trending_status_cw show_domain_blocks show_domain_blocks_rationale noindex + outgoing_spoilers require_invite_text + captcha_enabled media_cache_retention_period content_cache_retention_period backups_retention_period @@ -45,10 +53,15 @@ class Form::AdminSettings peers_api_enabled preview_sensitive_media profile_directory + hide_followers_count + show_reblogs_in_public_timelines + show_replies_in_public_timelines trends trendable_by_default + trending_status_cw noindex require_invite_text + captcha_enabled ).freeze UPLOAD_KEYS = %i( @@ -56,6 +69,10 @@ class Form::AdminSettings mascot ).freeze + PSEUDO_KEYS = %i( + flavour_and_skin + ).freeze + attr_accessor(*KEYS) validates :registrations_mode, inclusion: { in: %w(open approved none) }, if: -> { defined?(@registrations_mode) } @@ -94,7 +111,7 @@ class Form::AdminSettings return false unless valid? KEYS.each do |key| - next unless instance_variable_defined?("@#{key}") + next if PSEUDO_KEYS.include?(key) || !instance_variable_defined?("@#{key}") if UPLOAD_KEYS.include?(key) public_send(key).save @@ -105,6 +122,14 @@ class Form::AdminSettings end end + def flavour_and_skin + "#{Setting.flavour}/#{Setting.skin}" + end + + def flavour_and_skin=(value) + @flavour, @skin = value.split('/', 2) + end + private def typecast_value(key, value) diff --git a/app/models/form/domain_block_batch.rb b/app/models/form/domain_block_batch.rb new file mode 100644 index 000000000..39012df51 --- /dev/null +++ b/app/models/form/domain_block_batch.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class Form::DomainBlockBatch + include ActiveModel::Model + include Authorization + include AccountableConcern + + attr_accessor :domain_blocks_attributes, :action, :current_account + + def save + case action + when 'save' + save! + end + end + + private + + def domain_blocks + @domain_blocks ||= domain_blocks_attributes.values.filter_map do |attributes| + DomainBlock.new(attributes.without('enabled')) if ActiveModel::Type::Boolean.new.cast(attributes['enabled']) + end + end + + def save! + domain_blocks.each do |domain_block| + authorize(domain_block, :create?) + next if DomainBlock.rule_for(domain_block.domain).present? + + domain_block.save! + DomainBlockWorker.perform_async(domain_block.id) + log_action :create, domain_block + end + end +end |