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 ApplicationModel::ChecksUserColumnsFillup
|
2017-01-31 17:13:45 +00:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2020-09-08 15:06:23 +00:00
|
|
|
before_validation :fill_up_user_validate
|
|
|
|
end
|
|
|
|
|
|
|
|
def fill_up_user_validate
|
|
|
|
return fill_up_user_create if new_record?
|
|
|
|
|
|
|
|
fill_up_user_update
|
2017-01-31 17:13:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
set created_by_id & updated_by_id if not given based on UserInfo (current session)
|
|
|
|
|
|
|
|
Used as before_create callback, no own use needed
|
|
|
|
|
|
|
|
result = Model.fill_up_user_create(params)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = params # params with updated_by_id & created_by_id if not given based on UserInfo (current session)
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def fill_up_user_create
|
|
|
|
if self.class.column_names.include? 'updated_by_id'
|
|
|
|
if UserInfo.current_user_id
|
|
|
|
if updated_by_id && updated_by_id != UserInfo.current_user_id
|
|
|
|
logger.info "NOTICE create - self.updated_by_id is different: #{updated_by_id}/#{UserInfo.current_user_id}"
|
|
|
|
end
|
|
|
|
self.updated_by_id = UserInfo.current_user_id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-16 22:53:20 +00:00
|
|
|
return true if !self.class.column_names.include? 'created_by_id'
|
2017-01-31 17:13:45 +00:00
|
|
|
|
2017-06-16 22:53:20 +00:00
|
|
|
return true if !UserInfo.current_user_id
|
2017-01-31 17:13:45 +00:00
|
|
|
|
|
|
|
if created_by_id && created_by_id != UserInfo.current_user_id
|
|
|
|
logger.info "NOTICE create - self.created_by_id is different: #{created_by_id}/#{UserInfo.current_user_id}"
|
|
|
|
end
|
|
|
|
self.created_by_id = UserInfo.current_user_id
|
2017-06-16 22:53:20 +00:00
|
|
|
true
|
2017-01-31 17:13:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
set updated_by_id if not given based on UserInfo (current session)
|
|
|
|
|
|
|
|
Used as before_update callback, no own use needed
|
|
|
|
|
|
|
|
result = Model.fill_up_user_update(params)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = params # params with updated_by_id & created_by_id if not given based on UserInfo (current session)
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def fill_up_user_update
|
2017-06-16 22:53:20 +00:00
|
|
|
return true if !self.class.column_names.include? 'updated_by_id'
|
|
|
|
return true if !UserInfo.current_user_id
|
2017-01-31 17:13:45 +00:00
|
|
|
|
|
|
|
self.updated_by_id = UserInfo.current_user_id
|
2017-06-16 22:53:20 +00:00
|
|
|
true
|
2017-01-31 17:13:45 +00:00
|
|
|
end
|
|
|
|
end
|