assets.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://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. if !data[ app_model_ticket ]
  20. data[ app_model_ticket ] = {}
  21. end
  22. return data if data[ app_model_ticket ][ id ]
  23. data[app_model_ticket][id] = attributes_with_association_ids
  24. data[app_model_ticket][id]['checklist_incomplete_items'] = checklist&.incomplete
  25. group.assets(data)
  26. organization&.assets(data)
  27. assets_user(data)
  28. data
  29. end
  30. def assets_user(data)
  31. app_model_user = User.to_app_model
  32. %w[created_by_id updated_by_id owner_id customer_id].each do |local_user_id|
  33. next if !self[ local_user_id ]
  34. next if data[ app_model_user ] && data[ app_model_user ][ self[ local_user_id ] ]
  35. user = User.lookup(id: self[ local_user_id ])
  36. next if !user
  37. data = user.assets(data)
  38. end
  39. end
  40. def authorized_asset?
  41. return true if UserInfo.current_user.blank?
  42. return true if TicketPolicy.new(UserInfo.current_user, self).show?
  43. false
  44. end
  45. end