macro.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. class Macro < ApplicationModel
  3. include ChecksClientNotification
  4. include ChecksHtmlSanitized
  5. include CanSeed
  6. include HasCollectionUpdate
  7. include HasSearchIndexBackend
  8. include CanSelector
  9. include CanSearch
  10. include Macro::TriggersSubscriptions
  11. include HasOptionalGroups
  12. store :perform
  13. validates :perform, 'validations/verify_perform_rules': true
  14. validates :name, presence: true, uniqueness: { case_sensitive: false }
  15. validates :ux_flow_next_up, inclusion: { in: %w[none next_task next_task_on_close next_from_overview] }
  16. validates :note, length: { maximum: 250 }
  17. sanitized_html :note
  18. collection_push_permission('ticket.agent')
  19. ApplicableOn = Struct.new(:result, :blocking_tickets) do
  20. delegate :==, to: :result
  21. delegate :!, to: :result
  22. def error_message
  23. "Macro blocked by: #{blocking_tickets.join(', ')}"
  24. end
  25. end
  26. def applicable_on?(tickets)
  27. tickets = Array(tickets)
  28. return ApplicableOn.new(true, []) if group_ids.blank?
  29. blocking = tickets.reject { |elem| group_ids.include? elem.group_id }
  30. ApplicableOn.new(blocking.none?, blocking)
  31. end
  32. def performable_on?(object, activator_type:)
  33. return false if !active
  34. return true if group_ids.blank?
  35. group_ids.include? object.group_id
  36. end
  37. end