2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2015-10-15 13:23:41 +00:00
|
|
|
|
|
|
|
class Macro < ApplicationModel
|
2017-05-02 15:21:13 +00:00
|
|
|
include ChecksClientNotification
|
2021-04-12 09:49:26 +00:00
|
|
|
include ChecksHtmlSanitized
|
2017-05-02 15:21:13 +00:00
|
|
|
include ChecksLatestChangeObserved
|
2017-05-14 18:41:25 +00:00
|
|
|
include CanSeed
|
2020-02-20 13:34:03 +00:00
|
|
|
include HasCollectionUpdate
|
2017-01-31 17:13:45 +00:00
|
|
|
|
2015-10-15 13:23:41 +00:00
|
|
|
store :perform
|
|
|
|
validates :name, presence: true
|
2021-09-09 12:35:00 +00:00
|
|
|
validates :ux_flow_next_up, inclusion: { in: %w[none next_task next_task_on_close next_from_overview] }
|
2019-09-04 07:42:50 +00:00
|
|
|
|
|
|
|
has_and_belongs_to_many :groups, after_add: :cache_update, after_remove: :cache_update, class_name: 'Group'
|
2020-02-20 13:34:03 +00:00
|
|
|
|
2021-04-12 09:49:26 +00:00
|
|
|
sanitized_html :note
|
|
|
|
|
2020-02-20 13:34:03 +00:00
|
|
|
collection_push_permission('ticket.agent')
|
2021-12-20 13:02:30 +00:00
|
|
|
|
|
|
|
ApplicableOn = Struct.new(:result, :blocking_tickets) do
|
|
|
|
delegate :==, to: :result
|
|
|
|
delegate :!, to: :result
|
|
|
|
|
|
|
|
def error_message
|
|
|
|
"Macro blocked by: #{blocking_tickets.join(', ')}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def applicable_on?(tickets)
|
|
|
|
tickets = Array(tickets)
|
|
|
|
|
|
|
|
return ApplicableOn.new(true, []) if group_ids.blank?
|
|
|
|
|
|
|
|
blocking = tickets.reject { |elem| group_ids.include? elem.group_id }
|
|
|
|
|
|
|
|
ApplicableOn.new(blocking.none?, blocking)
|
|
|
|
end
|
2015-10-15 13:23:41 +00:00
|
|
|
end
|