Add domainblocks to reject_reply_exclude_followers

This commit is contained in:
KMY 2023-05-12 21:46:28 +09:00
parent f84a002675
commit 3fa8efaf93
12 changed files with 50 additions and 9 deletions

View file

@ -78,15 +78,15 @@ module Admin
end end
def update_params def update_params
params.require(:domain_block).permit(:severity, :reject_media, :reject_favourite, :reject_reply, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous) params.require(:domain_block).permit(:severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous)
end end
def resource_params def resource_params
params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous) params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous)
end end
def form_domain_block_batch_params def form_domain_block_batch_params
params.require(:form_domain_block_batch).permit(domain_blocks_attributes: [:enabled, :domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous]) params.require(:form_domain_block_batch).permit(domain_blocks_attributes: [:enabled, :domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous])
end end
def action_from_button def action_from_button

View file

@ -69,7 +69,7 @@ class Api::V1::Admin::DomainBlocksController < Api::BaseController
end end
def domain_block_params def domain_block_params
params.permit(:severity, :reject_media, :reject_favourite, :reject_reply, :reject_reports, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous) params.permit(:severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_reports, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous)
end end
def insert_pagination_headers def insert_pagination_headers
@ -101,6 +101,6 @@ class Api::V1::Admin::DomainBlocksController < Api::BaseController
end end
def resource_params def resource_params
params.permit(:domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous) params.permit(:domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous)
end end
end end

View file

@ -47,6 +47,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
def create_status def create_status
return reject_payload! if unsupported_object_type? || non_matching_uri_hosts?(@account.uri, object_uri) || tombstone_exists? || !related_to_local_activity? return reject_payload! if unsupported_object_type? || non_matching_uri_hosts?(@account.uri, object_uri) || tombstone_exists? || !related_to_local_activity?
return reject_payload! if (reply_to_local? || reply_to_local_account?) && reject_reply_to_local? return reject_payload! if (reply_to_local? || reply_to_local_account?) && reject_reply_to_local?
return reject_payload! if (!reply_to_local_account_following? || !reply_to_local_status_following?) && reject_reply_exclude_followers?
with_redis_lock("create:#{object_uri}") do with_redis_lock("create:#{object_uri}") do
return if delete_arrived_first?(object_uri) || poll_vote? return if delete_arrived_first?(object_uri) || poll_vote?
@ -141,6 +142,10 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
accounts_in_audience.any?(&:local?) accounts_in_audience.any?(&:local?)
end end
def reply_to_local_account_following?
!reply_to_local_account? || accounts_in_audience.none? { |account| account.local? && !account.following?(@account) }
end
def accounts_in_audience def accounts_in_audience
return @accounts_in_audience if @accounts_in_audience return @accounts_in_audience if @accounts_in_audience
@ -403,10 +408,18 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
!replied_to_status.nil? && replied_to_status.account.local? !replied_to_status.nil? && replied_to_status.account.local?
end end
def reply_to_local_status_following?
!reply_to_local? || replied_to_status.account.following?(@account)
end
def reject_reply_to_local? def reject_reply_to_local?
@reject_reply_to_local ||= DomainBlock.reject_reply?(@account.domain) @reject_reply_to_local ||= DomainBlock.reject_reply?(@account.domain)
end end
def reject_reply_exclude_followers?
@reject_reply_exclude_followers ||= DomainBlock.reject_reply_exclude_followers?(@account.domain)
end
def ignore_hashtags? def ignore_hashtags?
@ignore_hashtags ||= DomainBlock.reject_hashtag?(@account.domain) @ignore_hashtags ||= DomainBlock.reject_hashtag?(@account.domain)
end end

View file

