allow overriding visibility/sensitivity by domain

staging
multiple creatures 2019-02-12 06:56:36 +00:00
parent d6738df083
commit 1d5da39902
1 changed files with 11 additions and 0 deletions

View File

@ -37,6 +37,8 @@ class Status < ApplicationRecord
LOCAL_DOMAINS = ENV.fetch('LOCAL_DOMAINS', '').chomp.split(/\.?\s+/).freeze
LOCAL_URIS = LOCAL_DOMAINS.map { |domain| "https://#{domain}/%" }.freeze
FORCE_SENSITIVE = ENV.fetch('FORCE_SENSITIVE', '').chomp.split(/\.?\s+/).freeze
FORCE_UNLISTED = ENV.fetch('FORCE_UNLISTED', '').chomp.split(/\.?\s+/).freeze
# If `override_timestamps` is set at creation time, Snowflake ID creation
# will be based on current time instead of `created_at`
@ -293,6 +295,8 @@ class Status < ApplicationRecord
after_create :set_poll_id
after_find :limit_visibility
class << self
def selectable_visibilities
visibilities.keys - %w(direct limited)
@ -547,6 +551,13 @@ class Status < ApplicationRecord
self.sensitive = false if sensitive.nil?
end
def limit_visibility
return unless has_attribute?(:uri) && !uri.nil?
domain = Addressable::URI.parse(uri).host
self.sensitive = true if domain.in?(FORCE_SENSITIVE)
self.visibility = :unlisted if domain.in?(FORCE_UNLISTED)
end
def set_locality
if account.domain.nil? && !attribute_changed?(:local_only)
self.local_only = marked_local_only?