2017-01-31 17:13:45 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
2017-05-02 15:21:13 +00:00
|
|
|
module HasActivityStreamLog
|
2017-01-31 17:13:45 +00:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
after_create :activity_stream_create
|
|
|
|
after_update :activity_stream_update
|
|
|
|
before_destroy :activity_stream_destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
log object create activity stream, if configured - will be executed automatically
|
|
|
|
|
|
|
|
model = Model.find(123)
|
|
|
|
model.activity_stream_create
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def activity_stream_create
|
|
|
|
activity_stream_log('create', self['created_by_id'])
|
2017-06-16 22:53:20 +00:00
|
|
|
true
|
2017-01-31 17:13:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
log object update activity stream, if configured - will be executed automatically
|
|
|
|
|
|
|
|
model = Model.find(123)
|
|
|
|
model.activity_stream_update
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def activity_stream_update
|
2017-09-23 06:25:55 +00:00
|
|
|
return true if !saved_changes?
|
2017-01-31 17:13:45 +00:00
|
|
|
|
|
|
|
ignored_attributes = self.class.instance_variable_get(:@activity_stream_attributes_ignored) || []
|
2017-11-23 08:09:44 +00:00
|
|
|
ignored_attributes += %i[created_at updated_at created_by_id updated_by_id]
|
2017-01-31 17:13:45 +00:00
|
|
|
|
|
|
|
log = false
|
2017-11-23 08:09:44 +00:00
|
|
|
saved_changes.each_key do |key|
|
2017-01-31 17:13:45 +00:00
|
|
|
next if ignored_attributes.include?(key.to_sym)
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-01-31 17:13:45 +00:00
|
|
|
log = true
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2017-06-16 22:53:20 +00:00
|
|
|
return true if !log
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-01-31 17:13:45 +00:00
|
|
|
activity_stream_log('update', self['updated_by_id'])
|
2017-06-16 22:53:20 +00:00
|
|
|
true
|
2017-01-31 17:13:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
delete object activity stream, will be executed automatically
|
|
|
|
|
|
|
|
model = Model.find(123)
|
|
|
|
model.activity_stream_destroy
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def activity_stream_destroy
|
|
|
|
ActivityStream.remove(self.class.to_s, id)
|
2017-06-16 22:53:20 +00:00
|
|
|
true
|
2017-01-31 17:13:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# methods defined here are going to extend the class, not the instance of it
|
|
|
|
class_methods do
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
2019-07-31 08:23:48 +00:00
|
|
|
serve method to ignore model attributes in activity stream and/or limit activity stream permission
|
2017-01-31 17:13:45 +00:00
|
|
|
|
|
|
|
class Model < ApplicationModel
|
2017-05-02 15:21:13 +00:00
|
|
|
include HasActivityStreamLog
|
2017-01-31 17:13:45 +00:00
|
|
|
activity_stream_permission 'admin.user'
|
|
|
|
activity_stream_attributes_ignored :create_article_type_id, :preferences
|
|
|
|
end
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def activity_stream_attributes_ignored(*attributes)
|
|
|
|
@activity_stream_attributes_ignored = attributes
|
|
|
|
end
|
|
|
|
|
|
|
|
def activity_stream_permission(permission)
|
|
|
|
@activity_stream_permission = permission
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|