Better names for the official email methods

This commit is contained in:
Jakub
2015-11-30 21:52:48 +01:00
parent ae25c4bed0
commit ea9a2b3be6
4 changed files with 9 additions and 9 deletions

View File

@@ -202,7 +202,7 @@ class User < ActiveRecord::Base
!erased? !erased?
end end
def has_officials_email_domain? def has_official_email?
domain = Setting.value_for 'email_domain_for_officials' domain = Setting.value_for 'email_domain_for_officials'
return false if !email or !domain or domain.length == 0 return false if !email or !domain or domain.length == 0
(email.end_with? "@#{domain}") or (email.end_with? ".#{domain}") (email.end_with? "@#{domain}") or (email.end_with? ".#{domain}")
@@ -210,8 +210,8 @@ class User < ActiveRecord::Base
# Check if the user is confirmed and has an official email address # Check if the user is confirmed and has an official email address
# In that case, we assign a level 1 official level # In that case, we assign a level 1 official level
def check_if_officials_email_domain def check_if_official_email
if confirmed_at and !official? and has_officials_email_domain? if confirmed_at and !official? and has_official_email?
self.official_level = 1 self.official_level = 1
self.official_position = Setting.value_for 'official_level_1_name' self.official_position = Setting.value_for 'official_level_1_name'
end end
@@ -220,7 +220,7 @@ class User < ActiveRecord::Base
def check_if_confirmation def check_if_confirmation
# If we are confirming the mail address, we check if the user is an official # If we are confirming the mail address, we check if the user is an official
if confirmed_at and confirmed_at_changed? if confirmed_at and confirmed_at_changed?
check_if_officials_email_domain check_if_official_email
end end
end end

View File

@@ -6,15 +6,15 @@ namespace :users do
end end
desc "Assigns official level to users with the officials' email domain" desc "Assigns official level to users with the officials' email domain"
task check_if_officials_email_domains: :environment do task check_for_official_emails: :environment do
domain = Setting.value_for 'email_domain_for_officials' domain = Setting.value_for 'email_domain_for_officials'
# We end the task if there is no email domain configured # We end the task if there is no email domain configured
if domain.length > 0 if domain.length > 0
# We filter the mail addresses with SQL to speed up the process # 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. # The real check will be done by check_if_official_email, however.
User.where('official_level = 0 and email like ?', "%#{domain}").find_each do |user| User.where('official_level = 0 and email like ?', "%#{domain}").find_each do |user|
user.check_if_officials_email_domain user.check_if_official_email
puts "#{user.username} (#{user.email}) is now a level-1 official." if user.official? puts "#{user.username} (#{user.email}) is now a level-1 official." if user.official?
user.save user.save
end end

View File

@@ -240,7 +240,7 @@ describe User do
end end
end end
describe "check_if_officials_email_domain" do describe "check_if_official_email" do
it "assigns official level to confirmed users with the officials' email domain" do it "assigns official level to confirmed users with the officials' email domain" do
# We will use empleados.madrid.es as the officials' domain # We will use empleados.madrid.es as the officials' domain
# Subdomains are also accepted # Subdomains are also accepted