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::ChecksImport
|
2017-01-31 17:13:45 +00:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
before_create :check_attributes_protected
|
|
|
|
end
|
|
|
|
|
2019-01-28 06:04:05 +00:00
|
|
|
class_methods do
|
|
|
|
# Use `include CanBeImported` in a class to override this method
|
|
|
|
def importable?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
2017-01-31 17:13:45 +00:00
|
|
|
|
2019-01-28 06:04:05 +00:00
|
|
|
def check_attributes_protected
|
2017-01-31 17:13:45 +00:00
|
|
|
# do noting, use id as it is
|
|
|
|
return if !Setting.get('system_init_done')
|
2019-01-28 06:04:05 +00:00
|
|
|
return if Setting.get('import_mode') && self.class.importable?
|
2017-06-16 20:43:09 +00:00
|
|
|
return if !has_attribute?(:id)
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-01-31 17:13:45 +00:00
|
|
|
self[:id] = nil
|
2017-06-16 22:53:20 +00:00
|
|
|
true
|
2017-01-31 17:13:45 +00:00
|
|
|
end
|
|
|
|
end
|