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

Fix User Lookup Via SSO Email: Make Query Case-Insensitive #924

Merged
merged 4 commits into from
Oct 15, 2024

Conversation

aaronskiba
Copy link
Collaborator

Fixes #900

Changes proposed in this PR:

  • Applied .downcase to the SSO email for case-insensitive user lookup:

    email = provider_data.info.email.downcase
    user = User.find_or_initialize_by(email: email)
    • Given that all user emails in the database are stored in lowercase, this change ensures User.find_or_initialize_by(email: email) is case-insensitive (where email is the email provided by SSO/CILogon).
    • Analysis of the identifiers table (where provider.info.email values are stored) shows that some emails contain capital letters, whereas no capitalised emails exist within the users table. Without applying .downcase, the code was susceptible to the bug illustrated in the following comment: ActiveRecord::RecordInvalid: Validation failed: Email has already been taken #900 (comment)
  • Some factoring has also been done: ade1189

This commit is intended to resolve the following issue: #900
- `user.email` is already set as desired within `user = User.find_or_initialize_by(email: email)`
- Also, the `.presence` method seems to simplify the assignment of `firstname` and `surname`. https://apidock.com/rails/Object/presence
Copy link
Collaborator

@lagoan lagoan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks grea! I have a small comment over the use of a variable where we can avoid it.

Comment on lines +195 to +196
firstname: provider_data.info&.first_name.presence || _('First name'),
surname: provider_data.info&.last_name.presence || _('Last name'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this way so much better!

app/models/user.rb Outdated Show resolved Hide resolved
Copy link
Collaborator

@lagoan lagoan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants