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:
parent
255c39ef5a
commit
ea7cbe1908
|
@ -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)
|
||||
elsif self.commentable.class == Grit::Commit
|
||||
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.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}
|
||||
|
|
|
@ -60,8 +60,8 @@ class User < ActiveRecord::Base
|
|||
def find_for_database_authentication(warden_conditions)
|
||||
conditions = warden_conditions.dup
|
||||
login = conditions.delete(:login)
|
||||
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))",
|
||||
where(conditions).where("lower(uname) = :value OR " +
|
||||
"exists (select null from user_emails m where m.user_id = m.user_id and lower(m.email) = :value)",
|
||||
{:value => login.downcase}).first
|
||||
end
|
||||
|
||||
|
|
|
@ -3,15 +3,7 @@ class UserEmail < ActiveRecord::Base
|
|||
|
||||
belongs_to :user
|
||||
|
||||
validates :email_lower, :uniqueness => true
|
||||
validates :email, :uniqueness => 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
|
||||
|
|
|
@ -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
|
46
db/schema.rb
46
db/schema.rb
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# 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|
|
||||
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
|
||||
|
||||
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|
|
||||
t.string "description"
|
||||
t.string "name"
|
||||
|
@ -263,6 +270,27 @@ ActiveRecord::Schema.define(:version => 20120129120025) do
|
|||
t.string "owner_type"
|
||||
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|
|
||||
t.string "name", :null => false
|
||||
t.integer "arch_id", :null => false
|
||||
|
@ -299,29 +327,29 @@ ActiveRecord::Schema.define(:version => 20120129120025) do
|
|||
end
|
||||
|
||||
create_table "user_emails", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
t.string "email", :null => false
|
||||
t.integer "user_id", :null => false
|
||||
t.string "email", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "email_lower", :null => false
|
||||
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"
|
||||
|
||||
create_table "users", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "email", :default => "", :null => false
|
||||
t.string "encrypted_password", :limit => 128, :default => "", :null => false
|
||||
t.string "email", :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.datetime "reset_password_sent_at"
|
||||
t.string "remember_token"
|
||||
t.datetime "remember_created_at"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.text "ssh_key"
|
||||
t.string "uname"
|
||||
t.string "role"
|
||||
t.string "language", :default => "en"
|
||||
t.string "language", :default => "en"
|
||||
end
|
||||
|
||||
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
||||
|
|
|
@ -13,16 +13,5 @@ describe UserEmail do
|
|||
@stranger.emails.create(:email => @user.emails.first.email)
|
||||
@stranger.emails.exists?(:email => @user.emails.first.email).should be_false
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue