macro.rb 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
  2. class Macro < ApplicationModel
  3. include ChecksClientNotification
  4. include ChecksHtmlSanitized
  5. include ChecksLatestChangeObserved
  6. include CanSeed
  7. include HasCollectionUpdate
  8. store :perform
  9. validates :name, presence: true
  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. sanitized_html :note
  13. collection_push_permission('ticket.agent')
  14. ApplicableOn = Struct.new(:result, :blocking_tickets) do
  15. delegate :==, to: :result
  16. delegate :!, to: :result
  17. def error_message
  18. "Macro blocked by: #{blocking_tickets.join(', ')}"
  19. end
  20. end
  21. def applicable_on?(tickets)
  22. tickets = Array(tickets)
  23. return ApplicableOn.new(true, []) if group_ids.blank?
  24. blocking = tickets.reject { |elem| group_ids.include? elem.group_id }
  25. ApplicableOn.new(blocking.none?, blocking)
  26. end
  27. end