* Change: #591 ホワイトリストのドメイン一覧の保存先・画面変更 * Update account_batch.rb * 表示まわりを改善 * Update dangerous.rake
This commit is contained in:
parent
8c399cefce
commit
ff2860d0df
18 changed files with 211 additions and 49 deletions
|
@ -98,10 +98,10 @@ class Form::AccountBatch
|
|||
|
||||
def approve_remote_domain!
|
||||
domains = accounts.group_by(&:domain).pluck(0)
|
||||
if (Setting.permit_new_account_domains || []).compact_blank.present?
|
||||
list = ((Setting.permit_new_account_domains || []) + domains).compact_blank.uniq.join("\n")
|
||||
Form::AdminSettings.new(permit_new_account_domains: list).save
|
||||
(domains - SpecifiedDomain.where(domain: domains, table: 0).pluck(:domain)).each do |domain|
|
||||
SpecifiedDomain.create!(domain: domain, table: 0)
|
||||
end
|
||||
|
||||
Account.where(domain: domains, remote_pending: true).find_each do |account|
|
||||
approve_remote_account(account)
|
||||
end
|
||||
|
|
|
@ -61,7 +61,6 @@ class Form::AdminSettings
|
|||
unlocked_friend
|
||||
enable_local_timeline
|
||||
emoji_reaction_disallow_domains
|
||||
permit_new_account_domains
|
||||
block_unfollow_account_mention
|
||||
hold_remote_new_accounts
|
||||
).freeze
|
||||
|
@ -121,7 +120,6 @@ class Form::AdminSettings
|
|||
|
||||
STRING_ARRAY_KEYS = %i(
|
||||
emoji_reaction_disallow_domains
|
||||
permit_new_account_domains
|
||||
).freeze
|
||||
|
||||
attr_accessor(*KEYS)
|
||||
|
|
78
app/models/specified_domain.rb
Normal file
78
app/models/specified_domain.rb
Normal file
|
@ -0,0 +1,78 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: specified_domains
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# domain :string not null
|
||||
# table :integer default(0), not null
|
||||
# options :jsonb not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
class SpecifiedDomain < ApplicationRecord
|
||||
attr_accessor :domains
|
||||
|
||||
validates :domain, uniqueness: { scope: :table }
|
||||
after_commit :invalidate_cache!
|
||||
|
||||
scope :white_list_domains, -> { where(table: 0) }
|
||||
|
||||
class << self
|
||||
def white_list_domain_caches
|
||||
Rails.cache.fetch('specified_domains:white_list') { white_list_domains.to_a }
|
||||
end
|
||||
|
||||
def save_from_hashes(rows, type, caches)
|
||||
unmatched = caches
|
||||
matched = []
|
||||
|
||||
SpecifiedDomain.transaction do
|
||||
rows.filter { |item| item[:domain].present? }.each do |item|
|
||||
exists = unmatched.find { |i| i.domain == item[:domain] }
|
||||
|
||||
if exists.present?
|
||||
unmatched.delete(exists)
|
||||
matched << exists
|
||||
|
||||
next unless item.key?(:options) && item[:options] == exists.options
|
||||
|
||||
exists.update!(options: item[:options])
|
||||
elsif matched.none? { |i| i.domain == item[:domain] }
|
||||
SpecifiedDomain.create!(
|
||||
domain: item[:domain],
|
||||
table: type,
|
||||
options: item[:options] || {}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
SpecifiedDomain.destroy(unmatched.map(&:id))
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def save_from_raws(rows, type, caches)
|
||||
hashes = (rows['domains'] || []).map do |domain|
|
||||
{
|
||||
domain: domain,
|
||||
type: type,
|
||||
}
|
||||
end
|
||||
|
||||
save_from_hashes(hashes, type, caches)
|
||||
end
|
||||
|
||||
def save_from_raws_as_white_list(rows)
|
||||
save_from_raws(rows, 0, white_list_domain_caches)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def invalidate_cache!
|
||||
Rails.cache.delete('specified_domains:white_list')
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue