@@ -54,6 +54,7 @@ def create_notification(
5454 no_users : bool = False , # noqa: FBT001
5555 url : str | None = None ,
5656 url_api : str | None = None ,
57+ alert_only : bool = False , # noqa: FBT001
5758 ** kwargs : dict ,
5859) -> None :
5960 """Create an instance of a NotificationManager and dispatch the notification."""
@@ -86,6 +87,7 @@ def create_notification(
8687 no_users = no_users ,
8788 url = url ,
8889 url_api = url_api ,
90+ alert_only = alert_only ,
8991 ** kwargs ,
9092 )
9193
@@ -802,61 +804,68 @@ def _process_notifications(
802804 )
803805 logger .debug ("process notifications for %s" , notifications .user )
804806
805- if self . system_settings . enable_slack_notifications and "slack" in getattr (
806- notifications ,
807- event ,
808- getattr ( notifications , "other" ),
809- ):
810- logger .debug ("Sending Slack Notification " )
811- self ._get_manager_instance ("slack " ).send_slack_notification (
807+ alert_only = kwargs . get ( "alert_only" , False )
808+ if alert_only :
809+ logger . debug ( "sending alert only" )
810+
811+ if "alert" in getattr ( notifications , event , getattr ( notifications , "other" ) ):
812+ logger .debug (f "Sending Alert to { notifications . user } " )
813+ self ._get_manager_instance ("alert " ).send_alert_notification (
812814 event ,
813815 user = notifications .user ,
814816 ** kwargs ,
815817 )
816818
817- if self .system_settings .enable_msteams_notifications and "msteams" in getattr (
818- notifications ,
819- event ,
820- getattr (notifications , "other" ),
821- ):
822- logger .debug ("Sending MSTeams Notification" )
823- self ._get_manager_instance ("msteams" ).send_msteams_notification (
819+ # Some errors should not be pushed to all channels, only to alerts.
820+ # For example reasons why JIRA Issues: https://github.com/DefectDojo/django-DefectDojo/issues/11575
821+ if not alert_only :
822+ if self .system_settings .enable_slack_notifications and "slack" in getattr (
823+ notifications ,
824824 event ,
825- user = notifications .user ,
826- ** kwargs ,
827- )
825+ getattr (notifications , "other" ),
826+ ):
827+ logger .debug ("Sending Slack Notification" )
828+ self ._get_manager_instance ("slack" ).send_slack_notification (
829+ event ,
830+ user = notifications .user ,
831+ ** kwargs ,
832+ )
828833
829- if self .system_settings .enable_mail_notifications and "mail" in getattr (
830- notifications ,
831- event ,
832- getattr (notifications , "other" ),
833- ):
834- logger .debug ("Sending Mail Notification" )
835- self ._get_manager_instance ("mail" ).send_mail_notification (
834+ if self .system_settings .enable_msteams_notifications and "msteams" in getattr (
835+ notifications ,
836836 event ,
837- user = notifications .user ,
838- ** kwargs ,
839- )
837+ getattr (notifications , "other" ),
838+ ):
839+ logger .debug ("Sending MSTeams Notification" )
840+ self ._get_manager_instance ("msteams" ).send_msteams_notification (
841+ event ,
842+ user = notifications .user ,
843+ ** kwargs ,
844+ )
840845
841- if self .system_settings .enable_webhooks_notifications and "webhooks" in getattr (
842- notifications ,
843- event ,
844- getattr (notifications , "other" ),
845- ):
846- logger .debug ("Sending Webhooks Notification" )
847- self ._get_manager_instance ("webhooks" ).send_webhooks_notification (
846+ if self .system_settings .enable_mail_notifications and "mail" in getattr (
847+ notifications ,
848848 event ,
849- user = notifications .user ,
850- ** kwargs ,
851- )
849+ getattr (notifications , "other" ),
850+ ):
851+ logger .debug ("Sending Mail Notification" )
852+ self ._get_manager_instance ("mail" ).send_mail_notification (
853+ event ,
854+ user = notifications .user ,
855+ ** kwargs ,
856+ )
852857
853- if "alert" in getattr (notifications , event , getattr (notifications , "other" )):
854- logger .debug (f"Sending Alert to { notifications .user } " )
855- self ._get_manager_instance ("alert" ).send_alert_notification (
858+ if self .system_settings .enable_webhooks_notifications and "webhooks" in getattr (
859+ notifications ,
856860 event ,
857- user = notifications .user ,
858- ** kwargs ,
859- )
861+ getattr (notifications , "other" ),
862+ ):
863+ logger .debug ("Sending Webhooks Notification" )
864+ self ._get_manager_instance ("webhooks" ).send_webhooks_notification (
865+ event ,
866+ user = notifications .user ,
867+ ** kwargs ,
868+ )
860869
861870
862871@app .task (ignore_result = True )
0 commit comments