Fix logic of block/mute bypass for mentions from moderators (#31271)
This commit is contained in:
parent
33d5ef9f16
commit
f23993a9fd
2 changed files with 68 additions and 1 deletions
|
@ -52,7 +52,7 @@ class NotifyService < BaseService
|
||||||
end
|
end
|
||||||
|
|
||||||
def from_staff?
|
def from_staff?
|
||||||
@sender.local? && @sender.user.present? && @sender.user_role&.overrides?(@recipient.user_role)
|
@sender.local? && @sender.user.present? && @sender.user_role&.overrides?(@recipient.user_role) && @sender.user_role&.highlighted? && @sender.user_role&.can?(*UserRole::Flags::CATEGORIES[:moderation])
|
||||||
end
|
end
|
||||||
|
|
||||||
def from_self?
|
def from_self?
|
||||||
|
|
|
@ -129,6 +129,73 @@ RSpec.describe NotifyService do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when the blocked sender has a role' do
|
||||||
|
let(:sender) { Fabricate(:user, role: sender_role).account }
|
||||||
|
let(:activity) { Fabricate(:mention, status: Fabricate(:status, account: sender)) }
|
||||||
|
let(:type) { :mention }
|
||||||
|
|
||||||
|
before do
|
||||||
|
recipient.block!(sender)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the role is a visible moderator' do
|
||||||
|
let(:sender_role) { Fabricate(:user_role, highlighted: true, permissions: UserRole::FLAGS[:manage_users]) }
|
||||||
|
|
||||||
|
it 'does notify' do
|
||||||
|
expect { subject }.to change(Notification, :count)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the role is a non-visible moderator' do
|
||||||
|
let(:sender_role) { Fabricate(:user_role, highlighted: false, permissions: UserRole::FLAGS[:manage_users]) }
|
||||||
|
|
||||||
|
it 'does not notify' do
|
||||||
|
expect { subject }.to_not change(Notification, :count)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the role is a visible non-moderator' do
|
||||||
|
let(:sender_role) { Fabricate(:user_role, highlighted: true) }
|
||||||
|
|
||||||
|
it 'does not notify' do
|
||||||
|
expect { subject }.to_not change(Notification, :count)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with filtered notifications' do
|
||||||
|
let(:unknown) { Fabricate(:account, username: 'unknown') }
|
||||||
|
let(:status) { Fabricate(:status, account: unknown) }
|
||||||
|
let(:activity) { Fabricate(:mention, account: recipient, status: status) }
|
||||||
|
let(:type) { :mention }
|
||||||
|
|
||||||
|
before do
|
||||||
|
Fabricate(:notification_policy, account: recipient, filter_not_following: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates a filtered notification' do
|
||||||
|
expect { subject }.to change(Notification, :count)
|
||||||
|
expect(Notification.last).to be_filtered
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when no notification request exists' do
|
||||||
|
it 'creates a notification request' do
|
||||||
|
expect { subject }.to change(NotificationRequest, :count)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when a notification request exists' do
|
||||||
|
let!(:notification_request) do
|
||||||
|
Fabricate(:notification_request, account: recipient, from_account: unknown, last_status: Fabricate(:status, account: unknown))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'updates the existing notification request' do
|
||||||
|
expect { subject }.to_not change(NotificationRequest, :count)
|
||||||
|
expect(notification_request.reload.last_status).to eq status
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe NotifyService::DismissCondition do
|
describe NotifyService::DismissCondition do
|
||||||
subject { described_class.new(notification) }
|
subject { described_class.new(notification) }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue