update.rb 784 B

12345678910111213141516171819202122232425262728
  1. # Copyright (C) 2012-2023 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) if article_data.present?
  11. end
  12. ticket
  13. end
  14. private
  15. def create_article(ticket, article_data)
  16. return if article_data.blank?
  17. Service::Ticket::Article::Create.new(current_user: current_user).execute(article_data: article_data.to_h.merge!(ticket_id: ticket.id))
  18. end
  19. end