From a27bafa59653328a0f06bedb1dfb2b6ee92af43d Mon Sep 17 00:00:00 2001
From: Matt Jankowski <matt@jankowski.online>
Date: Tue, 26 Nov 2024 04:45:47 -0500
Subject: [PATCH] Add `UserRole#bypass_block?` method for notification check
 (#32974)

---
 app/models/user_role.rb        | 4 ++++
 app/services/notify_service.rb | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/app/models/user_role.rb b/app/models/user_role.rb
index 23cc28b9b..815a89408 100644
--- a/app/models/user_role.rb
+++ b/app/models/user_role.rb
@@ -142,6 +142,10 @@ class UserRole < ApplicationRecord
     other_role.nil? || position > other_role.position
   end
 
+  def bypass_block?(role)
+    overrides?(role) && highlighted? && can?(*Flags::CATEGORIES[:moderation])
+  end
+
   def computed_permissions
     # If called on the everyone role, no further computation needed
     return permissions if everyone?
diff --git a/app/services/notify_service.rb b/app/services/notify_service.rb
index 0cf56c5a2..e87e5024f 100644
--- a/app/services/notify_service.rb
+++ b/app/services/notify_service.rb
@@ -134,7 +134,7 @@ class NotifyService < BaseService
     end
 
     def from_staff?
-      @sender.local? && @sender.user.present? && @sender.user_role&.overrides?(@recipient.user_role) && @sender.user_role&.highlighted? && @sender.user_role&.can?(*UserRole::Flags::CATEGORIES[:moderation])
+      @sender.local? && @sender.user.present? && @sender.user_role&.bypass_block?(@recipient.user_role)
     end
 
     def from_self?