Better names for the official email methods
This commit is contained in:
@@ -202,7 +202,7 @@ class User < ActiveRecord::Base
|
||||
!erased?
|
||||
end
|
||||
|
||||
def has_officials_email_domain?
|
||||
def has_official_email?
|
||||
domain = Setting.value_for 'email_domain_for_officials'
|
||||
return false if !email or !domain or domain.length == 0
|
||||
(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
|
||||
# In that case, we assign a level 1 official level
|
||||
def check_if_officials_email_domain
|
||||
if confirmed_at and !official? and has_officials_email_domain?
|
||||
def check_if_official_email
|
||||
if confirmed_at and !official? and has_official_email?
|
||||
self.official_level = 1
|
||||
self.official_position = Setting.value_for 'official_level_1_name'
|
||||
end
|
||||
@@ -220,7 +220,7 @@ class User < ActiveRecord::Base
|
||||
def check_if_confirmation
|
||||
# If we are confirming the mail address, we check if the user is an official
|
||||
if confirmed_at and confirmed_at_changed?
|
||||
check_if_officials_email_domain
|
||||
check_if_official_email
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -6,15 +6,15 @@ namespace :users do
|
||||
end
|
||||
|
||||
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'
|
||||
|
||||
# We end the task if there is no email domain configured
|
||||
if domain.length > 0
|
||||
# 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.check_if_officials_email_domain
|
||||
user.check_if_official_email
|
||||
puts "#{user.username} (#{user.email}) is now a level-1 official." if user.official?
|
||||
user.save
|
||||
end
|
||||
|
||||
@@ -240,7 +240,7 @@ describe User do
|
||||
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
|
||||
# We will use empleados.madrid.es as the officials' domain
|
||||
# Subdomains are also accepted
|
||||
|
||||
Reference in New Issue
Block a user