update.rb 996 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::Ticket::Update < Service::BaseWithCurrentUser
  3. include Service::Concerns::HandlesCoreWorkflow
  4. def execute(ticket:, ticket_data:)
  5. Pundit.authorize current_user, ticket, :update?
  6. set_core_workflow_information(ticket_data, ::Ticket, 'edit')
  7. article_data = ticket_data.delete(:article)
  8. ticket.with_lock do
  9. ticket.update!(ticket_data)
  10. create_article(ticket, article_data)
  11. end
  12. ticket
  13. end
  14. private
  15. def create_article(ticket, article_data)
  16. return if article_data.blank?
  17. preprocess_article_data! article_data
  18. Service::Ticket::Article::Create
  19. .new(current_user: current_user)
  20. .execute(article_data: article_data, ticket: ticket)
  21. end
  22. # Desktop UI supplies this data from frontend
  23. # Mobile UI leaves this processing for GraphQL
  24. def preprocess_article_data!(article_input)
  25. article_input[:from] = current_user.fullname
  26. end
  27. end