@ -27,6 +27,7 @@
# hidden :boolean default(FALSE), not null # hidden :boolean default(FALSE), not null
# hidden_anonymous :boolean default(FALSE), not null # hidden_anonymous :boolean default(FALSE), not null
# detect_invalid_subscription :boolean default(FALSE), not null # detect_invalid_subscription :boolean default(FALSE), not null
# reject_reply_exclude_followers :boolean default(FALSE), not null
# #
class DomainBlock < ApplicationRecord class DomainBlock < ApplicationRecord
@ -43,7 +44,7 @@ class DomainBlock < ApplicationRecord
scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) } scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
scope :with_user_facing_limitations, -> { where(hidden: false) } scope :with_user_facing_limitations, -> { where(hidden: false) }
scope :with_limitations, -> { where(severity: [:silence, :suspend]).or(where(reject_media: true)).or(where(reject_favourite: true)).or(where(reject_reply: true)).or(where(reject_new_follow: true)).or(where(reject_straight_follow: true)) } scope :with_limitations, -> { where(severity: [:silence, :suspend]).or(where(reject_media: true)).or(where(reject_favourite: true)).or(where(reject_reply: true)).or(where(reject_reply_exclude_followers: true)).or(where(reject_new_follow: true)).or(where(reject_straight_follow: true)) }
scope :by_severity, -> { order(Arel.sql('(CASE severity WHEN 0 THEN 1 WHEN 1 THEN 2 WHEN 2 THEN 0 END), domain')) } 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 def to_log_human_identifier
@ -58,6 +59,7 @@ class DomainBlock < ApplicationRecord
reject_media? ? :reject_media : nil, reject_media? ? :reject_media : nil,
reject_favourite? ? :reject_favourite : nil, reject_favourite? ? :reject_favourite : nil,
reject_reply? ? :reject_reply : nil, reject_reply? ? :reject_reply : nil,
reject_reply_exclude_followers? ? :reject_reply_exclude_followers : nil,
reject_send_not_public_searchability? ? :reject_send_not_public_searchability : nil, reject_send_not_public_searchability? ? :reject_send_not_public_searchability : nil,
reject_send_public_unlisted? ? :reject_send_public_unlisted : nil, reject_send_public_unlisted? ? :reject_send_public_unlisted : nil,
reject_send_dissubscribable? ? :reject_send_dissubscribable : nil, reject_send_dissubscribable? ? :reject_send_dissubscribable : nil,
@ -92,6 +94,10 @@ class DomainBlock < ApplicationRecord
!!rule_for(domain)&.reject_reply? !!rule_for(domain)&.reject_reply?
end end
def reject_reply_exclude_followers?(domain)
!!rule_for(domain)&.reject_reply_exclude_followers?
end
def reject_hashtag?(domain) def reject_hashtag?(domain)
!!rule_for(domain)&.reject_hashtag? !!rule_for(domain)&.reject_hashtag?
end end
@ -128,7 +134,7 @@ class DomainBlock < ApplicationRecord
return false if other_block.suspend? && (silence? || noop?) return false if other_block.suspend? && (silence? || noop?)
return false if other_block.silence? && noop? return false if other_block.silence? && noop?
(reject_media || !other_block.reject_media) && (reject_favourite || !other_block.reject_favourite) && (reject_reply || !other_block.reject_reply) && (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_reply_exclude_followers || !other_block.reject_reply_exclude_followers) && (reject_reports || !other_block.reject_reports)
end end
def affected_accounts_count def affected_accounts_count

View file

@ -3,7 +3,7 @@
class REST::Admin::DomainBlockSerializer < ActiveModel::Serializer class REST::Admin::DomainBlockSerializer < ActiveModel::Serializer
attributes :id, :domain, :created_at, :severity, attributes :id, :domain, :created_at, :severity,
:reject_media, :reject_favourite, :reject_reply, :reject_reports, :reject_media, :reject_favourite, :reject_reply, :reject_reports,
:reject_send_not_public_searchability, :reject_send_not_public_searchability, :reject_reply_exclude_followers,
:reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive,
:reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription,
:private_comment, :public_comment, :obfuscate :private_comment, :public_comment, :obfuscate

View file

@ -23,6 +23,9 @@
.fields-group .fields-group
= f.input :reject_reply, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_reply'), hint: I18n.t('admin.domain_blocks.reject_reply_hint') = f.input :reject_reply, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_reply'), hint: I18n.t('admin.domain_blocks.reject_reply_hint')
.fields-group
= f.input :reject_reply_exclude_followers, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_reply_exclude_followers'), hint: I18n.t('admin.domain_blocks.reject_reply_exclude_followers_hint')
.fields-group .fields-group
= f.input :reject_send_not_public_searchability, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_send_not_public_searchability'), hint: I18n.t('admin.domain_blocks.reject_send_not_public_searchability_hint') = f.input :reject_send_not_public_searchability, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_send_not_public_searchability'), hint: I18n.t('admin.domain_blocks.reject_send_not_public_searchability_hint')

View file

@ -23,6 +23,9 @@
.fields-group .fields-group
= f.input :reject_reply, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_reply'), hint: I18n.t('admin.domain_blocks.reject_reply_hint') = f.input :reject_reply, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_reply'), hint: I18n.t('admin.domain_blocks.reject_reply_hint')
.fields-group
= f.input :reject_reply_exclude_followers, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_reply_exclude_followers'), hint: I18n.t('admin.domain_blocks.reject_reply_exclude_followers_hint')
.fields-group .fields-group
= f.input :reject_send_not_public_searchability, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_send_not_public_searchability'), hint: I18n.t('admin.domain_blocks.reject_send_not_public_searchability_hint') = f.input :reject_send_not_public_searchability, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_send_not_public_searchability'), hint: I18n.t('admin.domain_blocks.reject_send_not_public_searchability_hint')

View file

