Skip to content

Commit

Permalink
fix: Case insensitive email match (#6760)
Browse files Browse the repository at this point in the history
Fixes: https://linear.app/chatwoot/issue/CW-1354/email-id-case-sensitive

Co-authored-by: Sojan <sojan@pepalo.com>
  • Loading branch information
tejaswinichile and sojan-official committed Mar 28, 2023
1 parent fdb067a commit 54a809e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ class User < ApplicationRecord

scope :order_by_full_name, -> { order('lower(name) ASC') }

before_validation do
self.email = email.try(:downcase)
end

def send_devise_notification(notification, *args)
devise_mailer.with(account: Current.account).send(notification, self, *args).deliver_later
end
Expand Down
5 changes: 5 additions & 0 deletions spec/controllers/platform/api/v1/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
)
)
expect(platform_app.platform_app_permissibles.first.permissible_id).to eq data['id']

post '/platform/api/v1/users/', params: { name: 'test', email: 'TesT@test.com', password: 'Password1!' },
headers: { api_access_token: platform_app.access_token.token }, as: :json
data = JSON.parse(response.body)
expect(data['message']).to eq('Email has already been taken')
end

it 'fetch existing user and creates permissible for the user' do
Expand Down
7 changes: 7 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,11 @@
expect(user.will_save_change_to_email?).to be true
end
end

context 'when the supplied email is uppercase' do
it 'downcases the email on save' do
new_user = create(:user, email: 'Test123@test.com')
expect(new_user.email).to eq('test123@test.com')
end
end
end

0 comments on commit 54a809e

Please sign in to comment.