macro.rb 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (C) 2012-2022 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 :name, presence: true
  9. validates :ux_flow_next_up, inclusion: { in: %w[none next_task next_task_on_close next_from_overview] }
  10. has_and_belongs_to_many :groups, after_add: :cache_update, after_remove: :cache_update, class_name: 'Group'
  11. sanitized_html :note
  12. collection_push_permission('ticket.agent')
  13. ApplicableOn = Struct.new(:result, :blocking_tickets) do
  14. delegate :==, to: :result
  15. delegate :!, to: :result
  16. def error_message
  17. "Macro blocked by: #{blocking_tickets.join(', ')}"
  18. end
  19. end
  20. def applicable_on?(tickets)
  21. tickets = Array(tickets)
  22. return ApplicableOn.new(true, []) if group_ids.blank?
  23. blocking = tickets.reject { |elem| group_ids.include? elem.group_id }
  24. ApplicableOn.new(blocking.none?, blocking)
  25. end
  26. end