Downcase emails upon inviting
This commit is contained in:
parent
5f531f14f1
commit
f8b7307441
7 changed files with 34 additions and 13 deletions
|
|
@ -32,7 +32,7 @@ class UsersController < ApplicationController
|
||||||
if u[:email_preferences]
|
if u[:email_preferences]
|
||||||
@user.update_user_preferences(u[:email_preferences])
|
@user.update_user_preferences(u[:email_preferences])
|
||||||
flash[:notice] = I18n.t 'users.update.email_notifications_changed'
|
flash[:notice] = I18n.t 'users.update.email_notifications_changed'
|
||||||
# change passowrd
|
# change password
|
||||||
elsif u[:current_password] && u[:password] && u[:password_confirmation]
|
elsif u[:current_password] && u[:password] && u[:password_confirmation]
|
||||||
if @user.update_with_password(u)
|
if @user.update_with_password(u)
|
||||||
flash[:notice] = I18n.t 'users.update.password_changed'
|
flash[:notice] = I18n.t 'users.update.password_changed'
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ class Invitation < ActiveRecord::Base
|
||||||
validates_presence_of :sender, :recipient, :aspect
|
validates_presence_of :sender, :recipient, :aspect
|
||||||
|
|
||||||
def self.invite(opts = {})
|
def self.invite(opts = {})
|
||||||
|
opts[:identifier].downcase!
|
||||||
return false if opts[:identifier] == opts[:from].email
|
return false if opts[:identifier] == opts[:from].email
|
||||||
|
|
||||||
existing_user = self.find_existing_user(opts[:service], opts[:identifier])
|
existing_user = self.find_existing_user(opts[:service], opts[:identifier])
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ class User < ActiveRecord::Base
|
||||||
:recoverable, :rememberable, :trackable, :validatable,
|
:recoverable, :rememberable, :trackable, :validatable,
|
||||||
:timeoutable
|
:timeoutable
|
||||||
|
|
||||||
before_validation :strip_and_downcase_username, :on => :create
|
before_validation :strip_and_downcase_username
|
||||||
before_validation :set_current_language, :on => :create
|
before_validation :set_current_language, :on => :create
|
||||||
|
|
||||||
validates_presence_of :username
|
validates_presence_of :username
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ set :use_sudo, false
|
||||||
set :scm_verbose, true
|
set :scm_verbose, true
|
||||||
set :repository_cache, "remote_cache"
|
set :repository_cache, "remote_cache"
|
||||||
set :deploy_via, :checkout
|
set :deploy_via, :checkout
|
||||||
|
set :branch, 'devise_invitable-update'
|
||||||
|
|
||||||
namespace :deploy do
|
namespace :deploy do
|
||||||
task :symlink_config_files do
|
task :symlink_config_files do
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
require 'db/migrate/20110421120744_downcase_usernames'
|
|
||||||
class DowncaseUsernamesAgain < ActiveRecord::Migration
|
|
||||||
def self.up
|
|
||||||
DowncaseUsernames.up
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.down
|
|
||||||
DowncaseUsernames.down
|
|
||||||
end
|
|
||||||
end
|
|
||||||
29
db/migrate/20110513175000_eliminate_stray_user_records.rb
Normal file
29
db/migrate/20110513175000_eliminate_stray_user_records.rb
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
class EliminateStrayUserRecords < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
duplicated_emails = execute("SELECT LOWER(email) from users GROUP BY LOWER(email) HAVING COUNT(*) > 1").to_a
|
||||||
|
duplicated_emails.each do |email|
|
||||||
|
records = execute("SELECT users.id, users.username, users.created_at from users WHERE LOWER(users.email) = '#{email}'").to_a
|
||||||
|
with_username = records.select { |r| !r[1].blank? }
|
||||||
|
if with_username.length == 1
|
||||||
|
execute("DELETE FROM users WHERE LOWER(users.email) = '#{email}' AND users.username IS NULL")
|
||||||
|
end
|
||||||
|
if with_username.length == 0
|
||||||
|
newest_record = records.sort_by{|r| r[2].to_i}.last
|
||||||
|
execute("DELETE FROM users WHERE LOWER(users.email) = '#{email}' AND users.id != #{newest_record[0]}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
execute <<SQL
|
||||||
|
UPDATE users
|
||||||
|
SET users.username = LOWER(users.username)
|
||||||
|
WHERE users.username != LOWER(users.username)
|
||||||
|
SQL
|
||||||
|
execute <<SQL
|
||||||
|
UPDATE users
|
||||||
|
SET users.email = LOWER(users.email)
|
||||||
|
WHERE users.email != LOWER(users.email)
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -102,7 +102,7 @@ describe Invitation do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'invitated user' do
|
context 'invited user' do
|
||||||
it 'by email' do
|
it 'by email' do
|
||||||
@identifier = @users[3].email
|
@identifier = @users[3].email
|
||||||
@type = 'email'
|
@type = 'email'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue