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
commit af1627815c
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
4 changed files with 25 additions and 2 deletions

View File

@ -39,6 +39,7 @@
# created_by_application_id :bigint(8) # created_by_application_id :bigint(8)
# approved :boolean default(TRUE), not null # approved :boolean default(TRUE), not null
# last_read_notification :bigint(8) # last_read_notification :bigint(8)
# unique_email :string
# #
class User < ApplicationRecord class User < ApplicationRecord
@ -79,6 +80,7 @@ class User < ApplicationRecord
accepts_nested_attributes_for :invite_request, reject_if: ->(attributes) { attributes['text'].blank? } accepts_nested_attributes_for :invite_request, reject_if: ->(attributes) { attributes['text'].blank? }
validates :locale, inclusion: I18n.available_locales.map(&:to_s), if: :locale? 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 BlacklistedEmailValidator, on: :create
validates_with EmailMxValidator, if: :validate_email_dns? validates_with EmailMxValidator, if: :validate_email_dns?
validates :agreement, acceptance: { allow_nil: false, accept: [true, 'true', '1'] }, on: :create 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) } scope :emailable, -> { confirmed.enabled.joins(:account).merge(Account.searchable) }
before_validation :sanitize_languages before_validation :sanitize_languages
before_validation :set_unique_email
before_create :set_approved before_create :set_approved
# This avoids a deprecation warning from Rails 5.1 # This avoids a deprecation warning from Rails 5.1
@ -346,4 +349,10 @@ class User < ApplicationRecord
end end
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 end

View File

@ -0,0 +1,5 @@
class AddUniqueEmailToUsers < ActiveRecord::Migration[5.2]
def change
add_column :users, :unique_email, :string
end
end

View File

@ -0,0 +1,7 @@
class AddIndexUniqueEmailOnUsers < ActiveRecord::Migration[5.2]
disable_ddl_transaction!
def change
add_index :users, :unique_email, algorithm: :concurrently
end
end

View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_12_02_004114) do ActiveRecord::Schema.define(version: 2020_03_10_224203) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -824,11 +824,13 @@ ActiveRecord::Schema.define(version: 2019_12_02_004114) do
t.bigint "created_by_application_id" t.bigint "created_by_application_id"
t.boolean "approved", default: true, null: false t.boolean "approved", default: true, null: false
t.bigint "last_read_notification" t.bigint "last_read_notification"
t.string "unique_email"
t.index ["account_id"], name: "index_users_on_account_id" t.index ["account_id"], name: "index_users_on_account_id"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["created_by_application_id"], name: "index_users_on_created_by_application_id" t.index ["created_by_application_id"], name: "index_users_on_created_by_application_id"
t.index ["email"], name: "index_users_on_email", unique: true t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
t.index ["unique_email"], name: "index_users_on_unique_email"
end end
create_table "web_push_subscriptions", force: :cascade do |t| create_table "web_push_subscriptions", force: :cascade do |t|