Level 1 officials are now auto-assigned. Rake user:check_email_domains created.
This commit is contained in:
@@ -47,6 +47,8 @@ class User < ActiveRecord::Base
|
||||
scope :by_document, -> (document_type, document_number) { where(document_type: document_type, document_number: document_number) }
|
||||
|
||||
before_validation :clean_document_number
|
||||
|
||||
before_create :check_email_domain
|
||||
|
||||
def self.find_for_oauth(auth, signed_in_resource = nil)
|
||||
# Get the identity and user if they exist
|
||||
@@ -199,6 +201,18 @@ class User < ActiveRecord::Base
|
||||
def email_required?
|
||||
!erased?
|
||||
end
|
||||
|
||||
def has_officials_email_domain?
|
||||
domain = Setting.value_for 'email_domain_for_officials'
|
||||
email.end_with? "@#{domain}"
|
||||
end
|
||||
|
||||
def check_email_domain
|
||||
if !official? and has_officials_email_domain?
|
||||
self.official_level = 1
|
||||
self.official_position = Setting.value_for 'official_level_1_name'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def clean_document_number
|
||||
|
||||
@@ -10,3 +10,4 @@ en:
|
||||
max_votes_for_debate_edit: "Number of votes from which a Debate can no longer be edited"
|
||||
proposal_code_prefix: "Prefix for Proposal codes"
|
||||
votes_for_proposal_success: "Number of votes necessary for approval of a Proposal"
|
||||
email_domain_for_officials: "Email domain for public officials"
|
||||
|
||||
@@ -10,3 +10,4 @@ es:
|
||||
max_votes_for_debate_edit: "Número de votos en que un Debate deja de poderse editar"
|
||||
proposal_code_prefix: "Prefijo para los códigos de Propuestas"
|
||||
votes_for_proposal_success: "Número de votos necesarios para aprobar una Propuesta"
|
||||
email_domain_for_officials: "Dominio de email para cargos públicos"
|
||||
@@ -26,3 +26,6 @@ Setting.create(key: 'proposal_code_prefix', value: 'MAD')
|
||||
|
||||
# Number of votes needed for proposal success
|
||||
Setting.create(key: 'votes_for_proposal_success', value: '53726')
|
||||
|
||||
# Users with this email domain will automatically be marked as level 1 officials
|
||||
Setting.create(key: 'email_domain_for_officials', value: 'madrid.es')
|
||||
|
||||
@@ -4,5 +4,13 @@ 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_email_domains: :environment do
|
||||
User.find_each do |user|
|
||||
user.check_email_domain
|
||||
user.save
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user