Просмотр исходного кода

Fixes #4885 - Trigger does not send emails when target user gets more than 30 mails in the last 10 minutes.

Co-authored-by: Dominik Klein <dk@zammad.com>
Rolf Schmidt 1 год назад
Родитель
Сommit
6a9f800135
4 измененных файлов с 105 добавлено и 16 удалено
  1. 4 16
      app/models/ticket.rb
  2. 47 0
      db/migrate/20231017091313_loop_protection_settings.rb
  3. 38 0
      db/seeds/settings.rb
  4. 16 0
      i18n/zammad.pot

+ 4 - 16
app/models/ticket.rb

@@ -1190,13 +1190,7 @@ returns a hex color code
       end
 
       # loop protection / check if maximal count of trigger mail has reached
-      map = {
-        10  => 10,
-        30  => 15,
-        60  => 25,
-        180 => 50,
-        600 => 100,
-      }
+      map = Setting.get('ticket_trigger_loop_protection_articles_per_ticket')
       skip = false
       map.each do |minutes, count|
         already_sent = Ticket::Article.where(
@@ -1206,19 +1200,13 @@ returns a hex color code
         ).where('ticket_articles.created_at > ? AND ticket_articles.to LIKE ?', Time.zone.now - minutes.minutes, "%#{SqlHelper.quote_like(recipient_email.strip)}%").count
         next if already_sent < count
 
-        logger.info "Send no trigger based notification to #{recipient_email} because already sent #{count} for this ticket within last #{minutes} minutes (loop protection)"
+        logger.error "Send no trigger based notification to #{recipient_email} because already sent #{count} for this ticket within last #{minutes} minutes (loop protection set by setting ticket_trigger_loop_protection_articles_per_ticket)"
         skip = true
         break
       end
       next if skip
 
-      map = {
-        10  => 30,
-        30  => 60,
-        60  => 120,
-        180 => 240,
-        600 => 360,
-      }
+      map = Setting.get('ticket_trigger_loop_protection_articles_total')
       skip = false
       map.each do |minutes, count|
         already_sent = Ticket::Article.where(
@@ -1227,7 +1215,7 @@ returns a hex color code
         ).where('ticket_articles.created_at > ? AND ticket_articles.to LIKE ?', Time.zone.now - minutes.minutes, "%#{SqlHelper.quote_like(recipient_email.strip)}%").count
         next if already_sent < count
 
-        logger.info "Send no trigger based notification to #{recipient_email} because already sent #{count} in total within last #{minutes} minutes (loop protection)"
+        logger.error "Send no trigger based notification to #{recipient_email} because already sent #{count} in total within last #{minutes} minutes (loop protection set by setting ticket_trigger_loop_protection_articles_total)"
         skip = true
         break
       end

+ 47 - 0
db/migrate/20231017091313_loop_protection_settings.rb

@@ -0,0 +1,47 @@
+# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
+
+class LoopProtectionSettings < ActiveRecord::Migration[7.0]
+  def change
+    # return if it's a new setup
+    return if !Setting.exists?(name: 'system_init_done')
+
+    Setting.create_if_not_exists(
+      title:       'Ticket Trigger Loop Protection Articles per Ticket',
+      name:        'ticket_trigger_loop_protection_articles_per_ticket',
+      area:        'Ticket::Core',
+      description: 'Defines the configuration how many articles can be created in a minute range per ticket.',
+      options:     {},
+      state:       {
+        10  => 10,
+        30  => 15,
+        60  => 25,
+        180 => 50,
+        600 => 100,
+      },
+      preferences: {
+        permission: ['admin.ticket'],
+        hidden:     true,
+      },
+      frontend:    false
+    )
+    Setting.create_if_not_exists(
+      title:       'Ticket Trigger Loop Protection Articles Total',
+      name:        'ticket_trigger_loop_protection_articles_total',
+      area:        'Ticket::Core',
+      description: 'Defines the configuration how many articles can be created in a minute range globally.',
+      options:     {},
+      state:       {
+        10  => 30,
+        30  => 60,
+        60  => 120,
+        180 => 240,
+        600 => 360,
+      },
+      preferences: {
+        permission: ['admin.ticket'],
+        hidden:     true,
+      },
+      frontend:    false
+    )
+  end
+end

+ 38 - 0
db/seeds/settings.rb

@@ -2678,6 +2678,44 @@ Setting.create_if_not_exists(
   },
   frontend:    false
 )
+Setting.create_if_not_exists(
+  title:       __('Ticket Trigger Loop Protection Articles per Ticket'),
+  name:        'ticket_trigger_loop_protection_articles_per_ticket',
+  area:        'Ticket::Core',
+  description: __('Defines the configuration how many articles can be created in a minute range per ticket.'),
+  options:     {},
+  state:       {
+    10  => 10,
+    30  => 15,
+    60  => 25,
+    180 => 50,
+    600 => 100,
+  },
+  preferences: {
+    permission: ['admin.ticket'],
+    hidden:     true,
+  },
+  frontend:    false
+)
+Setting.create_if_not_exists(
+  title:       __('Ticket Trigger Loop Protection Articles Total'),
+  name:        'ticket_trigger_loop_protection_articles_total',
+  area:        'Ticket::Core',
+  description: __('Defines the configuration how many articles can be created in a minute range globally.'),
+  options:     {},
+  state:       {
+    10  => 30,
+    30  => 60,
+    60  => 120,
+    180 => 240,
+    600 => 360,
+  },
+  preferences: {
+    permission: ['admin.ticket'],
+    hidden:     true,
+  },
+  frontend:    false
+)
 Setting.create_if_not_exists(
   title:       __('Recursive Ticket Triggers Loop Max.'),
   name:        'ticket_trigger_recursive_max_loop',

+ 16 - 0
i18n/zammad.pot

@@ -3736,6 +3736,14 @@ msgstr ""
 msgid "Defines the backend for user and organization image lookups."
 msgstr ""
 
+#: db/seeds/settings.rb
+msgid "Defines the configuration how many articles can be created in a minute range globally."
+msgstr ""
+
+#: db/seeds/settings.rb
+msgid "Defines the configuration how many articles can be created in a minute range per ticket."
+msgstr ""
+
 #: db/seeds/settings.rb
 msgid "Defines the custom unit to be shown next to the time accounting input field."
 msgstr ""
@@ -12305,6 +12313,14 @@ msgstr ""
 msgid "Ticket Subscriptions"
 msgstr ""
 
+#: db/seeds/settings.rb
+msgid "Ticket Trigger Loop Protection Articles Total"
+msgstr ""
+
+#: db/seeds/settings.rb
+msgid "Ticket Trigger Loop Protection Articles per Ticket"
+msgstr ""
+
 #: app/frontend/apps/mobile/pages/ticket/components/TicketDetailView/TicketActionsDialog.vue
 msgid "Ticket actions"
 msgstr ""