mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 17:33:27 +08:00
add users with invalid email addresses (#5224)
* add users with invalid email addresses * start to add suspend user stff * don't create a suspend_user function * include reason for suspension
This commit is contained in:

committed by
Régis Hanol

parent
361fbfa518
commit
20e7e285d6
@ -72,6 +72,8 @@ class ImportScripts::Base
|
|||||||
min_private_message_title_length: 1,
|
min_private_message_title_length: 1,
|
||||||
allow_duplicate_topic_titles: true,
|
allow_duplicate_topic_titles: true,
|
||||||
disable_emails: true,
|
disable_emails: true,
|
||||||
|
max_attachment_size_kb: 102400,
|
||||||
|
max_image_size_kb: 102400,
|
||||||
authorized_extensions: '*'
|
authorized_extensions: '*'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@ -144,7 +146,7 @@ class ImportScripts::Base
|
|||||||
created = 0
|
created = 0
|
||||||
skipped = 0
|
skipped = 0
|
||||||
failed = 0
|
failed = 0
|
||||||
total = opts[:total] || results.size
|
total = opts[:total] || results.count
|
||||||
|
|
||||||
results.each do |result|
|
results.each do |result|
|
||||||
g = yield(result)
|
g = yield(result)
|
||||||
@ -220,7 +222,7 @@ class ImportScripts::Base
|
|||||||
created = 0
|
created = 0
|
||||||
skipped = 0
|
skipped = 0
|
||||||
failed = 0
|
failed = 0
|
||||||
total = opts[:total] || results.size
|
total = opts[:total] || results.count
|
||||||
|
|
||||||
results.each do |result|
|
results.each do |result|
|
||||||
u = yield(result)
|
u = yield(result)
|
||||||
@ -277,6 +279,7 @@ class ImportScripts::Base
|
|||||||
|
|
||||||
original_username = opts[:username]
|
original_username = opts[:username]
|
||||||
original_name = opts[:name]
|
original_name = opts[:name]
|
||||||
|
original_email = opts[:email] = opts[:email].downcase
|
||||||
|
|
||||||
# Allow the || operations to work with empty strings ''
|
# Allow the || operations to work with empty strings ''
|
||||||
opts[:username] = nil if opts[:username].blank?
|
opts[:username] = nil if opts[:username].blank?
|
||||||
@ -292,9 +295,13 @@ class ImportScripts::Base
|
|||||||
opts[:username] = UserNameSuggester.suggest(opts[:username] || opts[:name].presence || opts[:email])
|
opts[:username] = UserNameSuggester.suggest(opts[:username] || opts[:name].presence || opts[:email])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unless opts[:email].match(EmailValidator.email_regex)
|
||||||
|
opts[:email] = "invalid#{SecureRandom.hex}@no-email.invalid"
|
||||||
|
puts "Invalid email #{original_email} for #{opts[:username]}. Using: #{opts[:email]}"
|
||||||
|
end
|
||||||
|
|
||||||
opts[:name] = original_username if original_name.blank? && opts[:username] != original_username
|
opts[:name] = original_username if original_name.blank? && opts[:username] != original_username
|
||||||
|
|
||||||
opts[:email] = opts[:email].downcase
|
|
||||||
opts[:trust_level] = TrustLevel[1] unless opts[:trust_level]
|
opts[:trust_level] = TrustLevel[1] unless opts[:trust_level]
|
||||||
opts[:active] = opts.fetch(:active, true)
|
opts[:active] = opts.fetch(:active, true)
|
||||||
opts[:import_mode] = true
|
opts[:import_mode] = true
|
||||||
@ -306,6 +313,7 @@ class ImportScripts::Base
|
|||||||
u.custom_fields["import_username"] = opts[:username] if original_username.present?
|
u.custom_fields["import_username"] = opts[:username] if original_username.present?
|
||||||
u.custom_fields["import_avatar_url"] = avatar_url if avatar_url.present?
|
u.custom_fields["import_avatar_url"] = avatar_url if avatar_url.present?
|
||||||
u.custom_fields["import_pass"] = opts[:password] if opts[:password].present?
|
u.custom_fields["import_pass"] = opts[:password] if opts[:password].present?
|
||||||
|
u.custom_fields["import_email"] = original_email if original_email != opts[:email]
|
||||||
|
|
||||||
begin
|
begin
|
||||||
User.transaction do
|
User.transaction do
|
||||||
@ -335,6 +343,27 @@ class ImportScripts::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if u.custom_fields['import_email']
|
||||||
|
u.suspended_at = Time.zone.at(Time.now)
|
||||||
|
u.suspended_till = 200.years.from_now
|
||||||
|
ban_reason = 'Invalid email address on import'
|
||||||
|
u.active=false
|
||||||
|
u.save!
|
||||||
|
|
||||||
|
user_option = u.user_option
|
||||||
|
user_option.email_digests = false
|
||||||
|
user_option.email_private_messages = false
|
||||||
|
user_option.email_direct = false
|
||||||
|
user_option.email_always = false
|
||||||
|
user_option.save!
|
||||||
|
if u.save
|
||||||
|
StaffActionLogger.new(Discourse.system_user).log_user_suspend(u, ban_reason)
|
||||||
|
else
|
||||||
|
Rails.logger.error("Failed to suspend user #{u.username}. #{u.errors.try(:full_messages).try(:inspect)}")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
post_create_action.try(:call, u) if u.persisted?
|
post_create_action.try(:call, u) if u.persisted?
|
||||||
|
|
||||||
u # If there was an error creating the user, u.errors has the messages
|
u # If there was an error creating the user, u.errors has the messages
|
||||||
@ -353,7 +382,7 @@ class ImportScripts::Base
|
|||||||
def create_categories(results)
|
def create_categories(results)
|
||||||
created = 0
|
created = 0
|
||||||
skipped = 0
|
skipped = 0
|
||||||
total = results.size
|
total = results.count
|
||||||
|
|
||||||
results.each do |c|
|
results.each do |c|
|
||||||
params = yield(c)
|
params = yield(c)
|
||||||
@ -425,7 +454,7 @@ class ImportScripts::Base
|
|||||||
def create_posts(results, opts = {})
|
def create_posts(results, opts = {})
|
||||||
skipped = 0
|
skipped = 0
|
||||||
created = 0
|
created = 0
|
||||||
total = opts[:total] || results.size
|
total = opts[:total] || results.count
|
||||||
start_time = get_start_time("posts-#{total}") # the post count should be unique enough to differentiate between posts and PMs
|
start_time = get_start_time("posts-#{total}") # the post count should be unique enough to differentiate between posts and PMs
|
||||||
|
|
||||||
results.each do |r|
|
results.each do |r|
|
||||||
@ -505,7 +534,7 @@ class ImportScripts::Base
|
|||||||
def create_bookmarks(results, opts = {})
|
def create_bookmarks(results, opts = {})
|
||||||
created = 0
|
created = 0
|
||||||
skipped = 0
|
skipped = 0
|
||||||
total = opts[:total] || results.size
|
total = opts[:total] || results.count
|
||||||
|
|
||||||
user = User.new
|
user = User.new
|
||||||
post = Post.new
|
post = Post.new
|
||||||
|
Reference in New Issue
Block a user