when user verifies a secondary email, revalidate GPG signatures
This commit is contained in:
parent
a32f1dddf2
commit
442dbf6d4b
|
@ -7,6 +7,8 @@ class Email < ActiveRecord::Base
|
||||||
validates :email, presence: true, uniqueness: true, email: true
|
validates :email, presence: true, uniqueness: true, email: true
|
||||||
validate :unique_email, if: ->(email) { email.email_changed? }
|
validate :unique_email, if: ->(email) { email.email_changed? }
|
||||||
|
|
||||||
|
after_commit :update_invalid_gpg_signatures, if: -> { previous_changes.key?('confirmed_at') }
|
||||||
|
|
||||||
devise :confirmable
|
devise :confirmable
|
||||||
self.reconfirmable = false # currently email can't be changed, no need to reconfirm
|
self.reconfirmable = false # currently email can't be changed, no need to reconfirm
|
||||||
|
|
||||||
|
@ -17,4 +19,9 @@ class Email < ActiveRecord::Base
|
||||||
def unique_email
|
def unique_email
|
||||||
self.errors.add(:email, 'has already been taken') if User.exists?(email: self.email)
|
self.errors.add(:email, 'has already been taken') if User.exists?(email: self.email)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# once email is confirmed, update the gpg signatures
|
||||||
|
def update_invalid_gpg_signatures
|
||||||
|
user.update_invalid_gpg_signatures if confirmed?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,4 +11,21 @@ describe Email do
|
||||||
expect(described_class.new(email: ' inFO@exAMPLe.com ').email)
|
expect(described_class.new(email: ' inFO@exAMPLe.com ').email)
|
||||||
.to eq 'info@example.com'
|
.to eq 'info@example.com'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#update_invalid_gpg_signatures' do
|
||||||
|
let(:user) do
|
||||||
|
create(:user, email: 'tula.torphy@abshire.ca').tap do |user|
|
||||||
|
user.skip_reconfirmation!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
|
it 'synchronizes the gpg keys when the email is updated' do
|
||||||
|
email = user.emails.create(email: 'new@email.com')
|
||||||
|
expect(user).to receive(:update_invalid_gpg_signatures)
|
||||||
|
email.confirm
|
||||||
|
# email.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue