Skip to content

Commit

Permalink
Fix: 他のサーバー同士のスタンプでemoji_reaction_policyが適用される問題 (#165)
Browse files Browse the repository at this point in the history
* Fix: 他のサーバー同士のスタンプで`emoji_reaction_policy`が適用される問題

* こっちに変更

* #161 テストを追加

* テスト修正
  • Loading branch information
kmycode committed Oct 22, 2023
1 parent a87f6f4 commit 2a474c8
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
201 changes: 201 additions & 0 deletions spec/models/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down

0 comments on commit 2a474c8

Please sign in to comment.