20211025093743_issue_2429_user_identifier_validation.rb 757 B

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2024 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_value do |value|
  10. if value.try(:key?, 'null')
  11. value['null'] = true
  12. end
  13. next if !value.is_a? Hash
  14. value.each_value 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