@ -12,6 +12,7 @@
= f.hidden_field :reject_media = f.hidden_field :reject_media
= f.hidden_field :reject_favourite = f.hidden_field :reject_favourite
= f.hidden_field :reject_reply = f.hidden_field :reject_reply
= f.hidden_field :reject_reply_exclude_followers
= f.hidden_field :reject_send_not_public_searchability = f.hidden_field :reject_send_not_public_searchability
= f.hidden_field :reject_send_public_unlisted = f.hidden_field :reject_send_public_unlisted
= f.hidden_field :reject_send_dissubscribable = f.hidden_field :reject_send_dissubscribable

View file

@ -423,7 +423,9 @@ en:
reject_new_follow: Reject follows reject_new_follow: Reject follows
reject_new_follow_hint: Reject follows in the future reject_new_follow_hint: Reject follows in the future
reject_reply: Reject replies reject_reply: Reject replies
reject_reply_exclude_followers: Reject replies exclude followers
reject_reply_hint: Reject replies in the future reject_reply_hint: Reject replies in the future
reject_reply_exclude_followers_hint: Reject replies exclude followers in the future
reject_reports: Reject reports reject_reports: Reject reports
reject_reports_hint: Ignore all reports coming from this domain. Irrelevant for suspensions reject_reports_hint: Ignore all reports coming from this domain. Irrelevant for suspensions
reject_send_dissubscribable: 購読拒否アカウントの投稿を配送しない reject_send_dissubscribable: 購読拒否アカウントの投稿を配送しない
@ -513,6 +515,7 @@ en:
reject_new_follow: Reject follows reject_new_follow: Reject follows
reject_straight_follow: Reject straight follow reject_straight_follow: Reject straight follow
reject_reply: Reject reply reject_reply: Reject reply
reject_reply_exclude_followers: Reject reply exclude followers
reject_reports: Reject reports reject_reports: Reject reports
silence: Limit silence: Limit
suspend: Suspend suspend: Suspend

View file

@ -420,7 +420,9 @@ ja:
reject_new_follow: 新規フォローを拒否 reject_new_follow: 新規フォローを拒否
reject_new_follow_hint: 今後の新規フォローを拒否します。停止とは無関係です reject_new_follow_hint: 今後の新規フォローを拒否します。停止とは無関係です
reject_reply: リプライを拒否 reject_reply: リプライを拒否
reject_reply_exclude_followers: フォロー相手以外からのリプライを拒否
reject_reply_hint: 今後のリプライを拒否します。停止とは無関係です reject_reply_hint: 今後のリプライを拒否します。停止とは無関係です
reject_reply_exclude_followers_hint: 今後のリプライを拒否します。停止とは無関係です
reject_reports: 通報を拒否 reject_reports: 通報を拒否
reject_reports_hint: このドメインからの通報をすべて無視します。停止とは無関係です reject_reports_hint: このドメインからの通報をすべて無視します。停止とは無関係です
reject_send_dissubscribable: 購読拒否アカウントの投稿を配送しない reject_send_dissubscribable: 購読拒否アカウントの投稿を配送しない
@ -507,6 +509,7 @@ ja:
reject_media: メディアを拒否する reject_media: メディアを拒否する
reject_new_follow: 新規フォローを拒否 reject_new_follow: 新規フォローを拒否
reject_reply: リプライを拒否 reject_reply: リプライを拒否
reject_reply_exclude_followers: フォロー相手以外からのリプライを拒否
reject_reports: 通報を拒否 reject_reports: 通報を拒否
reject_send_dissubscribable: 購読拒否投稿配送なし reject_send_dissubscribable: 購読拒否投稿配送なし
reject_send_media: メディア付き投稿配送なし reject_send_media: メディア付き投稿配送なし

View file

@ -0,0 +1,8 @@
# frozen_string_literal: true
class AddRejectReplyExcludeFollowersToDomainBlocks < ActiveRecord::Migration[6.1]
def change
add_column :domain_blocks, :reject_reply_exclude_followers, :boolean, null: false, default: false
add_index :domain_blocks, :reject_reply_exclude_followers
end
end

View file

@ -12,7 +12,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2023_05_10_033040) do ActiveRecord::Schema.define(version: 2023_05_12_122757) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -512,6 +512,7 @@ ActiveRecord::Schema.define(version: 2023_05_10_033040) do
t.boolean "hidden", default: false, null: false t.boolean "hidden", default: false, null: false
t.boolean "hidden_anonymous", default: false, null: false t.boolean "hidden_anonymous", default: false, null: false
t.boolean "detect_invalid_subscription", default: false, null: false t.boolean "detect_invalid_subscription", default: false, null: false
t.boolean "reject_reply_exclude_followers", default: false, null: false
t.index ["domain"], name: "index_domain_blocks_on_domain", unique: true t.index ["domain"], name: "index_domain_blocks_on_domain", unique: true
end end