From 565e60d0db899e36cee8dbd1d8e31c7517f7191e Mon Sep 17 00:00:00 2001 From: KMY Date: Fri, 28 Apr 2023 08:52:50 +0900 Subject: [PATCH] Add hidden parameter to domain blocks --- app/controllers/admin/domain_blocks_controller.rb | 6 +++--- app/controllers/api/v1/admin/domain_blocks_controller.rb | 4 ++-- .../api/v1/instances/domain_blocks_controller.rb | 1 + app/models/domain_block.rb | 4 +++- app/views/admin/domain_blocks/edit.html.haml | 6 ++++++ app/views/admin/domain_blocks/new.html.haml | 6 ++++++ config/locales/ja.yml | 4 ++++ db/migrate/20230427233749_add_hidden_to_domain_blocks.rb | 6 ++++++ db/schema.rb | 4 +++- 9 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20230427233749_add_hidden_to_domain_blocks.rb diff --git a/app/controllers/admin/domain_blocks_controller.rb b/app/controllers/admin/domain_blocks_controller.rb index 2294388b15..48f2fdbbf6 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_favourite, :reject_reply, :reject_send_not_public_searchability, :reject_send_unlisted_dissubscribable, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :reject_reports, :private_comment, :public_comment, :obfuscate) + params.require(:domain_block).permit(:severity, :reject_media, :reject_favourite, :reject_reply, :reject_send_not_public_searchability, :reject_send_unlisted_dissubscribable, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous) end def resource_params - params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_send_not_public_searchability, :reject_send_unlisted_dissubscribable, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :reject_reports, :private_comment, :public_comment, :obfuscate) + params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_send_not_public_searchability, :reject_send_unlisted_dissubscribable, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous) end 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_unlisted_dissubscribable, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :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_send_not_public_searchability, :reject_send_unlisted_dissubscribable, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous]) 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 add327ff92..a981fba005 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_favourite, :reject_reply, :reject_reports, :reject_send_not_public_searchability, :reject_send_unlisted_dissubscribable, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :private_comment, :public_comment, :obfuscate) + params.permit(:severity, :reject_media, :reject_favourite, :reject_reply, :reject_reports, :reject_send_not_public_searchability, :reject_send_unlisted_dissubscribable, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous) 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_favourite, :reject_reply, :reject_send_not_public_searchability, :reject_send_unlisted_dissubscribable, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :reject_reports, :private_comment, :public_comment, :obfuscate) + params.permit(:domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_send_not_public_searchability, :reject_send_unlisted_dissubscribable, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous) end end diff --git a/app/controllers/api/v1/instances/domain_blocks_controller.rb b/app/controllers/api/v1/instances/domain_blocks_controller.rb index e954c45897..15fba7ecd1 100644 --- a/app/controllers/api/v1/instances/domain_blocks_controller.rb +++ b/app/controllers/api/v1/instances/domain_blocks_controller.rb @@ -26,5 +26,6 @@ class Api::V1::Instances::DomainBlocksController < Api::BaseController def set_domain_blocks @domain_blocks = DomainBlock.with_user_facing_limitations.by_severity + @domain_blocks = @domain_blocks.filter { |block| !block.hidden_anonymous } if !user_signed_in? end end diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb index cc34f2ab99..dab9056a63 100644 --- a/app/models/domain_block.rb +++ b/app/models/domain_block.rb @@ -25,6 +25,8 @@ # reject_hashtag :boolean default(FALSE), not null # reject_straight_follow :boolean default(FALSE), not null # reject_new_follow :boolean default(FALSE), not null +# hidden :boolean default(FALSE), not null +# hidden_anonymous :boolean default(FALSE), not null # class DomainBlock < ApplicationRecord @@ -40,7 +42,7 @@ class DomainBlock < ApplicationRecord delegate :count, to: :accounts, prefix: true scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) } - scope :with_user_facing_limitations, -> { where(severity: [:silence, :suspend]).or(where(reject_media: true)) } + scope :with_user_facing_limitations, -> { where(severity: [:silence, :suspend]).or(where(reject_media: true)).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 :by_severity, -> { order(Arel.sql('(CASE severity WHEN 0 THEN 1 WHEN 1 THEN 2 WHEN 2 THEN 0 END), domain')) } diff --git a/app/views/admin/domain_blocks/edit.html.haml b/app/views/admin/domain_blocks/edit.html.haml index da37cea2c2..aea62d51c8 100644 --- a/app/views/admin/domain_blocks/edit.html.haml +++ b/app/views/admin/domain_blocks/edit.html.haml @@ -62,5 +62,11 @@ .field-group = f.input :public_comment, wrapper: :with_label, label: I18n.t('admin.domain_blocks.public_comment'), hint: t('admin.domain_blocks.public_comment_hint'), as: :string + .fields-group + = f.input :hidden, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.hidden'), hint: I18n.t('admin.domain_blocks.hidden_hint') + + .fields-group + = f.input :hidden_anonymous, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.hidden_anonymous'), hint: I18n.t('admin.domain_blocks.hidden_anonymous_hint') + .actions = f.button :button, t('generic.save_changes'), type: :submit diff --git a/app/views/admin/domain_blocks/new.html.haml b/app/views/admin/domain_blocks/new.html.haml index 8f7f31ebe9..470cf52cea 100644 --- a/app/views/admin/domain_blocks/new.html.haml +++ b/app/views/admin/domain_blocks/new.html.haml @@ -62,5 +62,11 @@ .field-group = f.input :public_comment, wrapper: :with_label, label: I18n.t('admin.domain_blocks.public_comment'), hint: t('admin.domain_blocks.public_comment_hint'), as: :string + .fields-group + = f.input :hidden, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.hidden'), hint: I18n.t('admin.domain_blocks.hidden_hint') + + .fields-group + = f.input :hidden_anonymous, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.hidden_anonymous'), hint: I18n.t('admin.domain_blocks.hidden_anonymous_hint') + .actions = f.button :button, t('.create'), type: :submit diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 9b706a4d45..decb270e2e 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -387,6 +387,10 @@ ja: existing_domain_block: あなたは既に%{name}さんに厳しい制限を課しています。 existing_domain_block_html: 既に%{name}に対して、より厳しい制限を課しています。先にその制限を解除する必要があります。 export: エクスポート + hidden: 非公開にする + hidden_hint: 公開することで当サーバーの安全が脅かされる場合、このドメインブロックを非公開にすることができます。 + hidden_anonymous: 未ログインユーザーに非公開にする + hidden_anonymous_hint: 公開することで当サーバーの安全が脅かされる場合、非ログインユーザーに限りこのドメインブロックを非公開にすることができます。 import: インポート new: create: ブロックを作成 diff --git a/db/migrate/20230427233749_add_hidden_to_domain_blocks.rb b/db/migrate/20230427233749_add_hidden_to_domain_blocks.rb new file mode 100644 index 0000000000..0d64308525 --- /dev/null +++ b/db/migrate/20230427233749_add_hidden_to_domain_blocks.rb @@ -0,0 +1,6 @@ +class AddHiddenToDomainBlocks < ActiveRecord::Migration[6.1] + def change + add_column :domain_blocks, :hidden, :boolean, null: false, default: false + add_column :domain_blocks, :hidden_anonymous, :boolean, null: false, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index b12919be4e..5779eaac91 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_27_122753) do +ActiveRecord::Schema.define(version: 2023_04_27_233749) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -479,6 +479,8 @@ ActiveRecord::Schema.define(version: 2023_04_27_122753) do t.boolean "reject_hashtag", default: false, null: false t.boolean "reject_straight_follow", default: false, null: false t.boolean "reject_new_follow", default: false, null: false + t.boolean "hidden", default: false, null: false + t.boolean "hidden_anonymous", default: false, null: false t.index ["domain"], name: "index_domain_blocks_on_domain", unique: true end