-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue #6847 #6905
Fix issue #6847 #6905
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ class User < ActiveRecord::Base | |
validates :color_theme, inclusion: {in: AVAILABLE_COLOR_THEME_CODES}, allow_blank: true | ||
validates_format_of :unconfirmed_email, :with => Devise.email_regexp, :allow_blank => true | ||
|
||
validate :unconfirmed_email_quasiuniqueness | ||
|
||
validates_presence_of :person, :unless => proc {|user| user.invitation_token.present?} | ||
validates_associated :person | ||
validate :no_person_with_same_username | ||
|
@@ -83,6 +85,8 @@ class User < ActiveRecord::Base | |
|
||
before_save :guard_unconfirmed_email | ||
|
||
after_save :remove_invalid_unconfirmed_emails | ||
|
||
def self.all_sharing_with_person(person) | ||
User.joins(:contacts).where(:contacts => {:person_id => person.id}) | ||
end | ||
|
@@ -484,6 +488,13 @@ def mine?(target) | |
end | ||
|
||
|
||
# Ensure that the unconfirmed email isn't already someone's email | ||
def unconfirmed_email_quasiuniqueness | ||
if User.exists?(["id != ? AND email = ?", id, unconfirmed_email]) | ||
errors.add(:unconfirmed_email, "is already in use") | ||
end | ||
end | ||
|
||
def guard_unconfirmed_email | ||
self.unconfirmed_email = nil if unconfirmed_email.blank? || unconfirmed_email == email | ||
|
||
|
@@ -492,6 +503,16 @@ def guard_unconfirmed_email | |
end | ||
end | ||
|
||
# Whenever email is set, clear all unconfirmed emails which match | ||
def remove_invalid_unconfirmed_emails | ||
if email_changed? | ||
User.where("unconfirmed_email = ?", email).find_each do |problem_user| | ||
problem_user.unconfirmed_email = nil | ||
problem_user.save | ||
end | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think setting it to |
||
|
||
# Generate public/private keys for User and associated Person | ||
def generate_keys | ||
key_size = (Rails.env == 'test' ? 512 : 4096) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -305,6 +305,13 @@ | |
alice.email = "somebody@anywhere" | ||
expect(alice).not_to be_valid | ||
end | ||
|
||
it "resets a matching unconfirmed_email on save" do | ||
eve.update_attribute :unconfirmed_email, "[email protected]" | ||
alice.update_attribute :email, "[email protected]" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use |
||
eve.reload | ||
expect(eve.unconfirmed_email).to eql(nil) | ||
end | ||
end | ||
|
||
describe "of unconfirmed_email" do | ||
|
@@ -321,6 +328,11 @@ | |
expect(alice).to be_valid | ||
end | ||
|
||
it "requires an unconfirmed_email address which is not another user's email address" do | ||
alice.unconfirmed_email = eve.email | ||
expect(alice).not_to be_valid | ||
end | ||
|
||
it "requires a valid unconfirmed_email address" do | ||
alice.unconfirmed_email = "somebody@anywhere" | ||
expect(alice).not_to be_valid | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a user facing error, right? It should use a translation then :)