namespace :users do desc "Recalculates all the failed census calls counters for users" task count_failed_census_calls: :environment do User.find_each{ |user| User.reset_counters(user.id, :failed_census_calls)} end desc "Assigns official level to users with the officials' email domain" task check_if_officials_email_domains: :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 # We filter the mail addresses with SQL to speed up the process # The real check will be done by check_if_officials_email_domains, however. User.where('official_level = 0 and email like ?', "%#{domain}").find_each do |user| user.check_if_officials_email_domain puts "#{user.username} (#{user.email}) is now a level-1 official." if user.official? user.save end end end end