From 2a474c89066d9dfa65abc3997b9ab1a69400f774 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: Sun, 22 Oct 2023 09:46:19 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=E4=BB=96=E3=81=AE=E3=82=B5=E3=83=BC?= =?UTF-8?q?=E3=83=90=E3=83=BC=E5=90=8C=E5=A3=AB=E3=81=AE=E3=82=B9=E3=82=BF?= =?UTF-8?q?=E3=83=B3=E3=83=97=E3=81=A7`emoji=5Freaction=5Fpolicy`=E3=81=8C?= =?UTF-8?q?=E9=81=A9=E7=94=A8=E3=81=95=E3=82=8C=E3=82=8B=E5=95=8F=E9=A1=8C?= =?UTF-8?q?=20(#165)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: 他のサーバー同士のスタンプで`emoji_reaction_policy`が適用される問題 * こっちに変更 * #161 テストを追加 * テスト修正 --- app/models/account.rb | 1 + spec/models/account_spec.rb | 201 ++++++++++++++++++++++++++++++++++++ 2 files changed, 202 insertions(+) diff --git a/app/models/account.rb b/app/models/account.rb index 5ff438839dbc83..51f2e699715a3d 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -392,6 +392,7 @@ def show_emoji_reaction?(account) def allow_emoji_reaction?(account) return false if account.nil? + return true unless local? || account.local? show_emoji_reaction?(account) end diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index c13d57c7614cc1..5cdc31ecd94358 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -246,6 +246,207 @@ end end + describe '#allow_emoji_reaction?' do + let(:policy) { :allow } + let(:reactioned) { Fabricate(:user, settings: { emoji_reaction_policy: policy }).account } + let(:followee) { Fabricate(:account) } + let(:follower) { Fabricate(:account) } + let(:mutual) { Fabricate(:account) } + let(:anyone) { Fabricate(:account) } + + before do + follower.follow!(reactioned) + reactioned.follow!(followee) + mutual.follow!(reactioned) + reactioned.follow!(mutual) + end + + context 'when policy is arrow' do + it 'allows anyone' do + expect(reactioned.allow_emoji_reaction?(anyone)).to be true + end + + it 'allows followee' do + expect(reactioned.allow_emoji_reaction?(followee)).to be true + end + + it 'allows follower' do + expect(reactioned.allow_emoji_reaction?(follower)).to be true + end + + it 'allows mutual' do + expect(reactioned.allow_emoji_reaction?(mutual)).to be true + end + + it 'allows self' do + expect(reactioned.allow_emoji_reaction?(reactioned)).to be true + end + end + + context 'when policy is following_only' do + let(:policy) { :following_only } + + it 'allows anyone' do + expect(reactioned.allow_emoji_reaction?(anyone)).to be false + end + + it 'allows followee' do + expect(reactioned.allow_emoji_reaction?(followee)).to be true + end + + it 'allows follower' do + expect(reactioned.allow_emoji_reaction?(follower)).to be false + end + + it 'allows mutual' do + expect(reactioned.allow_emoji_reaction?(mutual)).to be true + end + + it 'allows self' do + expect(reactioned.allow_emoji_reaction?(reactioned)).to be true + end + end + + context 'when policy is followers_only' do + let(:policy) { :followers_only } + + it 'allows anyone' do + expect(reactioned.allow_emoji_reaction?(anyone)).to be false + end + + it 'allows followee' do + expect(reactioned.allow_emoji_reaction?(followee)).to be false + end + + it 'allows follower' do + expect(reactioned.allow_emoji_reaction?(follower)).to be true + end + + it 'allows mutual' do + expect(reactioned.allow_emoji_reaction?(mutual)).to be true + end + + it 'allows self' do + expect(reactioned.allow_emoji_reaction?(reactioned)).to be true + end + end + + context 'when policy is mutuals_only' do + let(:policy) { :mutuals_only } + + it 'allows anyone' do + expect(reactioned.allow_emoji_reaction?(anyone)).to be false + end + + it 'allows followee' do + expect(reactioned.allow_emoji_reaction?(followee)).to be false + end + + it 'allows follower' do + expect(reactioned.allow_emoji_reaction?(follower)).to be false + end + + it 'allows mutual' do + expect(reactioned.allow_emoji_reaction?(mutual)).to be true + end + + it 'allows self' do + expect(reactioned.allow_emoji_reaction?(reactioned)).to be true + end + end + + context 'when policy is outside_only' do + let(:policy) { :outside_only } + + it 'allows anyone' do + expect(reactioned.allow_emoji_reaction?(anyone)).to be false + end + + it 'allows followee' do + expect(reactioned.allow_emoji_reaction?(followee)).to be true + end + + it 'allows follower' do + expect(reactioned.allow_emoji_reaction?(follower)).to be true + end + + it 'allows mutual' do + expect(reactioned.allow_emoji_reaction?(mutual)).to be true + end + + it 'allows self' do + expect(reactioned.allow_emoji_reaction?(reactioned)).to be true + end + end + + context 'when policy is block' do + let(:policy) { :block } + + it 'allows anyone' do + expect(reactioned.allow_emoji_reaction?(anyone)).to be false + end + + it 'allows followee' do + expect(reactioned.allow_emoji_reaction?(followee)).to be false + end + + it 'allows follower' do + expect(reactioned.allow_emoji_reaction?(follower)).to be false + end + + it 'allows mutual' do + expect(reactioned.allow_emoji_reaction?(mutual)).to be false + end + + it 'allows self' do + expect(reactioned.allow_emoji_reaction?(reactioned)).to be false + end + end + + context 'when reactioned is remote user' do + let(:reactioned) { Fabricate(:account, domain: 'foo.bar', uri: 'https://foo.bar/actor', settings: { emoji_reaction_policy: :following_only }) } + + it 'allows anyone' do + expect(reactioned.allow_emoji_reaction?(anyone)).to be false + end + + it 'allows followee' do + expect(reactioned.allow_emoji_reaction?(followee)).to be true + end + end + + context 'when reactor is remote user' do + let(:anyone) { Fabricate(:account, domain: 'foo.bar', uri: 'https://foo.bar/actor/anyone') } + let(:policy) { :following_only } + + it 'allows anyone' do + expect(reactioned.allow_emoji_reaction?(anyone)).to be false + end + + it 'allows followee' do + expect(reactioned.allow_emoji_reaction?(followee)).to be true + end + end + + context 'when both are remote user' do + let(:reactioned) { Fabricate(:account, domain: 'foo.bar', uri: 'https://foo.bar/actor', settings: { emoji_reaction_policy: policy }) } + let(:anyone) { Fabricate(:account, domain: 'foo.bar', uri: 'https://foo.bar/actor/anyone') } + let(:followee) { Fabricate(:account, domain: 'foo.bar', uri: 'https://foo.bar/actor/followee') } + + it 'allows anyone' do + expect(reactioned.allow_emoji_reaction?(anyone)).to be true + end + + context 'with blocking' do + let(:policy) { :block } + + it 'allows anyone' do + expect(reactioned.allow_emoji_reaction?(anyone)).to be true + end + end + end + end + describe '#favourited?' do subject { Fabricate(:account) }