2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
# Reopens the ticket in case certain new articles are created.
|
|
|
|
module Ticket::Article::ResetsTicketState
|
|
|
|
extend ActiveSupport::Concern
|
2013-01-04 08:10:36 +00:00
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
included do
|
|
|
|
after_create :ticket_article_reset_ticket_state
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def ticket_article_reset_ticket_state
|
2013-01-04 08:10:36 +00:00
|
|
|
|
|
|
|
# return if we run import mode
|
2018-06-12 11:59:18 +00:00
|
|
|
return true if Setting.get('import_mode')
|
2013-01-04 08:10:36 +00:00
|
|
|
|
2017-09-27 18:12:21 +00:00
|
|
|
# only change state if not processed via postmaster
|
2018-06-12 11:59:18 +00:00
|
|
|
return true if ApplicationHandleInfo.postmaster?
|
2017-09-27 18:12:21 +00:00
|
|
|
|
2013-01-04 08:10:36 +00:00
|
|
|
# if article in internal
|
2021-03-01 08:18:40 +00:00
|
|
|
return true if internal
|
2013-01-04 08:10:36 +00:00
|
|
|
|
|
|
|
# if sender is agent
|
2021-03-01 08:18:40 +00:00
|
|
|
return true if Ticket::Article::Sender.lookup(id: sender_id).name != 'Agent'
|
2013-01-04 08:10:36 +00:00
|
|
|
|
|
|
|
# if article is a message to customer
|
2021-03-01 08:18:40 +00:00
|
|
|
return true if !Ticket::Article::Type.lookup(id: type_id).communication
|
2013-01-04 08:10:36 +00:00
|
|
|
|
|
|
|
# if current ticket state is still new
|
2021-03-01 08:18:40 +00:00
|
|
|
ticket = Ticket.find_by(id: ticket_id)
|
2018-06-12 11:59:18 +00:00
|
|
|
return true if !ticket
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-02-12 17:21:03 +00:00
|
|
|
new_state = Ticket::State.find_by(default_create: true)
|
|
|
|
return true if ticket.state_id != new_state.id
|
2013-01-04 08:10:36 +00:00
|
|
|
|
2017-02-12 17:21:03 +00:00
|
|
|
state = Ticket::State.find_by(default_follow_up: true)
|
2018-06-12 11:59:18 +00:00
|
|
|
return true if !state
|
2013-01-04 08:10:36 +00:00
|
|
|
|
|
|
|
# set ticket to open
|
2014-06-08 22:01:20 +00:00
|
|
|
ticket.state_id = state.id
|
2013-01-04 08:10:36 +00:00
|
|
|
|
|
|
|
# save ticket
|
|
|
|
ticket.save
|
|
|
|
end
|
2013-06-12 15:59:58 +00:00
|
|
|
end
|