diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 26 | ||||
-rw-r--r-- | app/models/account_warning.rb | 2 | ||||
-rw-r--r-- | app/models/admin/account_action.rb | 18 | ||||
-rw-r--r-- | app/models/domain_block.rb | 26 | ||||
-rw-r--r-- | app/models/status.rb | 5 | ||||
-rw-r--r-- | app/models/user.rb | 4 |
6 files changed, 65 insertions, 16 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index 6e7cf3773..5f88a951f 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -48,6 +48,9 @@ # vars :jsonb not null # replies :boolean default(TRUE), not null # unlisted :boolean default(FALSE), not null +# force_unlisted :boolean default(FALSE), not null +# force_sensitive :boolean default(FALSE), not null +# adults_only :boolean default(FALSE), not null # class Account < ApplicationRecord @@ -120,6 +123,7 @@ class Account < ApplicationRecord :moderator?, :staff?, :locale, + :default_sensitive?, :hides_network?, :shows_application?, :always_local?, @@ -185,6 +189,28 @@ class Account < ApplicationRecord ResolveAccountService.new.call(acct) end + def force_unlisted! + transaction do + update!(force_unlisted: true) + Status.where(account_id: id, visibility: :public).in_batches.update_all(visibility: :unlisted) + end + end + + def force_sensitive! + transaction do + update!(force_sensitive: true) + Status.where(account_id: id, sensitive: false).in_batches.update_all(sensitive: true) + end + end + + def allow_public! + update!(force_unlisted: false) + end + + def allow_nonsensitive! + update!(force_sensitive: false) + end + def silenced? silenced_at.present? end diff --git a/app/models/account_warning.rb b/app/models/account_warning.rb index 157e6c04d..4e06cf3d0 100644 --- a/app/models/account_warning.rb +++ b/app/models/account_warning.rb @@ -13,7 +13,7 @@ # class AccountWarning < ApplicationRecord - enum action: %i(none disable silence suspend), _suffix: :action + enum action: %i(none disable force_sensitive force_unlisted silence suspend), _suffix: :action belongs_to :account, inverse_of: :account_warnings belongs_to :target_account, class_name: 'Account', inverse_of: :targeted_account_warnings diff --git a/app/models/admin/account_action.rb b/app/models/admin/account_action.rb index 84c3f880d..1ed464423 100644 --- a/app/models/admin/account_action.rb +++ b/app/models/admin/account_action.rb @@ -8,6 +8,8 @@ class Admin::AccountAction TYPES = %w( none disable + force_sensitive + force_unlisted silence suspend ).freeze @@ -56,6 +58,10 @@ class Admin::AccountAction case type when 'disable' handle_disable! + when 'force_sensitive' + handle_force_sensitive! + when 'force_unlisted' + handle_force_unlisted! when 'silence' handle_silence! when 'suspend' @@ -97,6 +103,18 @@ class Admin::AccountAction target_account.user&.disable! end + def handle_force_sensitive! + authorize(target_account, :force_sensitive?) + log_action(:force_sensitive, target_account.user) + target_account.force_sensitive! + end + + def handle_force_unlisted! + authorize(target_account, :force_unlisted?) + log_action(:force_unlisted, target_account.user) + target_account.force_unlisted! + end + def handle_silence! authorize(target_account, :silence?) log_action(:silence, target_account) diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb index 84c08c158..c62ca3d8c 100644 --- a/app/models/domain_block.rb +++ b/app/models/domain_block.rb @@ -3,19 +3,20 @@ # # Table name: domain_blocks # -# id :bigint(8) not null, primary key -# domain :string default(""), not null -# created_at :datetime not null -# updated_at :datetime not null -# severity :integer default("silence") -# reject_media :boolean default(FALSE), not null -# reject_reports :boolean default(FALSE), not null +# id :bigint(8) not null, primary key +# domain :string default(""), not null +# created_at :datetime not null +# updated_at :datetime not null +# severity :integer default("noop") +# reject_media :boolean default(FALSE), not null +# reject_reports :boolean default(FALSE), not null +# force_sensitive :boolean default(FALSE), not null # class DomainBlock < ApplicationRecord include DomainNormalizable - enum severity: [:silence, :suspend, :noop] + enum severity: [:noop, :force_unlisted, :silence, :suspend] validates :domain, presence: true, uniqueness: true @@ -28,10 +29,15 @@ class DomainBlock < ApplicationRecord where(domain: domain, severity: :suspend).exists? end + def self.force_unlisted?(domain) + where(domain: domain, severity: :force_unlisted).exists? + end + def stricter_than?(other_block) return true if suspend? - return false if other_block.suspend? && (silence? || noop?) - return false if other_block.silence? && noop? + return false if other_block.suspend? && !suspend? + return false if other_block.silence? && (noop? || force_unlisted?) + return false if other_block.force_unlisted? && noop? (reject_media || !other_block.reject_media) && (reject_reports || !other_block.reject_reports) end diff --git a/app/models/status.rb b/app/models/status.rb index 0b26e4605..3c98369b1 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -40,8 +40,6 @@ class Status < ApplicationRecord # match both with and without U+FE0F (the emoji variation selector) LOCAL_ONLY_TOKENS = /(?:#!|\u{1f441}\ufe0f?)\u200b?\z/ - 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` @@ -561,9 +559,6 @@ class Status < ApplicationRecord def set_visibility self.visibility = reblog.visibility if reblog? && visibility.nil? self.visibility = (account.locked? ? :private : :public) if visibility.nil? - self.visibility = :unlisted if visibility == :public && account.domain.in?(FORCE_UNLISTED) - self.sensitive = true if account.domain.in?(FORCE_SENSITIVE) - self.sensitive = false if sensitive.nil? end def set_locality diff --git a/app/models/user.rb b/app/models/user.rb index 5d67dc0d9..2bd039958 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -309,6 +309,10 @@ class User < ApplicationRecord @hide_captions ||= (settings.hide_captions || false) end + def default_sensitive? + @default_sensitive ||= settings.default_sensitive + end + def setting_default_privacy settings.default_privacy || 'public' end |