debian-mirror-gitlab/app/models/email.rb

39 lines
1 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
class Email < ActiveRecord::Base
2015-04-26 12:48:37 +05:30
include Sortable
2018-03-17 18:26:18 +05:30
include Gitlab::SQL::Pattern
2015-04-26 12:48:37 +05:30
2014-09-02 18:07:02 +05:30
belongs_to :user
validates :user_id, presence: true
2016-04-02 18:10:28 +05:30
validates :email, presence: true, uniqueness: true, email: true
2014-09-02 18:07:02 +05:30
validate :unique_email, if: ->(email) { email.email_changed? }
2018-03-17 18:26:18 +05:30
scope :confirmed, -> { where.not(confirmed_at: nil) }
after_commit :update_invalid_gpg_signatures, if: -> { previous_changes.key?('confirmed_at') }
devise :confirmable
2019-03-02 22:35:43 +05:30
self.reconfirmable = false # currently email can't be changed, no need to reconfirm
2018-03-17 18:26:18 +05:30
delegate :username, to: :user
2017-08-17 22:00:37 +05:30
def email=(value)
write_attribute(:email, value.downcase.strip)
2014-09-02 18:07:02 +05:30
end
def unique_email
self.errors.add(:email, 'has already been taken') if User.exists?(email: self.email)
end
2018-03-17 18:26:18 +05:30
2018-11-18 11:00:15 +05:30
def accept_pending_invitations!
user.accept_pending_invitations!
end
2018-03-17 18:26:18 +05:30
# once email is confirmed, update the gpg signatures
def update_invalid_gpg_signatures
user.update_invalid_gpg_signatures if confirmed?
end
2014-09-02 18:07:02 +05:30
end