Skip to content

Commit

Permalink
Merge pull request #76 from atsu1125/develop
Browse files Browse the repository at this point in the history
Merge develop to 20240810 version
  • Loading branch information
atsu1125 authored Aug 10, 2024
2 parents 97501da + 3c5cf31 commit 3475ddd
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/controllers/admin/domain_blocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ def set_domain_block
end

def update_params
params.require(:domain_block).permit(:severity, :reject_media, :reject_reports, :private_comment, :public_comment, :obfuscate)
params.require(:domain_block).permit(:severity, :reject_media, :reject_reports, :private_comment, :public_comment, :obfuscate, :reject_send_public_unlisted, :reject_send_private)
end

def resource_params
params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_reports, :private_comment, :public_comment, :obfuscate)
params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_reports, :private_comment, :public_comment, :obfuscate, :reject_send_public_unlisted, :reject_send_private)
end
end
end
12 changes: 10 additions & 2 deletions app/lib/status_reach_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def inboxes
private

def reached_account_inboxes
Account.where(id: reached_account_ids).inboxes
Account.where(id: reached_account_ids).where.not(domain: banned_domains).inboxes
end

def reached_account_ids
Expand Down Expand Up @@ -74,7 +74,7 @@ def followers_inboxes
elsif @status.direct_visibility? || @status.limited_visibility?
[]
else
@status.account.followers.inboxes
@status.account.followers.where.not(domain: banned_domains).inboxes
end
end

Expand All @@ -93,4 +93,12 @@ def distributable?
def unsafe?
@options[:unsafe]
end

def banned_domains
return @banned_domains if @banned_domains
blocks = []
blocks << DomainBlock.where(reject_send_public_unlisted: true).pluck(:domain) if @status.public_visibility? || @status.unlisted_visibility?
blocks << DomainBlock.where(reject_send_private: true).pluck(:domain) if @status.private_visibility? || @status.direct_visibility? || @status.limited_visibility?
return @banned_domains = blocks.uniq
end
end
32 changes: 21 additions & 11 deletions app/models/domain_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,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_send_public_unlisted :boolean default(FALSE), not null
# reject_send_private :boolean default(FALSE), not null
#

class DomainBlock < ApplicationRecord
Expand Down Expand Up @@ -47,6 +49,14 @@ def reject_reports?(domain)
!!rule_for(domain)&.reject_reports?
end

def reject_send_public_unlisted?(domain)
!!rule_for(domain)&.reject_send_public_unlisted?
end

def reject_send_private?(domain)
!!rule_for(domain)&.reject_send_private?
end

alias blocked? suspend?

def rule_for(domain)
Expand All @@ -67,7 +77,7 @@ def stricter_than?(other_block)
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_reports || !other_block.reject_reports) && (reject_send_public_unlisted || !other_block.reject_send_public_unlisted) && (reject_send_private || !other_block.reject_send_private)
end

def affected_accounts_count
Expand Down
6 changes: 6 additions & 0 deletions app/views/admin/domain_blocks/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
.fields-group
= f.input :obfuscate, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.obfuscate'), hint: I18n.t('admin.domain_blocks.obfuscate_hint')

.fields-group
= f.input :reject_send_public_unlisted, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_send_public_unlisted'), hint: I18n.t('admin.domain_blocks.reject_send_public_unlisted_hint')

.fields-group
= f.input :reject_send_private, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_send_private'), hint: I18n.t('admin.domain_blocks.reject_send_private_hint')

.field-group
= f.input :private_comment, wrapper: :with_label, label: I18n.t('admin.domain_blocks.private_comment'), hint: t('admin.domain_blocks.private_comment_hint'), rows: 6

Expand Down
6 changes: 6 additions & 0 deletions app/views/admin/domain_blocks/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
.fields-group
= f.input :obfuscate, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.obfuscate'), hint: I18n.t('admin.domain_blocks.obfuscate_hint')

