diff --git a/app/controllers/admin/domain_blocks_controller.rb b/app/controllers/admin/domain_blocks_controller.rb index 750f5c995c..3eb7b50d3f 100644 --- a/app/controllers/admin/domain_blocks_controller.rb +++ b/app/controllers/admin/domain_blocks_controller.rb @@ -78,15 +78,15 @@ module Admin 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_favourite, :reject_reply, :reject_reports, :private_comment, :public_comment, :obfuscate) 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_favourite, :reject_reply, :reject_reports, :private_comment, :public_comment, :obfuscate) end def form_domain_block_batch_params - params.require(:form_domain_block_batch).permit(domain_blocks_attributes: [:enabled, :domain, :severity, :reject_media, :reject_reports, :private_comment, :public_comment, :obfuscate]) + params.require(:form_domain_block_batch).permit(domain_blocks_attributes: [:enabled, :domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_reports, :private_comment, :public_comment, :obfuscate]) end def action_from_button diff --git a/app/controllers/api/v1/admin/domain_blocks_controller.rb b/app/controllers/api/v1/admin/domain_blocks_controller.rb index 8b77e9717d..2fea6c12b1 100644 --- a/app/controllers/api/v1/admin/domain_blocks_controller.rb +++ b/app/controllers/api/v1/admin/domain_blocks_controller.rb @@ -69,7 +69,7 @@ class Api::V1::Admin::DomainBlocksController < Api::BaseController end def domain_block_params - params.permit(:severity, :reject_media, :reject_reports, :private_comment, :public_comment, :obfuscate) + params.permit(:severity, :reject_media, :reject_favourite, :reject_reply, :reject_reports, :private_comment, :public_comment, :obfuscate) end def insert_pagination_headers @@ -101,6 +101,6 @@ class Api::V1::Admin::DomainBlocksController < Api::BaseController end def resource_params - params.permit(:domain, :severity, :reject_media, :reject_reports, :private_comment, :public_comment, :obfuscate) + params.permit(:domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_reports, :private_comment, :public_comment, :obfuscate) end end diff --git a/app/javascript/packs/admin.jsx b/app/javascript/packs/admin.jsx index 038e9b4347..f8a8cc6d9f 100644 --- a/app/javascript/packs/admin.jsx +++ b/app/javascript/packs/admin.jsx @@ -108,12 +108,22 @@ delegate(document, '.filter-subset--with-select select', 'change', ({ target }) const onDomainBlockSeverityChange = (target) => { const rejectMediaDiv = document.querySelector('.input.with_label.domain_block_reject_media'); + const rejectFavouriteDiv= document.querySelector('.input.with_label.domain_block_reject_favourite'); + const rejectReplyDiv = document.querySelector('.input.with_label.domain_block_reject_reply'); const rejectReportsDiv = document.querySelector('.input.with_label.domain_block_reject_reports'); if (rejectMediaDiv) { rejectMediaDiv.style.display = (target.value === 'suspend') ? 'none' : 'block'; } + if (rejectFavouriteDiv) { + rejectFavouriteDiv.style.display = (target.value === 'suspend') ? 'none' : 'block'; + } + + if (rejectReplyDiv) { + rejectReplyDiv.style.display = (target.value === 'suspend') ? 'none' : 'block'; + } + if (rejectReportsDiv) { rejectReportsDiv.style.display = (target.value === 'suspend') ? 'none' : 'block'; } diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index 95009e0081..67f4ab4df9 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -46,6 +46,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity 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 reply_to_local? && reject_reply_to_local? with_lock("create:#{object_uri}") do return if delete_arrived_first?(object_uri) || poll_vote? @@ -392,6 +393,10 @@ class ActivityPub::Activity::Create < ActivityPub::Activity !replied_to_status.nil? && replied_to_status.account.local? end + def reject_reply_to_local? + @reject_reply_to_local ||= DomainBlock.reject_reply?(@account.domain) + end + def related_to_local_activity? fetch? || followed_by_local_accounts? || requested_through_relay? || responds_to_followed_account? || addresses_local_accounts? diff --git a/app/lib/activitypub/activity/like.rb b/app/lib/activitypub/activity/like.rb index c0592c4c61..4c58d46ce7 100644 --- a/app/lib/activitypub/activity/like.rb +++ b/app/lib/activitypub/activity/like.rb @@ -4,7 +4,7 @@ class ActivityPub::Activity::Like < ActivityPub::Activity def perform @original_status = status_from_uri(object_uri) - return if @original_status.nil? || !@original_status.account.local? || delete_arrived_first?(@json['id']) + return if @original_status.nil? || !@original_status.account.local? || delete_arrived_first?(@json['id']) || reject_favourite? if shortcode.nil? process_favourite @@ -15,6 +15,10 @@ class ActivityPub::Activity::Like < ActivityPub::Activity private + def reject_favourite? + @reject_favourite ||= DomainBlock.reject_favourite?(@account.domain) + end + def process_favourite return if @account.favourited?(@original_status) diff --git a/app/models/admin/import.rb b/app/models/admin/import.rb index 0fd4bdb824..c94afe6c62 100644 --- a/app/models/admin/import.rb +++ b/app/models/admin/import.rb @@ -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 diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb index fbb045416c..2d864e95c4 100644 --- a/app/models/domain_block.rb +++ b/app/models/domain_block.rb @@ -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 diff --git a/app/serializers/rest/admin/domain_block_serializer.rb b/app/serializers/rest/admin/domain_block_serializer.rb index b955d008a6..f82abba16f 100644 --- a/app/serializers/rest/admin/domain_block_serializer.rb +++ b/app/serializers/rest/admin/domain_block_serializer.rb @@ -2,7 +2,7 @@ class REST::Admin::DomainBlockSerializer < ActiveModel::Serializer attributes :id, :domain, :created_at, :severity, - :reject_media, :reject_reports, + :reject_media, :reject_favourite, :reject_reply, :reject_reports, :private_comment, :public_comment, :obfuscate def id diff --git a/app/views/admin/domain_blocks/edit.html.haml b/app/views/admin/domain_blocks/edit.html.haml index 39c6d108a7..5cf43397ad 100644 --- a/app/views/admin/domain_blocks/edit.html.haml +++ b/app/views/admin/domain_blocks/edit.html.haml @@ -17,6 +17,12 @@ .fields-group = f.input :reject_media, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_media'), hint: I18n.t('admin.domain_blocks.reject_media_hint') + .fields-group + = f.input :reject_favourite, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_favourite'), hint: I18n.t('admin.domain_blocks.reject_favourite_hint') + + .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') + .fields-group = f.input :reject_reports, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_reports'), hint: I18n.t('admin.domain_blocks.reject_reports_hint') diff --git a/app/views/admin/domain_blocks/new.html.haml b/app/views/admin/domain_blocks/new.html.haml index bcaa331b56..df78adc0d7 100644 --- a/app/views/admin/domain_blocks/new.html.haml +++ b/app/views/admin/domain_blocks/new.html.haml @@ -17,6 +17,12 @@ .fields-group = f.input :reject_media, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_media'), hint: I18n.t('admin.domain_blocks.reject_media_hint') + .fields-group + = f.input :reject_favourite, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_favourite'), hint: I18n.t('admin.domain_blocks.reject_favourite_hint') + + .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') + .fields-group = f.input :reject_reports, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_reports'), hint: I18n.t('admin.domain_blocks.reject_reports_hint') diff --git a/app/views/admin/export_domain_blocks/_domain_block.html.haml b/app/views/admin/export_domain_blocks/_domain_block.html.haml index 5d4b6c4d0d..05a9571bc9 100644 --- a/app/views/admin/export_domain_blocks/_domain_block.html.haml +++ b/app/views/admin/export_domain_blocks/_domain_block.html.haml @@ -10,6 +10,8 @@ = f.hidden_field :domain = f.hidden_field :severity = f.hidden_field :reject_media + = f.hidden_field :reject_favourite + = f.hidden_field :reject_reply = f.hidden_field :reject_reports = f.hidden_field :obfuscate = f.hidden_field :private_comment diff --git a/config/locales/en.yml b/config/locales/en.yml index 0e764e599b..612bb4b27a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -412,8 +412,12 @@ en: private_comment_hint: Comment about this domain limitation for internal use by the moderators. public_comment: Public comment public_comment_hint: Comment about this domain limitation for the general public, if advertising the list of domain limitations is enabled. + reject_favourite: Reject favourites + reject_favourite_hint: Reject favourites or emoji-reaction in the future reject_media: Reject media files reject_media_hint: Removes locally stored media files and refuses to download any in the future. Irrelevant for suspensions + reject_reply: Reject replies + reject_reply_hint: Reject replies in the future reject_reports: Reject reports reject_reports_hint: Ignore all reports coming from this domain. Irrelevant for suspensions undo: Undo domain block @@ -483,7 +487,9 @@ en: description_html: You can define content policies that will be applied to all accounts from this domain and any of its subdomains. limited_federation_mode_description_html: You can chose whether to allow federation with this domain. policies: + reject_favourite: Reject favourite reject_media: Reject media + reject_reply: Reject reply reject_reports: Reject reports silence: Limit suspend: Suspend diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 7f689f2229..750655aaf2 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -403,8 +403,12 @@ ja: private_comment_hint: このコメントは同じサーバーのモデレーターも閲覧できます。 public_comment: コメント (公開) public_comment_hint: ドメインブロックの公開を有効にしている場合、このコメントも公開されます。 + reject_favourite: お気に入り、絵文字リアクションを拒否 + reject_favourite_hint: 今後のお気に入り、絵文字リアクションを拒否します。停止とは無関係です reject_media: メディアファイルを拒否 reject_media_hint: ローカルに保存されたメディアファイルを削除し、今後のダウンロードを拒否します。停止とは無関係です + reject_reply: リプライを拒否 + reject_reply_hint: 今後のリプライを拒否します。停止とは無関係です reject_reports: 通報を拒否 reject_reports_hint: このドメインからの通報をすべて無視します。停止とは無関係です undo: ドメインブロックを戻す @@ -471,7 +475,9 @@ ja: description_html: このドメインとそのサブドメインのすべてのアカウントに適用されるコンテンツポリシーを定義できます。 limited_federation_mode_description_html: このドメインとの連合を許可するかどうかを選択できます。 policies: + reject_favourite: お気に入りを拒否 reject_media: メディアを拒否する + reject_reply: リプライを拒否 reject_reports: 通報を拒否 silence: 制限 suspend: サスペンド diff --git a/db/migrate/20230427022606_add_reject_favourite_to_domain_blocks.rb b/db/migrate/20230427022606_add_reject_favourite_to_domain_blocks.rb new file mode 100644 index 0000000000..f312bdf2d7 --- /dev/null +++ b/db/migrate/20230427022606_add_reject_favourite_to_domain_blocks.rb @@ -0,0 +1,6 @@ +class AddRejectFavouriteToDomainBlocks < ActiveRecord::Migration[6.1] + def change + add_column :domain_blocks, :reject_favourite, :boolean, null: false, default: false + add_column :domain_blocks, :reject_reply, :boolean, null: false, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index aef6f3736e..adb2b6914a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_04_26_013738) do +ActiveRecord::Schema.define(version: 2023_04_27_022606) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -468,6 +468,8 @@ ActiveRecord::Schema.define(version: 2023_04_26_013738) do t.text "private_comment" t.text "public_comment" t.boolean "obfuscate", default: false, null: false + t.boolean "reject_favourite", default: false, null: false + t.boolean "reject_reply", default: false, null: false t.index ["domain"], name: "index_domain_blocks_on_domain", unique: true end