add fix script for user names
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
class UserNameValidator < ActiveModel::EachValidator
|
class UserNameValidator < ActiveModel::EachValidator
|
||||||
def validate_each(rec, attr, value)
|
def validate_each(rec, attr, value)
|
||||||
|
name = value
|
||||||
|
|
||||||
rec.errors[attr] << "already exists" if User.find_by_name(name).present?
|
rec.errors[attr] << "already exists" if User.find_by_name(name).present?
|
||||||
rec.errors[attr] << "must be 2 to 100 characters long" if !name.length.between?(2, 100)
|
rec.errors[attr] << "must be 2 to 100 characters long" if !name.length.between?(2, 100)
|
||||||
rec.errors[attr] << "cannot have whitespace or colons" if name =~ /[[:space:]]|:/
|
rec.errors[attr] << "cannot have whitespace or colons" if name =~ /[[:space:]]|:/
|
||||||
|
|||||||
12
script/fixes/043_fix_whitespace_usernames.rb
Normal file
12
script/fixes/043_fix_whitespace_usernames.rb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment'))
|
||||||
|
|
||||||
|
ActiveRecord::Base.connection.execute("set statement_timeout = 0")
|
||||||
|
|
||||||
|
User.where("name like ?", "% %").find_each do |user|
|
||||||
|
print "repairing #{user.name} -> "
|
||||||
|
user.name = user.name.gsub(/[[:space:]]/, "_")
|
||||||
|
user.save
|
||||||
|
puts user.name
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user