Merge remote-tracking branch 'origin/develop' into feature/frontend_refactor

This commit is contained in:
Alex Gleason
2020-03-11 14:52:10 -05:00
4 changed files with 25 additions and 2 deletions

View File

@@ -39,6 +39,7 @@
# created_by_application_id :bigint(8)
# approved :boolean default(TRUE), not null
# last_read_notification :bigint(8)
# unique_email :string
#
class User < ApplicationRecord
@@ -79,6 +80,7 @@ class User < ApplicationRecord
accepts_nested_attributes_for :invite_request, reject_if: ->(attributes) { attributes['text'].blank? }
validates :locale, inclusion: I18n.available_locales.map(&:to_s), if: :locale?
validates :unique_email, uniqueness: true, on: :create
validates_with BlacklistedEmailValidator, on: :create
validates_with EmailMxValidator, if: :validate_email_dns?
validates :agreement, acceptance: { allow_nil: false, accept: [true, 'true', '1'] }, on: :create
@@ -94,6 +96,7 @@ class User < ApplicationRecord
scope :emailable, -> { confirmed.enabled.joins(:account).merge(Account.searchable) }
before_validation :sanitize_languages
before_validation :set_unique_email
before_create :set_approved
# This avoids a deprecation warning from Rails 5.1
@@ -217,7 +220,7 @@ class User < ApplicationRecord
def allows_group_in_home_feed?
settings.group_in_home_feed
end
def token_for_app(a)
return nil if a.nil? || a.owner != self
Doorkeeper::AccessToken
@@ -346,4 +349,10 @@ class User < ApplicationRecord
end
end
def set_unique_email
user, domain = self.email.split('@')
user = user.split('+').first
user = user.gsub('.', '') if domain == 'gmail.com'
self.unique_email = "#{user}@#{domain}"
end
end