checks_kb_client_notification.rb 990 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module ChecksKbClientNotification
  3. extend ActiveSupport::Concern
  4. included do
  5. after_commit :notify_kb_clients_after
  6. class_attribute :notify_kb_clients_suspend, default: false
  7. end
  8. def self.disable_in_all_classes!
  9. all_classes.each { |klass| klass.notify_kb_clients_suspend = true }
  10. end
  11. def self.enable_in_all_classes!
  12. all_classes.each { |klass| klass.notify_kb_clients_suspend = false }
  13. end
  14. def self.all_classes
  15. ActiveRecord::Base
  16. .descendants
  17. .select { |c| c.included_modules.include?(ChecksKbClientNotification) }
  18. end
  19. private
  20. # generic call
  21. def notify_kb_clients_after
  22. return if self.class.notify_kb_clients_suspend?
  23. # do not leak details about deleted items. See ChecksKbClientVisibilityJob
  24. # after_commit does not allow on: :touch
  25. return if destroyed?
  26. ChecksKbClientNotificationJob.perform_later(self.class.name, id)
  27. end
  28. end