.fields-group
= f.input :reject_send_public_unlisted, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_send_public_unlisted'), hint: I18n.t('admin.domain_blocks.reject_send_public_unlisted_hint')

.fields-group
= f.input :reject_send_private, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_send_private'), hint: I18n.t('admin.domain_blocks.reject_send_private_hint')

.field-group
= f.input :private_comment, wrapper: :with_label, label: I18n.t('admin.domain_blocks.private_comment'), hint: t('admin.domain_blocks.private_comment_hint'), rows: 6

Expand Down
4 changes: 4 additions & 0 deletions app/views/admin/instances/_instance.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
- unless first_item
&bull;
= t('admin.domain_blocks.rejecting_reports')
- if instance.domain_block.reject_send_public_unlisted? || instance.domain_block.reject_send_private?
- unless first_item
&bull;
= t('admin.domain_blocks.rejecting_sending_some_visibilities_statuses')
- elsif whitelist_mode?
= t('admin.accounts.whitelisted')
- else
Expand Down
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,13 @@ en:
reject_media_hint: Removes locally stored media files and refuses to download any in the future. Irrelevant for suspensions
reject_reports: Reject reports
reject_reports_hint: Ignore all reports coming from this domain. Irrelevant for suspensions
reject_send_private: Do not Deliver Followers-Only Statuses
reject_send_private_hint: Stops delivering Followers-Only Statuses to this domain. Irrelevant for suspensions
reject_send_public_unlisted: Do not Deliver Public Statuses
reject_send_public_unlisted_hint: Stops delivering Public Statuses to this domain. Irrelevant for suspensions
rejecting_media: rejecting media files
rejecting_reports: rejecting reports
rejecting_sending_some_visibilities_statuses: rejecting sending some visibilities statuses
severity:
silence: limited
suspend: suspended
Expand Down
5 changes: 5 additions & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,13 @@ ja:
reject_media_hint: ローカルに保存されたメディアファイルを削除し、今後のダウンロードを拒否します。停止とは無関係です
reject_reports: 通報を拒否
reject_reports_hint: このドメインからの通報をすべて無視します。停止とは無関係です
reject_send_private: フォロワーのみの投稿を配送しない
reject_send_private_hint: 相手サーバーからのフェッチは防げません。停止とは無関係です
reject_send_public_unlisted: 公開投稿を配送しない
reject_send_public_unlisted_hint: 相手サーバーからのフェッチは防げません。停止とは無関係です
rejecting_media: メディアファイルを拒否中
rejecting_reports: 通報を拒否中
rejecting_sending_some_visibilities_statuses: 一部の公開範囲の投稿の配送を停止中
severity:
silence: サイレンス中
suspend: 停止中
Expand Down
17 changes: 17 additions & 0 deletions db/migrate/20240810170735_add_reject_sending_to_domain_blocks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require Rails.root.join('lib', 'mastodon', 'migration_helpers')

class AddRejectSendingToDomainBlocks < ActiveRecord::Migration[6.1]
include Mastodon::MigrationHelpers

disable_ddl_transaction!

def up
safety_assured { add_column_with_default :domain_blocks, :reject_send_public_unlisted, :boolean, default: false, allow_null: false }
safety_assured { add_column_with_default :domain_blocks, :reject_send_private, :boolean, default: false, allow_null: false }
end

def down
remove_column :domain_blocks, :reject_send_private
remove_column :domain_blocks, :reject_send_public_unlisted
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2022_11_08_021125) do
ActiveRecord::Schema.define(version: 2024_08_10_170735) do

# These are extensions that must be enabled in order to support this database
enable_extension "pgroonga"
Expand Down Expand Up @@ -378,6 +378,8 @@
t.text "private_comment"
t.text "public_comment"
t.boolean "obfuscate", default: false, null: false
t.boolean "reject_send_public_unlisted", default: false, null: false
t.boolean "reject_send_private", default: false, null: false
t.index ["domain"], name: "index_domain_blocks_on_domain", unique: true
end

Expand Down

0 comments on commit 3475ddd

Please sign in to comment.