fix_event_object.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Service::History::Concerns::FixEventObject
  3. extend ActiveSupport::Concern
  4. included do
  5. private
  6. def fix_event_object(event, entry)
  7. fix_mention_object(event, entry)
  8. fix_merge_object(event, entry)
  9. end
  10. # The related mention object is always a User. The action is suffixed with
  11. # `_mention` to distinguish it from other actions.
  12. def fix_mention_object(event, entry)
  13. return if entry.history_object.name != 'Mention'
  14. event[:action] = "#{event[:action]}_mention"
  15. event[:object] = __get_event_object_or_class_name(User, entry.value_to)
  16. end
  17. # The related merge object is always a Ticket.
  18. def fix_merge_object(event, entry)
  19. return if entry.history_type.name.exclude?('merge')
  20. id = entry.history_type.name.include?('received') ? entry.id_from : entry.id_to
  21. event[:object] = __get_event_object_or_class_name(Ticket, id)
  22. end
  23. def __get_event_object_or_class_name(klass, id)
  24. klass.find(id)
  25. rescue ActiveRecord::RecordNotFound
  26. { klass: klass.name }
  27. end
  28. end
  29. end