can_activity_stream_log.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module ApplicationModel::CanActivityStreamLog
  3. extend ActiveSupport::Concern
  4. =begin
  5. log activity for this object
  6. article = Ticket::Article.find(123)
  7. result = article.activity_stream_log('create', user_id)
  8. # force log
  9. result = article.activity_stream_log('create', user_id, true)
  10. returns
  11. result = true # false
  12. =end
  13. def activity_stream_log(type, user_id, force = false)
  14. # return if we run import mode
  15. return if Setting.get('import_mode')
  16. # return if we run on init mode
  17. return if !Setting.get('system_init_done')
  18. permission = self.class.instance_variable_get(:@activity_stream_permission)
  19. updated_at = self.updated_at
  20. if force
  21. updated_at = Time.zone.now
  22. end
  23. attributes = {
  24. o_id: self['id'],
  25. type: type,
  26. object: self.class.name,
  27. group_id: self['group_id'],
  28. permission: permission,
  29. created_at: updated_at,
  30. created_by_id: user_id,
  31. }.merge(activity_stream_log_attributes)
  32. ActivityStream.add(attributes)
  33. end
  34. private
  35. # callback function to overwrite
  36. # default history stream log attributes
  37. # gets called from activity_stream_log
  38. def activity_stream_log_attributes
  39. {}
  40. end
  41. end