edit.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class FormUpdater::Updater::Ticket::Edit < FormUpdater::Updater
  3. include FormUpdater::Concerns::ChecksCoreWorkflow
  4. include FormUpdater::Concerns::HasSecurityOptions
  5. core_workflow_screen 'edit'
  6. def resolve
  7. set_default_follow_up_state if !meta[:initial]
  8. super
  9. end
  10. def object_type
  11. ::Ticket
  12. end
  13. private
  14. def article_body_empty?
  15. !data.dig('article', 'body') || data['article']['body'].empty?
  16. end
  17. def state_changed?
  18. data['state_id'] != object.state.id
  19. end
  20. def customer?
  21. return false if current_user.permissions?('ticket.agent') && current_user.groups.access(:read).include?(object.group)
  22. return true if current_user.permissions?('ticket.customer')
  23. false
  24. end
  25. def set_resultant_field_values
  26. # Prevent multiple changes to the default follow-up state.
  27. result['isDefaultFollowUpStateSet'][:value] = true
  28. result['state_id'][:value] = ::Ticket::State.find_by(default_follow_up: true)&.id
  29. end
  30. # Ported from App.TicketZoom.setDefaultFollowUpState().
  31. def set_default_follow_up_state
  32. result_initialize_field('state_id')
  33. result_initialize_field('isDefaultFollowUpStateSet')
  34. # Set default state if body is present.
  35. return if article_body_empty?
  36. # And the state was not changed.
  37. return if state_changed?
  38. # And we are in the customer context.
  39. return if !customer?
  40. # And the default state was not set before.
  41. return if data['isDefaultFollowUpStateSet']
  42. # And only if the ticket is not in the default create state (e.g. "new").
  43. return if object.state.default_create
  44. set_resultant_field_values
  45. end
  46. end