2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2017-05-02 15:21:13 +00:00
|
|
|
module ApplicationModel::CanActivityStreamLog
|
2017-01-31 17:13:45 +00:00
|
|
|
extend ActiveSupport::Concern
|
2013-09-28 00:07:11 +00:00
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
log activity for this object
|
|
|
|
|
|
|
|
article = Ticket::Article.find(123)
|
2016-02-22 19:58:23 +00:00
|
|
|
result = article.activity_stream_log('create', user_id)
|
2013-09-28 00:07:11 +00:00
|
|
|
|
2013-10-07 03:38:07 +00:00
|
|
|
# force log
|
2016-02-22 19:58:23 +00:00
|
|
|
result = article.activity_stream_log('create', user_id, true)
|
2013-10-07 03:38:07 +00:00
|
|
|
|
2013-09-28 00:07:11 +00:00
|
|
|
returns
|
|
|
|
|
|
|
|
result = true # false
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
2016-02-22 19:58:23 +00:00
|
|
|
def activity_stream_log(type, user_id, force = false)
|
2015-05-01 13:08:43 +00:00
|
|
|
|
|
|
|
# return if we run import mode
|
|
|
|
return if Setting.get('import_mode')
|
|
|
|
|
|
|
|
# return if we run on init mode
|
|
|
|
return if !Setting.get('system_init_done')
|
|
|
|
|
2017-01-31 17:13:45 +00:00
|
|
|
permission = self.class.instance_variable_get(:@activity_stream_permission)
|
2015-05-01 13:08:43 +00:00
|
|
|
updated_at = self.updated_at
|
|
|
|
if force
|
2015-05-08 10:20:33 +00:00
|
|
|
updated_at = Time.zone.now
|
2013-10-07 03:38:07 +00:00
|
|
|
end
|
2017-01-31 17:13:45 +00:00
|
|
|
|
|
|
|
attributes = {
|
|
|
|
o_id: self['id'],
|
|
|
|
type: type,
|
|
|
|
object: self.class.name,
|
|
|
|
group_id: self['group_id'],
|
|
|
|
permission: permission,
|
|
|
|
created_at: updated_at,
|
2015-05-01 13:08:43 +00:00
|
|
|
created_by_id: user_id,
|
2017-01-31 17:13:45 +00:00
|
|
|
}.merge(activity_stream_log_attributes)
|
|
|
|
|
|
|
|
ActivityStream.add(attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# callback function to overwrite
|
|
|
|
# default history stream log attributes
|
|
|
|
# gets called from activity_stream_log
|
|
|
|
def activity_stream_log_attributes
|
|
|
|
{}
|
2013-09-28 00:07:11 +00:00
|
|
|
end
|
2014-02-03 19:23:00 +00:00
|
|
|
end
|