Skip to content

Commit

Permalink
Fix logic of block/mute bypass for mentions from moderators (mastodon…
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored Aug 7, 2024
1 parent c8b9e60 commit 719cabe
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/services/notify_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def message?
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?
Expand Down
34 changes: 34 additions & 0 deletions spec/services/notify_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,40 @@
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) }
Expand Down

0 comments on commit 719cabe

Please sign in to comment.