diff --git a/app/models/concerns/verification.rb b/app/models/concerns/verification.rb index 01d660012..3520e5b31 100644 --- a/app/models/concerns/verification.rb +++ b/app/models/concerns/verification.rb @@ -2,6 +2,7 @@ module Verification extend ActiveSupport::Concern included do + scope :residence_verified, -> { where.not(residence_verified_at: nil) } scope :level_three_verified, -> { where.not(verified_at: nil) } scope :level_two_verified, -> { where("users.level_two_verified_at IS NOT NULL OR (users.confirmed_phone IS NOT NULL AND users.residence_verified_at IS NOT NULL) AND verified_at IS NULL") } scope :level_two_or_three_verified, -> { where("users.verified_at IS NOT NULL OR users.level_two_verified_at IS NOT NULL OR (users.confirmed_phone IS NOT NULL AND users.residence_verified_at IS NOT NULL)") } diff --git a/lib/tasks/users.rake b/lib/tasks/users.rake index 1094f329b..062f4d783 100644 --- a/lib/tasks/users.rake +++ b/lib/tasks/users.rake @@ -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