From d7deb6f6401a0a49a7a569679f6fc757eb978f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KMY=EF=BC=88=E9=9B=AA=E3=81=82=E3=81=99=E3=81=8B=EF=BC=89?= Date: Tue, 28 Jan 2025 12:22:20 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20#959=20NG=E3=83=AB=E3=83=BC=E3=83=AB?= =?UTF-8?q?=E3=81=A7=E7=B5=B5=E6=96=87=E5=AD=97=E3=83=AA=E3=82=A2=E3=82=AF?= =?UTF-8?q?=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=92=E6=8B=92=E5=90=A6=E3=81=97?= =?UTF-8?q?=E3=81=9F=E5=A0=B4=E5=90=88=E3=80=81=E8=87=AA=E5=88=86=E3=81=AE?= =?UTF-8?q?=E3=82=B5=E3=83=BC=E3=83=90=E3=83=BC=E3=81=AE=E3=82=AB=E3=82=B9?= =?UTF-8?q?=E3=82=BF=E3=83=A0=E7=B5=B5=E6=96=87=E5=AD=97=E3=81=AF=E5=B8=B8?= =?UTF-8?q?=E3=81=AB=E6=8B=92=E5=90=A6=E3=81=95=E3=82=8C=E3=82=8B=20(#963)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: #959 NGルールで絵文字リアクションを拒否した場合、自分のサーバーのカスタム絵文字は常に拒否される * Fix test * Fix test --- app/models/admin/ng_rule.rb | 8 +++++--- spec/models/admin/ng_rule_spec.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/models/admin/ng_rule.rb b/app/models/admin/ng_rule.rb index 54ca39b4c9..3f25d8896e 100644 --- a/app/models/admin/ng_rule.rb +++ b/app/models/admin/ng_rule.rb @@ -62,9 +62,11 @@ class Admin::NgRule return false if @ng_rule.reaction_allow_follower && (recipient.id == @account.id || (!recipient.local? && !@account.local?) || recipient.following?(@account)) if @options[:reaction_type] == 'emoji_reaction' - enum_match?(:reaction_type, @options[:reaction_type], @ng_rule.reaction_type) && - text_match?(:emoji_reaction_name, @options[:emoji_reaction_name], @ng_rule.emoji_reaction_name) && - text_match?(:emoji_reaction_origin_domain, @options[:emoji_reaction_origin_domain], @ng_rule.emoji_reaction_origin_domain) + result = enum_match?(:reaction_type, @options[:reaction_type], @ng_rule.reaction_type) && + text_match?(:emoji_reaction_name, @options[:emoji_reaction_name], @ng_rule.emoji_reaction_name) + + emoji_reaction_origin_domain = @options[:emoji_reaction_origin_domain] || Rails.configuration.x.local_domain + result && text_match?(:emoji_reaction_origin_domain, emoji_reaction_origin_domain, @ng_rule.emoji_reaction_origin_domain) else enum_match?(:reaction_type, @options[:reaction_type], @ng_rule.reaction_type) end diff --git a/spec/models/admin/ng_rule_spec.rb b/spec/models/admin/ng_rule_spec.rb index fb85e6e9bb..ccae8403b4 100644 --- a/spec/models/admin/ng_rule_spec.rb +++ b/spec/models/admin/ng_rule_spec.rb @@ -278,5 +278,35 @@ RSpec.describe Admin::NgRule do it_behaves_like 'matches rule', 'reaction' end + + context 'with emoji reaction origin domain' do + let(:account) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/actor') } + let(:ng_rule) { Fabricate(:ng_rule, reaction_type: ['emoji_reaction'], emoji_reaction_origin_domain: 'ohagi.com') } + + context 'when remote emoji matches domain' do + let(:options) { { uri: uri, recipient: Fabricate(:account), reaction_type: 'emoji_reaction', emoji_reaction_origin_domain: 'ohagi.com' } } + + it_behaves_like 'matches rule', 'reaction' + end + + context 'when remote emoji does not match domain' do + let(:options) { { uri: uri, recipient: Fabricate(:account), reaction_type: 'emoji_reaction', emoji_reaction_origin_domain: 'test.com' } } + + it_behaves_like 'does not match rule' + end + + context 'when local emoji' do + let(:options) { { uri: uri, recipient: Fabricate(:account), reaction_type: 'emoji_reaction', emoji_reaction_origin_domain: nil } } + + it_behaves_like 'does not match rule' + end + + context 'when local emoji but all options match' do + let(:ng_rule) { Fabricate(:ng_rule, reaction_type: ['emoji_reaction']) } + let(:options) { { uri: uri, recipient: Fabricate(:account), reaction_type: 'emoji_reaction', emoji_reaction_origin_domain: nil } } + + it_behaves_like 'matches rule', 'reaction' + end + end end end