Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add user id verification to user by external id #216

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ def name
end

scope :by_external_identifier, lambda { |identifiers|
identifiers = [identifiers].flatten.compact.map(&:downcase)
joins('LEFT JOIN user_service_identifiers ON users.id = user_service_identifiers.user_id')
.where('lower(users.email) IN (:identifiers) OR lower(user_service_identifiers.identifier) IN (:identifiers)',
identifiers:)
}
identifiers = [identifiers].flatten.compact.map(&:to_s).map(&:downcase)
joins('LEFT JOIN user_service_identifiers ON users.id = user_service_identifiers.user_id')
.where('lower(users.email) IN (:identifiers) OR lower(user_service_identifiers.identifier) IN
(:identifiers) OR CAST(users.id AS TEXT) IN (:identifiers)',
identifiers:)
}

def self.by_name(full_name)
name_parts = full_name.split
Expand Down
6 changes: 6 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@
user = create(:user, email: '[email protected]')
expect(User.by_external_identifier(user.email).first).to eql(user)
end

it 'returns the user by the user id' do
user = create(:user, email: '[email protected]')

expect(User.by_external_identifier(user.id).first).to eql(user)
end
end

context '#by_name' do
Expand Down
Loading