create.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class FormUpdater::Updater::Ticket::Create < FormUpdater::Updater
  3. include FormUpdater::Concerns::AppliesTaskbarState
  4. include FormUpdater::Concerns::AppliesTicketTemplate
  5. include FormUpdater::Concerns::AppliesTicketSharedDraft
  6. include FormUpdater::Concerns::AppliesSplitTicketArticle
  7. include FormUpdater::Concerns::ChecksCoreWorkflow
  8. include FormUpdater::Concerns::HasSecurityOptions
  9. include FormUpdater::Concerns::ProvidesInitialValues
  10. include FormUpdater::Concerns::StoresTaskbarState
  11. core_workflow_screen 'create_middle'
  12. def object_type
  13. ::Ticket
  14. end
  15. def initial_values
  16. values = {
  17. 'priority_id' => ::Ticket::Priority.find_by(default_create: true)&.id
  18. }
  19. customer_id = meta.dig(:additional_data, 'customer_id')
  20. customer_user = ::User.find_by(id: customer_id)
  21. if customer_user
  22. values['customer_id'] = customer_id
  23. customer_object = customer_user.attributes
  24. .slice('active', 'email', 'firstname', 'fullname', 'image', 'lastname', 'mobile', 'out_of_office', 'out_of_office_end_at', 'out_of_office_start_at', 'phone', 'source', 'vip')
  25. .merge({
  26. '__typename' => 'User',
  27. 'id' => Gql::ZammadSchema.id_from_internal_id('User', customer_id),
  28. })
  29. # For customer_id we need also to add the user as an option.
  30. # TODO: maybe we can have some generic way for this, because we are also have it in other places (e.g. applies tempalte).
  31. result['customer_id'] ||= {}
  32. result['customer_id'][:options] = [{
  33. value: customer_id,
  34. label: customer_user.fullname.presence || customer_user.phone.presence || customer_user.login,
  35. heading: customer_user.organization&.name,
  36. object: customer_object
  37. }]
  38. end
  39. values
  40. end
  41. end