assets.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Trigger
  3. module Assets
  4. extend ActiveSupport::Concern
  5. =begin
  6. get all assets / related models for this trigger
  7. trigger = Trigger.find(123)
  8. result = trigger.assets(assets_if_exists)
  9. returns
  10. result = {
  11. :triggers => {
  12. 123 => trigger_model_123,
  13. 1234 => trigger_model_1234,
  14. }
  15. }
  16. =end
  17. def assets(data)
  18. app_model_trigger = Trigger.to_app_model
  19. data[ app_model_trigger ] ||= {}
  20. return data if data[ app_model_trigger ][ id ]
  21. data[ app_model_trigger ][ 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. app_model_webhook = Webhook.to_app_model
  30. data[ app_model_webhook ] ||= {}
  31. Webhook.find_each do |webhook|
  32. data = webhook.assets(data)
  33. end
  34. app_model_user = User.to_app_model
  35. data[ app_model_user ] ||= {}
  36. %w[created_by_id updated_by_id].each do |local_user_id|
  37. next if !self[ local_user_id ]
  38. next if data[ app_model_user ][ self[ local_user_id ] ]
  39. user = User.lookup(id: self[ local_user_id ])
  40. next if !user
  41. data = user.assets(data)
  42. end
  43. data
  44. end
  45. end
  46. end