checks_import.rb 605 B

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module ApplicationModel::ChecksImport
  3. extend ActiveSupport::Concern
  4. included do
  5. before_create :check_attributes_protected
  6. end
  7. class_methods do
  8. # Use `include CanBeImported` in a class to override this method
  9. def importable?
  10. false
  11. end
  12. end
  13. def check_attributes_protected
  14. # do noting, use id as it is
  15. return if !Setting.get('system_init_done')
  16. return if Setting.get('import_mode') && self.class.importable?
  17. return if !has_attribute?(:id)
  18. self[:id] = nil
  19. true
  20. end
  21. end