Add option to obfuscate domain name in public list of domain blocks (#15355)
- Replace the middle of the domain with * characters (except for periods) - Add SHA-256 digest of the domain name in tooltip
This commit is contained in:
parent
b1feb47055
commit
8a95867693
8 changed files with 48 additions and 4 deletions
|
@ -12,6 +12,7 @@
|
|||
# reject_reports :boolean default(FALSE), not null
|
||||
# private_comment :text
|
||||
# public_comment :text
|
||||
# obfuscate :boolean default(FALSE), not null
|
||||
#
|
||||
|
||||
class DomainBlock < ApplicationRecord
|
||||
|
@ -73,4 +74,23 @@ 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue