adds a rake task to assign missing geozones

This commit is contained in:
kikito
2016-02-19 18:01:06 +01:00
parent 3ad5fa19e5
commit 8fde9a77ac
2 changed files with 14 additions and 1 deletions

View File

@@ -4,7 +4,7 @@ namespace :users do
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_for_official_emails: :environment do
domain = Setting['email_domain_for_officials']
@@ -22,4 +22,16 @@ namespace :users do
end
end
desc "Associates a geozone to each user who doesn't have it already but has validated his residence using the census API"
task assign_geozones: :environment do
User.residence_verified.where(geozone_id: nil).find_each do |u|
response = CensusApi.new.call(u.document_type, u.document_number)
if response.valid?
u.geozone = Geozone.where(census_code: response.district_code).first
u.save
end
end
end
end