Revert "[refs #114] fix emails uniqueness"

This reverts commit bc9649561f5b8ac58f9b27d31d66365f16d0cce0.

Conflicts:

	app/models/subscribe.rb
	app/models/user_email.rb
This commit is contained in:
Alexander Machehin 2012-01-30 12:15:33 +06:00
parent 255c39ef5a
commit ea7cbe1908
6 changed files with 41 additions and 50 deletions

View File

@ -28,7 +28,7 @@ class Comment < ActiveRecord::Base
self.commentable.subscribes.create(:user => self.user) if !self.commentable.subscribes.exists?(:user_id => self.user.id) self.commentable.subscribes.create(:user => self.user) if !self.commentable.subscribes.exists?(:user_id => self.user.id)
elsif self.commentable.class == Grit::Commit elsif self.commentable.class == Grit::Commit
recipients = self.project.relations.by_role('admin').where(:object_type => 'User').map &:object # admins recipients = self.project.relations.by_role('admin').where(:object_type => 'User').map &:object # admins
recipients << self.user << UserEmail.where(:email_lower => self.commentable.committer.email.downcase).first.try(:user) # commentor and committer recipients << self.user << UserEmail.where(:email => self.commentable.committer.email).first.try(:user) # commentor and committer
recipients << self.project.owner if self.project.owner_type == 'User' # project owner recipients << self.project.owner if self.project.owner_type == 'User' # project owner
recipients.compact.uniq.each do |user| recipients.compact.uniq.each do |user|
options = {:project_id => self.project.id, :subscribeable_id => self.commentable.id, :subscribeable_type => self.commentable.class.name, :user_id => user.id} options = {:project_id => self.project.id, :subscribeable_id => self.commentable.id, :subscribeable_type => self.commentable.class.name, :user_id => user.id}

View File

@ -60,8 +60,8 @@ class User < ActiveRecord::Base
def find_for_database_authentication(warden_conditions) def find_for_database_authentication(warden_conditions)
conditions = warden_conditions.dup conditions = warden_conditions.dup
login = conditions.delete(:login) login = conditions.delete(:login)
where(conditions).where("(lower(uname) = :value OR \ where(conditions).where("lower(uname) = :value OR " +
exists (select null from user_emails m where m.user_id = m.user_id and m.email_lower = :value))", "exists (select null from user_emails m where m.user_id = m.user_id and lower(m.email) = :value)",
{:value => login.downcase}).first {:value => login.downcase}).first
end end

View File

@ -3,15 +3,7 @@ class UserEmail < ActiveRecord::Base
belongs_to :user belongs_to :user
validates :email_lower, :uniqueness => true validates :email, :uniqueness => true
validates :email, :presence => true validates :email, :presence => true
before_save :set_lower
before_validation :set_lower
private
def set_lower
self.email_lower = self.email.downcase
end
end end

View File

@ -1,18 +0,0 @@
class AddEmailLowerToUserEmails < ActiveRecord::Migration
def self.up
add_column :user_emails, :email_lower, :string
remove_index :user_emails, :email
UserEmail.reset_column_information
UserEmail.update_all("email_lower = lower(email)")
change_column :user_emails, :email_lower, :string, :null => false
add_index :user_emails, :email_lower
end
def self.down
remove_column :user_emails, :email_lower
add_index :user_emails, :email
remove_index :user_emails, :email_lower
end
end

View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120129120025) do ActiveRecord::Schema.define(:version => 20120123161250) do
create_table "arches", :force => true do |t| create_table "arches", :force => true do |t|
t.string "name", :null => false t.string "name", :null => false
@ -167,6 +167,13 @@ ActiveRecord::Schema.define(:version => 20120129120025) do
add_index "issues", ["project_id", "serial_id"], :name => "index_issues_on_project_id_and_serial_id", :unique => true add_index "issues", ["project_id", "serial_id"], :name => "index_issues_on_project_id_and_serial_id", :unique => true
create_table "permissions", :force => true do |t|
t.integer "right_id"
t.integer "role_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "platforms", :force => true do |t| create_table "platforms", :force => true do |t|
t.string "description" t.string "description"
t.string "name" t.string "name"
@ -263,6 +270,27 @@ ActiveRecord::Schema.define(:version => 20120129120025) do
t.string "owner_type" t.string "owner_type"
end end
create_table "rights", :force => true do |t|
t.string "name", :null => false
t.string "controller", :null => false
t.string "action", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "role_lines", :force => true do |t|
t.integer "role_id"
t.integer "relation_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "roles", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "rpms", :force => true do |t| create_table "rpms", :force => true do |t|
t.string "name", :null => false t.string "name", :null => false
t.integer "arch_id", :null => false t.integer "arch_id", :null => false
@ -299,29 +327,29 @@ ActiveRecord::Schema.define(:version => 20120129120025) do
end end
create_table "user_emails", :force => true do |t| create_table "user_emails", :force => true do |t|
t.integer "user_id", :null => false t.integer "user_id", :null => false
t.string "email", :null => false t.string "email", :null => false
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "email_lower", :null => false
end end
add_index "user_emails", ["email_lower"], :name => "index_user_emails_on_email_lower" add_index "user_emails", ["email"], :name => "index_user_emails_on_email"
add_index "user_emails", ["user_id"], :name => "index_user_emails_on_user_id" add_index "user_emails", ["user_id"], :name => "index_user_emails_on_user_id"
create_table "users", :force => true do |t| create_table "users", :force => true do |t|
t.string "name" t.string "name"
t.string "email", :default => "", :null => false t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "password_salt", :default => "", :null => false
t.string "reset_password_token" t.string "reset_password_token"
t.datetime "reset_password_sent_at" t.string "remember_token"
t.datetime "remember_created_at" t.datetime "remember_created_at"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.text "ssh_key" t.text "ssh_key"
t.string "uname" t.string "uname"
t.string "role" t.string "role"
t.string "language", :default => "en" t.string "language", :default => "en"
end end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true add_index "users", ["email"], :name => "index_users_on_email", :unique => true

View File

@ -13,16 +13,5 @@ describe UserEmail do
@stranger.emails.create(:email => @user.emails.first.email) @stranger.emails.create(:email => @user.emails.first.email)
@stranger.emails.exists?(:email => @user.emails.first.email).should be_false @stranger.emails.exists?(:email => @user.emails.first.email).should be_false
end end
it 'should not create duplicate lowercase emails' do
@stranger = Factory(:user)
@stranger.emails.create(:email => @user.email.upcase)
@stranger.emails.exists?(:email => @user.email.upcase).should be_false
end
it 'should not create too many emails' do
15.times {|i| @user.emails.create(:email => Factory.next(:email))}
@user.emails.count.should be_equal(UserEmail::MAX_EMAILS)
end
end end
end end