applies_ticket_template.rb 819 B

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module FormUpdater::Concerns::AppliesTicketTemplate
  3. extend ActiveSupport::Concern
  4. def resolve
  5. if agent? && selected_template.present?
  6. apply_template
  7. end
  8. super
  9. end
  10. private
  11. def apply_template
  12. apply_value = FormUpdater::ApplyValue.new(context:, data:, dirty_fields: meta[:dirty_fields], result:)
  13. selected_template.options.each_pair do |fieldpath, config|
  14. apply_value.perform(field: fieldpath.split('.').last, config:)
  15. end
  16. end
  17. def selected_template
  18. tid = meta.dig(:additional_data, 'templateId')
  19. Gql::ZammadSchema.authorized_object_from_id(tid, type: Template, user: context[:current_user]) if tid.present?
  20. end
  21. def agent?
  22. current_user.permissions?('ticket.agent')
  23. end
  24. end