Add: #437 ドメインブロックで「未ログインユーザーに非公開」の設定を「非公開」にコピーするマイグレーションコード (#439)

* Add: #437 ドメインブロックで「未ログインユーザーに非公開」の設定を「非公開」にコピーするマイグレーションコード

* Fix test for LTS

* Fix test
This commit is contained in:
KMY(雪あすか) 2024-01-09 16:19:23 +09:00 committed by GitHub
parent 4719ca6525
commit 7694c62bc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 26 deletions

View file

@ -70,7 +70,7 @@ class Api::V1::Admin::DomainBlocksController < Api::BaseController
def domain_block_params
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, :reject_friend, :detect_invalid_subscription, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous)
:reject_new_follow, :reject_friend, :detect_invalid_subscription, :private_comment, :public_comment, :obfuscate, :hidden)
end
def insert_pagination_headers
@ -103,6 +103,6 @@ class Api::V1::Admin::DomainBlocksController < Api::BaseController
def resource_params
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, :reject_friend, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous)
:reject_new_follow, :reject_friend, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden)
end
end

View file

@ -25,7 +25,6 @@
# 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
# detect_invalid_subscription :boolean default(FALSE), not null
# reject_reply_exclude_followers :boolean default(FALSE), not null
# reject_friend :boolean default(FALSE), not null
@ -44,7 +43,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(hidden: false, hidden_anonymous: false) }
scope :with_user_facing_limitations, -> { where(hidden: false) }
scope :with_limitations, lambda {
where(severity: [:silence, :suspend])
.or(where(reject_media: true))

View file

@ -0,0 +1,18 @@
# frozen_string_literal: true
class RemoveHiddenAnonymousFromDomainBlocks < ActiveRecord::Migration[7.0]
class DomainBlock < ApplicationRecord; end
def up
safety_assured do
DomainBlock.where(hidden_anonymous: true, hidden: false).update_all(hidden: true)
remove_column :domain_blocks, :hidden_anonymous
end
end
def down
safety_assured do
add_column :domain_blocks, :hidden_anonymous, :boolean, null: false, default: false
end
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2023_12_22_100226) do
ActiveRecord::Schema[7.1].define(version: 2024_01_09_035435) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -584,7 +584,6 @@ ActiveRecord::Schema[7.1].define(version: 2023_12_22_100226) do
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.boolean "detect_invalid_subscription", default: false, null: false
t.boolean "reject_reply_exclude_followers", default: false, null: false
t.boolean "reject_friend", default: false, null: false

View file

@ -37,16 +37,6 @@ RSpec.describe 'Domain Blocks' do
expect(body_as_json.pluck(:domain)).to_not include('hello.com')
end
end
context 'with hidden domain block from anonymous' do
before { Fabricate(:domain_block, domain: 'hello.com', hidden_anonymous: true) }
it 'returns http success and dont include hidden record' do
get api_v1_instance_domain_blocks_path
expect(body_as_json.pluck(:domain)).to_not include('hello.com')
end
end
end
context 'with domain blocks set to users' do
@ -84,16 +74,6 @@ RSpec.describe 'Domain Blocks' do
expect(body_as_json.pluck(:domain)).to_not include('hello.com')
end
end
context 'with hidden domain block from anonymous' do
before { Fabricate(:domain_block, domain: 'hello.com', hidden_anonymous: true) }
it 'returns http success and dont include hidden record' do
get api_v1_instance_domain_blocks_path, headers: headers
expect(body_as_json.pluck(:domain)).to_not include('hello.com')
end
end
end
context 'with domain blocks set to disabled' do