diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-05-19 01:14:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-19 01:14:30 +0200 |
commit | 620d0d80293bef80753ecfcec1c4c5226e67cd6d (patch) | |
tree | 8e658e468fe72d4d876a4575dba4c39f6561a125 /spec | |
parent | 8ec8410651ad95ef1da4484497caf93899c31e9b (diff) |
Account domain blocks (#2381)
* Add <ostatus:conversation /> tag to Atom input/output Only uses ref attribute (not href) because href would be the alternate link that's always included also. Creates new conversation for every non-reply status. Carries over conversation for every reply. Keeps remote URIs verbatim, generates local URIs on the fly like the rest of them. * Conversation muting - prevents notifications that reference a conversation (including replies, favourites, reblogs) from being created. API endpoints /api/v1/statuses/:id/mute and /api/v1/statuses/:id/unmute Currently no way to tell when a status/conversation is muted, so the web UI only has a "disable notifications" button, doesn't work as a toggle * Display "Dismiss notifications" on all statuses in notifications column, not just own * Add "muted" as a boolean attribute on statuses JSON For now always false on contained reblogs, since it's only relevant for statuses returned from the notifications endpoint, which are not nested Remove "Disable notifications" from detailed status view, since it's only relevant in the notifications column * Up max class length * Remove pending test for conversation mute * Add tests, clean up * Rename to "mute conversation" and "unmute conversation" * Raise validation error when trying to mute/unmute status without conversation * Adding account domain blocks that filter notifications and public timelines * Add tests for domain blocks in notifications, public timelines Filter reblogs of blocked domains from home * Add API for listing and creating account domain blocks * API for creating/deleting domain blocks, tests for Status#ancestors and Status#descendants, filter domain blocks from them * Filter domains in streaming API * Update account_domain_block_spec.rb
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/api/v1/domain_blocks_controller_spec.rb | 55 | ||||
-rw-r--r-- | spec/controllers/api/v1/media_controller_spec.rb | 1 | ||||
-rw-r--r-- | spec/fabricators/account_domain_block_fabricator.rb | 4 | ||||
-rw-r--r-- | spec/lib/feed_manager_spec.rb | 10 | ||||
-rw-r--r-- | spec/models/account_domain_block_spec.rb | 5 | ||||
-rw-r--r-- | spec/models/status_spec.rb | 93 | ||||
-rw-r--r-- | spec/services/notify_service_spec.rb | 7 |
7 files changed, 169 insertions, 6 deletions
diff --git a/spec/controllers/api/v1/domain_blocks_controller_spec.rb b/spec/controllers/api/v1/domain_blocks_controller_spec.rb new file mode 100644 index 000000000..c3331744d --- /dev/null +++ b/spec/controllers/api/v1/domain_blocks_controller_spec.rb @@ -0,0 +1,55 @@ +require 'rails_helper' + +RSpec.describe Api::V1::DomainBlocksController, type: :controller do + render_views + + let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) } + let(:token) { double acceptable?: true, resource_owner_id: user.id } + + before do + user.account.block_domain!('example.com') + allow(controller).to receive(:doorkeeper_token) { token } + end + + describe 'GET #show' do + before do + get :show + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'returns blocked domains' do + expect(body_as_json.first).to eq 'example.com' + end + end + + describe 'POST #create' do + before do + post :create, params: { domain: 'example.org' } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'creates a domain block' do + expect(user.account.domain_blocking?('example.org')).to be true + end + end + + describe 'DELETE #destroy' do + before do + delete :destroy, params: { domain: 'example.com' } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'deletes a domain block' do + expect(user.account.domain_blocking?('example.com')).to be false + end + end +end diff --git a/spec/controllers/api/v1/media_controller_spec.rb b/spec/controllers/api/v1/media_controller_spec.rb index c2d333282..b1d9798ea 100644 --- a/spec/controllers/api/v1/media_controller_spec.rb +++ b/spec/controllers/api/v1/media_controller_spec.rb @@ -55,7 +55,6 @@ RSpec.describe Api::V1::MediaController, type: :controller do end end - context 'video/webm' do before do post :create, params: { file: fixture_file_upload('files/attachment.webm', 'video/webm') } diff --git a/spec/fabricators/account_domain_block_fabricator.rb b/spec/fabricators/account_domain_block_fabricator.rb new file mode 100644 index 000000000..fbbddadd5 --- /dev/null +++ b/spec/fabricators/account_domain_block_fabricator.rb @@ -0,0 +1,4 @@ +Fabricator(:account_domain_block) do + account_id 1 + domain "MyString" +end diff --git a/spec/lib/feed_manager_spec.rb b/spec/lib/feed_manager_spec.rb index 16b1e7377..bf474c354 100644 --- a/spec/lib/feed_manager_spec.rb +++ b/spec/lib/feed_manager_spec.rb @@ -11,7 +11,7 @@ RSpec.describe FeedManager do describe '#filter?' do let(:alice) { Fabricate(:account, username: 'alice') } - let(:bob) { Fabricate(:account, username: 'bob') } + let(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') } let(:jeff) { Fabricate(:account, username: 'jeff') } context 'for home feed' do @@ -93,6 +93,14 @@ RSpec.describe FeedManager do status = PostStatusService.new.call(alice, 'Hey @jeff') expect(FeedManager.instance.filter?(:home, status, bob.id)).to be true end + + it 'returns true for reblog of a personally blocked domain' do + alice.block_domain!('example.com') + alice.follow!(jeff) + status = Fabricate(:status, text: 'Hello world', account: bob) + reblog = Fabricate(:status, reblog: status, account: jeff) + expect(FeedManager.instance.filter?(:home, reblog, alice.id)).to be true + end end context 'for mentions feed' do diff --git a/spec/models/account_domain_block_spec.rb b/spec/models/account_domain_block_spec.rb new file mode 100644 index 000000000..bd64e10fb --- /dev/null +++ b/spec/models/account_domain_block_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe AccountDomainBlock, type: :model do + +end diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb index d4f85b725..97ed94149 100644 --- a/spec/models/status_spec.rb +++ b/spec/models/status_spec.rb @@ -180,8 +180,48 @@ RSpec.describe Status, type: :model do end describe '#ancestors' do + let!(:alice) { Fabricate(:account, username: 'alice') } + let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') } + let!(:jeff) { Fabricate(:account, username: 'jeff') } + let!(:status) { Fabricate(:status, account: alice) } + let!(:reply1) { Fabricate(:status, thread: status, account: jeff) } + let!(:reply2) { Fabricate(:status, thread: reply1, account: bob) } + let!(:reply3) { Fabricate(:status, thread: reply2, account: alice) } + let!(:viewer) { Fabricate(:account, username: 'viewer') } + + it 'returns conversation history' do + expect(reply3.ancestors).to include(status, reply1, reply2) + end + + it 'does not return conversation history user is not allowed to see' do + reply1.update(visibility: :private) + status.update(visibility: :direct) + + expect(reply3.ancestors(viewer)).to_not include(reply1, status) + end + + it 'does not return conversation history from blocked users' do + viewer.block!(jeff) + expect(reply3.ancestors(viewer)).to_not include(reply1) + end + + it 'does not return conversation history from muted users' do + viewer.mute!(jeff) + expect(reply3.ancestors(viewer)).to_not include(reply1) + end + + it 'does not return conversation history from silenced and not followed users' do + jeff.update(silenced: true) + expect(reply3.ancestors(viewer)).to_not include(reply1) + end + + it 'does not return conversation history from blocked domains' do + viewer.block_domain!('example.com') + expect(reply3.ancestors(viewer)).to_not include(reply2) + end + it 'ignores deleted records' do - first_status = Fabricate(:status, account: bob) + first_status = Fabricate(:status, account: bob) second_status = Fabricate(:status, thread: first_status, account: alice) # Create cache and delete cached record @@ -192,8 +232,46 @@ RSpec.describe Status, type: :model do end end - describe '#filter_from_context?' do - pending + describe '#descendants' do + let!(:alice) { Fabricate(:account, username: 'alice') } + let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') } + let!(:jeff) { Fabricate(:account, username: 'jeff') } + let!(:status) { Fabricate(:status, account: alice) } + let!(:reply1) { Fabricate(:status, thread: status, account: alice) } + let!(:reply2) { Fabricate(:status, thread: status, account: bob) } + let!(:reply3) { Fabricate(:status, thread: reply1, account: jeff) } + let!(:viewer) { Fabricate(:account, username: 'viewer') } + + it 'returns replies' do + expect(status.descendants).to include(reply1, reply2, reply3) + end + + it 'does not return replies user is not allowed to see' do + reply1.update(visibility: :private) + reply3.update(visibility: :direct) + + expect(status.descendants(viewer)).to_not include(reply1, reply3) + end + + it 'does not return replies from blocked users' do + viewer.block!(jeff) + expect(status.descendants(viewer)).to_not include(reply3) + end + + it 'does not return replies from muted users' do + viewer.mute!(jeff) + expect(status.descendants(viewer)).to_not include(reply3) + end + + it 'does not return replies from silenced and not followed users' do + jeff.update(silenced: true) + expect(status.descendants(viewer)).to_not include(reply3) + end + + it 'does not return replies from blocked domains' do + viewer.block_domain!('example.com') + expect(status.descendants(viewer)).to_not include(reply2) + end end describe '.mutes_map' do @@ -368,6 +446,15 @@ RSpec.describe Status, type: :model do expect(results).not_to include(muted_status) end + it 'excludes statuses from accounts from personally blocked domains' do + blocked = Fabricate(:account, domain: 'example.com') + @account.block_domain!(blocked.domain) + blocked_status = Fabricate(:status, account: blocked) + + results = Status.as_public_timeline(@account) + expect(results).not_to include(blocked_status) + end + context 'with language preferences' do it 'excludes statuses in languages not allowed by the account user' do user = Fabricate(:user, allowed_languages: [:en, :es]) diff --git a/spec/services/notify_service_spec.rb b/spec/services/notify_service_spec.rb index 032c37a28..29bd741aa 100644 --- a/spec/services/notify_service_spec.rb +++ b/spec/services/notify_service_spec.rb @@ -7,7 +7,7 @@ RSpec.describe NotifyService do let(:user) { Fabricate(:user) } let(:recipient) { user.account } - let(:sender) { Fabricate(:account) } + let(:sender) { Fabricate(:account, domain: 'example.com') } let(:activity) { Fabricate(:follow, account: sender, target_account: recipient) } it { is_expected.to change(Notification, :count).by(1) } @@ -17,6 +17,11 @@ RSpec.describe NotifyService do is_expected.to_not change(Notification, :count) end + it 'does not notify when sender\'s domain is blocked' do + recipient.block_domain!(sender.domain) + is_expected.to_not change(Notification, :count) + end + it 'does not notify when sender is silenced and not followed' do sender.update(silenced: true) is_expected.to_not change(Notification, :count) |