assets.rb 1.2 KB

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