reset_new_state.rb 1012 B

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. class Observer::Ticket::ResetNewState < ActiveRecord::Observer
  3. observe 'ticket::_article'
  4. def after_create(record)
  5. # puts 'check reset new state'
  6. # return if we run import mode
  7. return if Setting.get('import_mode')
  8. # if article in internal
  9. return true if record.internal
  10. # if sender is agent
  11. return true if Ticket::Article::Sender.lookup( :id => record.sender_id ).name != 'Agent'
  12. # if article is a message to customer
  13. return true if !Ticket::Article::Type.lookup( :id => record.type_id ).communication
  14. # if current ticket state is still new
  15. ticket = Ticket.lookup( :id => record.ticket_id )
  16. return true if ticket.state.state_type.name != 'new'
  17. # TODO: add config option to state managment in UI
  18. state = Ticket::State.lookup( :name => 'open' )
  19. return if !state
  20. # set ticket to open
  21. ticket.state_id = state.id
  22. # save ticket
  23. ticket.save
  24. end
  25. end