0
0
Fork 0

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:
Eugen Rochko 2020-12-18 08:30:41 +01:00 committed by GitHub
parent b1feb47055
commit 8a95867693
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 48 additions and 4 deletions

View file

@ -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