trabajo-afectivo/app/models/macro.rb

39 lines
1 KiB
Ruby
Raw Permalink Normal View History

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
include ChecksClientNotification
include ChecksHtmlSanitized
include ChecksLatestChangeObserved
2017-05-14 18:41:25 +00:00
include CanSeed
include HasCollectionUpdate
2015-10-15 13:23:41 +00:00
store :perform
validates :name, presence: true
validates :ux_flow_next_up, inclusion: { in: %w[none next_task next_task_on_close next_from_overview] }
has_and_belongs_to_many :groups, after_add: :cache_update, after_remove: :cache_update, class_name: 'Group'
sanitized_html :note
collection_push_permission('ticket.agent')
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