feat: disable automation rules if condition fails multiple times (#9017)
* feat: add email for disabling automation rule * feat: disable automation rules and notify admin * feat: reset error count after update * feat: trigger invalid_condition_error if rule is invalid * feat: setup error trackable concern * refactor: use ErrorTrackable in Reauthorizable * fix: optional argument * feat: separate reauthorization_required_key * test: update case to use ERROR_TRACKABLE_COUNT * Revert "test: update case to use ERROR_TRACKABLE_COUNT" This reverts commit f439847147556a02759a7597a7fcf1d66091cafc. * Revert "feat: separate reauthorization_required_key" This reverts commit f4514fce217b0a2f2c2bf701a15de0a8b47acbc4. * Revert "fix: optional argument" This reverts commit 93b4194ec3f10f67e2402388c966c071c4d3b4fd. * Revert "refactor: use ErrorTrackable in Reauthorizable" This reverts commit 513c2a522bc782e73ea4b0f5ae34ce01e70e042c. * Revert "feat: setup error trackable concern" This reverts commit 278683060cf422f60af5d5c77100aa5272141141. * feat: use reauthorizable for automation rule * feat: remove redis key * test: fix method names * chore: refactor --------- Co-authored-by: Vishnu Narayanan <iamwishnu@gmail.com> Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#
|
||||
class AutomationRule < ApplicationRecord
|
||||
include Rails.application.routes.url_helpers
|
||||
include Reauthorizable
|
||||
|
||||
belongs_to :account
|
||||
has_many_attached :files
|
||||
@@ -28,6 +29,8 @@ class AutomationRule < ApplicationRecord
|
||||
validate :query_operator_presence
|
||||
validates :account_id, presence: true
|
||||
|
||||
after_update_commit :reauthorized!, if: -> { saved_change_to_conditions? }
|
||||
|
||||
scope :active, -> { where(active: true) }
|
||||
|
||||
def conditions_attributes
|
||||
|
||||
@@ -50,6 +50,9 @@ module Reauthorizable
|
||||
mailer.whatsapp_disconnect(inbox).deliver_later
|
||||
when 'Channel::Email'
|
||||
mailer.email_disconnect(inbox).deliver_later
|
||||
when 'AutomationRule'
|
||||
update!(active: false)
|
||||
mailer.automation_rule_disabled(self).deliver_later
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user