Level 1 officials are now auto-assigned. Rake user:check_email_domains created.
This commit is contained in:
@@ -48,6 +48,8 @@ class User < ActiveRecord::Base
|
|||||||
|
|
||||||
before_validation :clean_document_number
|
before_validation :clean_document_number
|
||||||
|
|
||||||
|
before_create :check_email_domain
|
||||||
|
|
||||||
def self.find_for_oauth(auth, signed_in_resource = nil)
|
def self.find_for_oauth(auth, signed_in_resource = nil)
|
||||||
# Get the identity and user if they exist
|
# Get the identity and user if they exist
|
||||||
identity = Identity.find_for_oauth(auth)
|
identity = Identity.find_for_oauth(auth)
|
||||||
@@ -200,6 +202,18 @@ class User < ActiveRecord::Base
|
|||||||
!erased?
|
!erased?
|
||||||
end
|
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
|
private
|
||||||
def clean_document_number
|
def clean_document_number
|
||||||
self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase unless self.document_number.blank?
|
self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase unless self.document_number.blank?
|
||||||
|
|||||||
@@ -10,3 +10,4 @@ en:
|
|||||||
max_votes_for_debate_edit: "Number of votes from which a Debate can no longer be edited"
|
max_votes_for_debate_edit: "Number of votes from which a Debate can no longer be edited"
|
||||||
proposal_code_prefix: "Prefix for Proposal codes"
|
proposal_code_prefix: "Prefix for Proposal codes"
|
||||||
votes_for_proposal_success: "Number of votes necessary for approval of a Proposal"
|
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"
|
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"
|
proposal_code_prefix: "Prefijo para los códigos de Propuestas"
|
||||||
votes_for_proposal_success: "Número de votos necesarios para aprobar una Propuesta"
|
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
|
# Number of votes needed for proposal success
|
||||||
Setting.create(key: 'votes_for_proposal_success', value: '53726')
|
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')
|
||||||
|
|||||||
@@ -5,4 +5,12 @@ namespace :users do
|
|||||||
User.find_each{ |user| User.reset_counters(user.id, :failed_census_calls)}
|
User.find_each{ |user| User.reset_counters(user.id, :failed_census_calls)}
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user