Skip to content

Show correct email for authorization confirmation#11667

Merged
vrajmohan merged 1 commit intomainfrom
vm-correct-email-for-authorization-confirmation
Dec 27, 2024
Merged

Show correct email for authorization confirmation#11667
vrajmohan merged 1 commit intomainfrom
vm-correct-email-for-authorization-confirmation

Conversation

@vrajmohan
Copy link
Contributor

🎫 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
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
Contributor

@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
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines 524 to 526
Copy link
Contributor

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
Contributor 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
Contributor

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
Contributor 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
Contributor 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
Contributor

aduth commented Dec 20, 2024

Can you resolve the merge conflict?

Comment on lines 214 to 216
Copy link
Contributor

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.

Copy link
Contributor

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
Contributor 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
Contributor 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
Contributor

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
Contributor 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 2 times, most recently from b83e589 to 076f430 Compare December 26, 2024 16:11
Comment on lines 52 to 54
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a scope? Can we mark it as one with

Suggested change
def self.last_sign_in
order('last_sign_in_at DESC NULLS LAST').first
end
scope :last_sign_in, -> { order('last_sign_in_at DESC NULLS LAST').first }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my opinion, a "scope" has the connotation of a filter and not an ordering. I followed the example described in the Rails docs itself (see the last couple of sections).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, scopes should return an ActiveRecord::Relation or nil whereas we are returning a single object.

@vrajmohan vrajmohan force-pushed the vm-correct-email-for-authorization-confirmation branch 2 times, most recently from 09d7e6d to 0cc4157 Compare December 26, 2024 17:24
@vrajmohan vrajmohan requested a review from mdiarra3 December 27, 2024 00:14
changelog: Upcoming Features, Partner account, Select email to share with partner

- Refactor - add a ServiceProviderIdentity#email_address_for_sharing that does the right thing
- Add tests to verify correct behavior in SAML and OIDC
- Eliminate EmailContext class that seemed to be of limited value.
- Create method EmailAddress#last_sign_in
- Remove code duplication from SAML and OIDC
- Get rid of EmailContext
- Get rid of `reek` remnants
- Fix minor typos
@vrajmohan vrajmohan force-pushed the vm-correct-email-for-authorization-confirmation branch from 0cc4157 to 2c07e2a Compare December 27, 2024 16:56
@vrajmohan vrajmohan merged commit 9e71b28 into main Dec 27, 2024
@vrajmohan vrajmohan deleted the vm-correct-email-for-authorization-confirmation branch December 27, 2024 17:14
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.

5 participants