Move automatic official_level assignment to the controller.
This commit is contained in:
@@ -8,15 +8,16 @@ namespace :users do
|
||||
desc "Assigns official level to users with the officials' email domain"
|
||||
task check_for_official_emails: :environment do
|
||||
domain = Setting.value_for 'email_domain_for_officials'
|
||||
|
||||
|
||||
# We end the task if there is no email domain configured
|
||||
if domain.length > 0
|
||||
if !domain.blank?
|
||||
# We filter the mail addresses with SQL to speed up the process
|
||||
# The real check will be done by check_if_official_email, however.
|
||||
User.where('official_level = 0 and email like ?', "%#{domain}").find_each do |user|
|
||||
user.check_if_official_email
|
||||
puts "#{user.username} (#{user.email}) is now a level-1 official." if user.official?
|
||||
user.save
|
||||
if user.has_official_email?
|
||||
user.add_official_position! (Setting.value_for 'official_level_1_name'), 1
|
||||
puts "#{user.username} (#{user.email}) is now a level-1 official."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user