Add domain block setting reject_favourite and reject_reply

This commit is contained in:
KMY 2023-04-27 12:04:10 +09:00
parent 27353bbaee
commit 6537405eab
15 changed files with 85 additions and 22 deletions

View file

@ -34,7 +34,7 @@ class Admin::Import
field&.strip
when '#severity'
field&.strip&.to_sym
when '#reject_media', '#reject_reports', '#obfuscate'
when '#reject_media', '#reject_favourite', '#reject_reply', '#reject_reports', '#obfuscate'
ActiveModel::Type::Boolean.new.cast(field)
else
field

View file

@ -4,16 +4,18 @@
#
# 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
# private_comment :text
# public_comment :text
# obfuscate :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("silence")
# reject_media :boolean default(FALSE), not null
# reject_reports :boolean default(FALSE), not null
# private_comment :text
# public_comment :text
# obfuscate :boolean default(FALSE), not null
# reject_favourite :boolean default(FALSE), not null
# reject_reply :boolean default(FALSE), not null
#
class DomainBlock < ApplicationRecord
@ -30,7 +32,7 @@ class DomainBlock < ApplicationRecord
scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
scope :with_user_facing_limitations, -> { where(severity: [:silence, :suspend]) }
scope :with_limitations, -> { where(severity: [:silence, :suspend]).or(where(reject_media: true)) }
scope :with_limitations, -> { where(severity: [:silence, :suspend]).or(where(reject_media: true)).or(where(reject_favourite: true)).or(where(reject_reply: true)) }
scope :by_severity, -> { order(Arel.sql('(CASE severity WHEN 0 THEN 1 WHEN 1 THEN 2 WHEN 2 THEN 0 END), domain')) }
def to_log_human_identifier
@ -41,7 +43,7 @@ class DomainBlock < ApplicationRecord
if suspend?
[:suspend]
else
[severity.to_sym, reject_media? ? :reject_media : nil, reject_reports? ? :reject_reports : nil].reject { |policy| policy == :noop || policy.nil? }
[severity.to_sym, reject_media? ? :reject_media : nil, reject_favourite? ? :reject_favourite : nil, reject_reply? ? :reject_reply : nil, reject_reports? ? :reject_reports : nil].reject { |policy| policy == :noop || policy.nil? }
end
end
@ -58,6 +60,14 @@ class DomainBlock < ApplicationRecord
!!rule_for(domain)&.reject_media?
end
def reject_favourite?(domain)
!!rule_for(domain)&.reject_favourite?
end
def reject_reply?(domain)
!!rule_for(domain)&.reject_reply?
end
def reject_reports?(domain)
!!rule_for(domain)&.reject_reports?
end
@ -82,7 +92,7 @@ class DomainBlock < ApplicationRecord
return false if other_block.suspend? && (silence? || noop?)
return false if other_block.silence? && noop?
(reject_media || !other_block.reject_media) && (reject_reports || !other_block.reject_reports)
(reject_media || !other_block.reject_media) && (reject_favourite || !other_block.reject_favourite) && (reject_reply || !other_block.reject_reply) && (reject_reports || !other_block.reject_reports)
end
def affected_accounts_count