2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
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
|
2020-09-30 09:07:01 +00:00
|
|
|
if self.class.column_names.include?('updated_by_id') && 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}"
|
2017-01-31 17:13:45 +00:00
|
|
|
end
|
2020-09-30 09:07:01 +00:00
|
|
|
self.updated_by_id = UserInfo.current_user_id
|
2017-01-31 17:13:45 +00:00
|
|
|
end
|
|
|
|
|
2020-09-30 09:07:01 +00:00
|
|
|
return true if self.class.column_names.exclude?('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
|
2020-09-30 09:07:01 +00:00
|
|
|
return true if self.class.column_names.exclude?('updated_by_id')
|
2017-06-16 22:53:20 +00:00
|
|
|
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
|