2014-02-03 19:23:00 +00:00
|
|
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2013-01-04 08:10:36 +00:00
|
|
|
class Observer::Ticket::ResetNewState < ActiveRecord::Observer
|
|
|
|
observe 'ticket::_article'
|
|
|
|
|
|
|
|
def after_create(record)
|
|
|
|
|
|
|
|
# return if we run import mode
|
|
|
|
return if Setting.get('import_mode')
|
|
|
|
|
|
|
|
# if article in internal
|
|
|
|
return true if record.internal
|
|
|
|
|
|
|
|
# if sender is agent
|
2016-03-08 06:32:58 +00:00
|
|
|
return true if Ticket::Article::Sender.lookup(id: record.sender_id).name != 'Agent'
|
2013-01-04 08:10:36 +00:00
|
|
|
|
|
|
|
# if article is a message to customer
|
2016-03-08 06:32:58 +00:00
|
|
|
return true if !Ticket::Article::Type.lookup(id: record.type_id).communication
|
2013-01-04 08:10:36 +00:00
|
|
|
|
|
|
|
# if current ticket state is still new
|
2016-03-08 06:32:58 +00:00
|
|
|
ticket = Ticket.lookup(id: record.ticket_id)
|
2014-06-08 22:01:20 +00:00
|
|
|
return true if ticket.state.state_type.name != 'new'
|
2013-01-04 08:10:36 +00:00
|
|
|
|
|
|
|
# TODO: add config option to state managment in UI
|
2016-03-08 06:32:58 +00:00
|
|
|
state = Ticket::State.lookup(name: 'open')
|
2013-01-04 08:10:36 +00:00
|
|
|
return if !state
|
|
|
|
|
|
|
|
# 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
|