assets.rb 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. module Ticket::Assets
  3. extend ActiveSupport::Concern
  4. =begin
  5. get all assets / related models for this ticket
  6. ticket = Ticket.find(123)
  7. result = ticket.assets(assets_if_exists)
  8. returns
  9. result = {
  10. users: {
  11. 123: user_model_123,
  12. 1234: user_model_1234,
  13. },
  14. tickets: [ ticket_model1 ]
  15. }
  16. =end
  17. def assets(data)
  18. app_model_ticket = Ticket.to_app_model
  19. app_model_user = User.to_app_model
  20. if !data[ app_model_ticket ]
  21. data[ app_model_ticket ] = {}
  22. end
  23. if !data[ app_model_ticket ][ id ]
  24. data[ app_model_ticket ][ id ] = attributes_with_association_ids
  25. end
  26. %w[created_by_id updated_by_id owner_id customer_id].each do |local_user_id|
  27. next if !self[ local_user_id ]
  28. next if data[ app_model_user ] && data[ app_model_user ][ self[ local_user_id ] ]
  29. user = User.lookup(id: self[ local_user_id ])
  30. next if !user
  31. data = user.assets(data)
  32. end
  33. data
  34. end
  35. end