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

Show correct email for authorization confirmation #11667

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

vrajmohan
Copy link
Member

🎫 Ticket

Link to the relevant ticket:
Authorization confirmation doesn't show selected email for partner

🛠 Summary of changes

  1. Refactored code - added a ServiceProviderIdentity#email_address_for_sharing that does the right thing
  2. Added a test to verify correct behavior in SAML
  3. Eliminated EmailContext class that seemed to be of limited value.

📜 Testing Plan

Use the "Steps to reproduce" from the Jira ticket.

@vrajmohan vrajmohan requested a review from a team December 18, 2024 15:46
@vrajmohan vrajmohan force-pushed the vm-correct-email-for-authorization-confirmation branch from 614c31a to b5c849e Compare December 19, 2024 04:29
@vrajmohan vrajmohan marked this pull request as ready for review December 19, 2024 04:30
def last_sign_in_email_address
confirmed_email_addresses.first
end

Copy link
Contributor

Choose a reason for hiding this comment

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

I like how you are using this to simplify things like EmailContext.new(current_user)...etc

Copy link
Contributor

@kevinsmaster5 kevinsmaster5 left a comment

Choose a reason for hiding this comment

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

Looks good and works as expected in bug ticket.

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Nice refactors 👍

Comment on lines -14 to -16
def email_address_count
user.email_addresses.count
end
Copy link
Member

Choose a reason for hiding this comment

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

I don't think these stubs were valid anyways, but might have been trying to refer to this method now removed and we could remove the stub as well?

allow(user).to receive(:email_address_count).and_return(2)

allow(user).to receive(:email_address_count).and_return(2)

app/models/service_provider_identity.rb Show resolved Hide resolved
Comment on lines 524 to 526
def last_sign_in_email_address
confirmed_email_addresses.first
end
Copy link
Member

Choose a reason for hiding this comment

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

Similar comment about test coverage in spec/models/user_spec.rb. I'd be specifically concerned to have regression coverage in how we rely on confirmed_email_addresses to be ordered here, which I wouldn't think is a given.

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO, it would be better to use scopes as shown at the end of https://api.rubyonrails.org/v8.0.1/classes/ActiveRecord/Scoping/Named/ClassMethods.html#method-i-scope. Should I go ahead?

Copy link
Member

Choose a reason for hiding this comment

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

What would scopes do for us here, or at least specifically in regard to my comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

We would be explicit when we say user.email_addresses.confirmed.last_signed_in.

@vrajmohan vrajmohan force-pushed the vm-correct-email-for-authorization-confirmation branch from e17819d to be8d297 Compare December 20, 2024 01:52
@vrajmohan
Copy link
Member Author

Just realizing that I have misunderstood active service provider identities. Fixing...

@vrajmohan vrajmohan force-pushed the vm-correct-email-for-authorization-confirmation branch from be8d297 to 4aa4f42 Compare December 20, 2024 15:34
@vrajmohan vrajmohan requested a review from aduth December 20, 2024 16:09
@aduth
Copy link
Member

aduth commented Dec 20, 2024

Can you resolve the merge conflict?

Comment on lines 214 to 216
context 'when an email address for sharing has been set' do
it 'returns the shared email' do
identity.email_address = shared_email_address
Copy link
Member

Choose a reason for hiding this comment

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

Minor: I might expect the assignment here to happen in a before block so that if we added additional test cases to this context, each would have the same common behavior of "sharing has been set" without having to duplicate the code. Similar to what we're doing with feature flag enabling.

Suggested change
context 'when an email address for sharing has been set' do
it 'returns the shared email' do
identity.email_address = shared_email_address
context 'when an email address for sharing has been set' do
before do
identity.email_address = shared_email_address
end
it 'returns the shared email' do

Same comment applies for context block below this.

email_addresses.where.not(confirmed_at: nil).order('last_sign_in_at DESC NULLS LAST')
email_addresses.confirmed
Copy link
Member

Choose a reason for hiding this comment

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

How are we ensuring last_sign_in_at ordering with this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

This line by itself does not ensure that. The change to User#last_sign_in_email_address on line 524 does it.

Copy link
Member Author

Choose a reason for hiding this comment

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

After further discussion with @aduth, we decided to leave the sort order in, even though the tests pass. We plan to clean this up in a separate PR.

@vrajmohan vrajmohan force-pushed the vm-correct-email-for-authorization-confirmation branch from 4aa4f42 to 7d8fc14 Compare December 20, 2024 18:06
Copy link
Member

Choose a reason for hiding this comment

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

I think a rebase might have gone awry, reintroducing code removed in #11656 (causing build failure).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, saw that! Fixing.

@vrajmohan vrajmohan force-pushed the vm-correct-email-for-authorization-confirmation branch from 7d8fc14 to b83e589 Compare December 20, 2024 19:05
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.

3 participants