assets.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class Template
  3. module Assets
  4. extend ActiveSupport::Concern
  5. def assets(data)
  6. return data if assets_added_to?(data)
  7. app_model = Template.to_app_model
  8. if !data[ app_model ]
  9. data[ app_model ] = {}
  10. end
  11. return data if data[ app_model ][ id ]
  12. data[ app_model ][ id ] = attributes_with_association_ids
  13. assets_content(data)
  14. data
  15. end
  16. def assets_content(data)
  17. return if options.blank?
  18. assets_user(data)
  19. assets_state(data)
  20. assets_priority(data)
  21. assets_group(data)
  22. end
  23. def assets_user(data)
  24. User.find_by(id: options[:owner_id])&.assets(data)
  25. User.find_by(id: options[:customer_id])&.assets(data)
  26. end
  27. def assets_state(data)
  28. Ticket::State.find_by(id: options[:state_id])&.assets(data)
  29. end
  30. def assets_priority(data)
  31. Ticket::Priority.find_by(id: options[:priority_id])&.assets(data)
  32. end
  33. def assets_group(data)
  34. Group.find_by(id: options[:group_id])&.assets(data)
  35. end
  36. end
  37. end