end
def update_params
- params.require(:domain_block).permit(:severity, :reject_media, :reject_reports, :private_comment, :public_comment)
+ params.require(:domain_block).permit(:severity, :reject_media, :reject_reports, :private_comment, :public_comment, :obfuscate)
end
def resource_params
- params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_reports, :private_comment, :public_comment)
+ params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_reports, :private_comment, :public_comment, :obfuscate)
end
end
end
# reject_reports :boolean default(FALSE), not null
# private_comment :text
# public_comment :text
+# obfuscate :boolean default(FALSE), not null
#
class DomainBlock < ApplicationRecord
scope = suspend? ? accounts.where(suspended_at: created_at) : accounts.where(silenced_at: created_at)
scope.count
end
+
+ def public_domain
+ return domain unless obfuscate?
+
+ length = domain.size
+ visible_ratio = length / 4
+
+ domain.chars.map.with_index do |chr, i|
+ if i > visible_ratio && i < length - visible_ratio && chr != '.'
+ '*'
+ else
+ chr
+ end
+ end.join
+ end
+
+ def domain_digest
+ Digest::SHA256.hexdigest(domain)
+ end
end
- domain_blocks.each do |domain_block|
%tr
%td.nowrap
- %span{ title: domain_block.domain }= domain_block.domain
+ %span{ title: "SHA-256: #{domain_block.domain_digest}" }= domain_block.public_domain
%td
= domain_block.public_comment if display_blocks_rationale?
.fields-group
= f.input :reject_reports, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_reports'), hint: I18n.t('admin.domain_blocks.reject_reports_hint')
+ .fields-group
+ = f.input :obfuscate, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.obfuscate'), hint: I18n.t('admin.domain_blocks.obfuscate_hint')
+
.field-group
= f.input :private_comment, wrapper: :with_label, label: I18n.t('admin.domain_blocks.private_comment'), hint: t('admin.domain_blocks.private_comment_hint'), rows: 6
.fields-group
= f.input :reject_reports, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_reports'), hint: I18n.t('admin.domain_blocks.reject_reports_hint')
+ .fields-group
+ = f.input :obfuscate, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.obfuscate'), hint: I18n.t('admin.domain_blocks.obfuscate_hint')
+
.field-group
= f.input :private_comment, wrapper: :with_label, label: I18n.t('admin.domain_blocks.private_comment'), hint: t('admin.domain_blocks.private_comment_hint'), rows: 6
silence: Silence
suspend: Suspend
title: New domain block
+ obfuscate: Obfuscate domain name
+ obfuscate_hint: Partially obfuscate the domain name in the list if advertising the list of domain limitations is enabled
private_comment: Private comment
private_comment_hint: Comment about this domain limitation for internal use by the moderators.
public_comment: Public comment
--- /dev/null
+require Rails.root.join('lib', 'mastodon', 'migration_helpers')
+
+class AddObfuscateToDomainBlocks < ActiveRecord::Migration[5.2]
+ include Mastodon::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ def up
+ safety_assured { add_column_with_default :domain_blocks, :obfuscate, :boolean, default: false, allow_null: false }
+ end
+
+ def down
+ remove_column :domain_blocks, :obfuscate
+ end
+end
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2020_12_06_004238) do
+ActiveRecord::Schema.define(version: 2020_12_18_054746) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
t.boolean "reject_reports", default: false, null: false
t.text "private_comment"
t.text "public_comment"
+ t.boolean "obfuscate", default: false, null: false
t.index ["domain"], name: "index_domain_blocks_on_domain", unique: true
end