assets.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Sla
  3. module Assets
  4. extend ActiveSupport::Concern
  5. =begin
  6. get all assets / related models for this sla
  7. sla = Sla.find(123)
  8. result = sla.assets(assets_if_exists)
  9. returns
  10. result = {
  11. :slas => {
  12. 123 => sla_model_123,
  13. 1234 => sla_model_1234,
  14. }
  15. }
  16. =end
  17. def assets(data)
  18. app_model_sla = Sla.to_app_model
  19. if !data[ app_model_sla ]
  20. data[ app_model_sla ] = {}
  21. end
  22. return data if data[ app_model_sla ][ id ]
  23. data[ app_model_sla ][ id ] = attributes_with_association_ids
  24. data = assets_of_selector('condition', data)
  25. if calendar_id
  26. calendar = Calendar.lookup(id: calendar_id)
  27. if calendar
  28. data = calendar.assets(data)
  29. end
  30. end
  31. app_model_user = User.to_app_model
  32. if !data[ app_model_user ]
  33. data[ app_model_user ] = {}
  34. end
  35. %w[created_by_id updated_by_id].each do |local_user_id|
  36. next if !self[ local_user_id ]
  37. next if data[ app_model_user ][ self[ local_user_id ] ]
  38. user = User.lookup(id: self[ local_user_id ])
  39. next if !user
  40. data = user.assets(data)
  41. end
  42. data
  43. end
  44. end
  45. end