Sha256: 404533f52b064cda6ef8f320d23b3afdd2e9ffd02e1f399ed7c31b916583819f

Contents?: true

Size: 1.17 KB

Versions: 36

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

class FixUserNames < ActiveRecord::Migration[5.2]
  def change
    # Comes from Decidim::User specs
    weird_characters =
      ["<", ">", "?", "\\%", "&", "^", "*", "#", "@", "(", ")", "[", "]", "=", "+", ":", ";", "\"", "{", "}", "\\", "|", "/"]
    characters_to_remove = "<>?%&^*\#@()[]=+:;\"{}\\|/"

    weird_characters.each do |character|
      Decidim::UserBaseEntity.where(deleted_at: nil).where("name like '%#{character}%' escape '\' OR nickname like '%#{character}%' escape '\'").find_each do |entity|
        Rails.logger.debug "detected character: #{character}"
        Rails.logger.debug "UserBaseEntity ID: #{entity.id}"
        Rails.logger.debug "#{entity.name} => #{entity.name.delete(characters_to_remove).strip}"
        Rails.logger.debug "#{entity.nickname} => #{entity.nickname.delete(characters_to_remove).strip}"

        entity.name = entity.name.delete(characters_to_remove).strip
        sanitized_nickname = entity.nickname.delete(characters_to_remove).strip
        entity.nickname = Decidim::UserBaseEntity.nicknamize(sanitized_nickname, organization: entity.organization)
        entity.save(validate: false)
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
decidim-core-0.26.7 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.26.5 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.26.4 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.26.3 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.26.2 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.26.1 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.26.0 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.26.0.rc2 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.26.0.rc1 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.25.2 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.25.1 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.25.0 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.25.0.rc4 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.25.0.rc3 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.25.0.rc2 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.25.0.rc1 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.24.3 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.23.6 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.24.2 db/migrate/20190412131728_fix_user_names.rb
decidim-core-0.23.5 db/migrate/20190412131728_fix_user_names.rb