20211025093743_issue_2429_user_identifier_validation.rb 751 B

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class Issue2429UserIdentifierValidation < ActiveRecord::Migration[6.0]
  3. def up
  4. return if !Setting.exists?(name: 'system_init_done')
  5. %i[firstname lastname email phone].each { |elem| update_single(elem) }
  6. end
  7. def update_single(elem)
  8. attr = ObjectManager::Attribute.for_object(User).find_by(name: elem)
  9. attr.screens.each do |_, value|
  10. if value.try(:key?, 'null')
  11. value['null'] = true
  12. end
  13. next if !value.is_a? Hash
  14. value.each do |_, inner_value|
  15. if inner_value.try(:key?, 'null')
  16. inner_value['null'] = true
  17. end
  18. end
  19. end
  20. attr.save!
  21. rescue => e
  22. Rails.logger.error e
  23. end
  24. end