macro.rb 1.2 KB

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