From 719cabe024e87fcc5cc57d3ec66de956af2d3db7 Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 7 Aug 2024 08:52:10 +0200 Subject: [PATCH] Fix logic of block/mute bypass for mentions from moderators (#31271) --- app/services/notify_service.rb | 2 +- spec/services/notify_service_spec.rb | 34 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/services/notify_service.rb b/app/services/notify_service.rb index 23f92c816b..b0bef8cd65 100644 --- a/app/services/notify_service.rb +++ b/app/services/notify_service.rb @@ -48,7 +48,7 @@ class NotifyService < BaseService end 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 def from_self? diff --git a/spec/services/notify_service_spec.rb b/spec/services/notify_service_spec.rb index c7e00129b2..d64cfe5907 100644 --- a/spec/services/notify_service_spec.rb +++ b/spec/services/notify_service_spec.rb @@ -129,6 +129,40 @@ RSpec.describe NotifyService do 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) }