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

3372: Allow users to be added to multiple roles #3386

Merged
merged 10 commits into from
Jun 11, 2023
Merged

Conversation

dorner
Copy link
Collaborator

@dorner dorner commented Feb 17, 2023

Resolves #3372

Description

With the new role capability, there should be nothing stopping a user from belonging to multiple organizations or partners if necessary. This change ensures that the current role (organization or partner) is reflected in whatever the user sees, which allows for the role switcher to work in all cases.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Local and unit tests.

@dorner dorner requested review from awwaiid and cielf February 17, 2023 20:45
@awwaiid
Copy link
Collaborator

awwaiid commented Feb 26, 2023

I don't normally ask for a history squash/rewrite .... but in this case ....... :)

@dorner
Copy link
Collaborator Author

dorner commented Feb 28, 2023

Most of those commits were unrelated to the actual ticket. I've deleted them outright and they should no longer be necessary now that importmaps have been merged.

@cielf
Copy link
Collaborator

cielf commented Mar 3, 2023

@dorner IIRTC, at least some of the tests that are failing are related to this subject matter...

@@ -160,22 +160,6 @@
expect(subject).to redirect_to(dashboard_path)
end
end

Copy link
Collaborator

@cielf cielf Mar 3, 2023

Choose a reason for hiding this comment

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

I'm not sure why you are removing these tests. On the surface it seems like we would still want to make sure that you can't access donations for a different org, and that you have to be signed in to access the donations

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True - let me rejig these instead. The issue is that it was depending on the organization_id in the parameter, which is no longer the real indication of which organization you're looking at. In fact, we could remove that organization_id which we add to every URL - it makes it a bit confusing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah I know why I removed them - because I added application-level tests instead. So rather than testing a single controller we're now testing every controller in the app 😄

Copy link
Collaborator

Choose a reason for hiding this comment

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

Alright, then.

@cielf
Copy link
Collaborator

cielf commented Mar 3, 2023

@dorner. I've skimmed the changes, and IIRTC, if someone gets invited to a second role, they are not getting invited. Which, on the one hand, means they don't have to accept the second invite, and have the whole annoying "you can't sign in, you have a pending invitation" thing. Yay!

But there would be value in them getting notified that they have been invited to the second role, which, IIRTC, they won't be? We've already seen a couple of cases where someone has signed up as a bank (when they probably shouldn't have), and then years later, is being brought on as a partner. Although we don't want that tail wagging our dog, it will be a support ticket every time a bank expects an invitation to be sent, but the user doesn't get any notification.


return current_role.resource if current_role.resource.is_a?(Organization)

Organization.find_by(short_name: params[:organization_id])
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure why you aren't setting @current_organization if it isn't already set, in the new version. That feels like it could have some side effects.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope. Did a search and nothing else reads this instance variable (as it should be).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see anything that ever sets the instance variable?

@cielf
Copy link
Collaborator

cielf commented Mar 3, 2023

Hopefully this is nearly the final nail in the grand edifice you've been building over these last few months!
I'll want to manually test the partner switching thing, though-- I've slotted that in for tomorrow afternoon.

@@ -9,7 +9,6 @@ def self.invite(email:, resource:, name: nil, roles: [])

user = User.find_by(email: email)
if user
user.invite!
Copy link
Collaborator

Choose a reason for hiding this comment

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

How does this interact with the ability of the banks to resend the invitations to the partner? Maybe invite! if the user has not yet accepted their invitation/set a password?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There should be a way to force this behavior. Let me take a look.

@cielf
Copy link
Collaborator

cielf commented Mar 3, 2023

Hopefully this is nearly the final nail in the grand edifice you've been building over these last few months! I'll want to manually test the partner switching thing, though-- I've slotted that in for tomorrow afternoon.

The partner switching thing seems to work now on local, anyway. Hooray!

@dorner
Copy link
Collaborator Author

dorner commented Mar 24, 2023

@cielf made some changes and fixes addressing the comments! Need to wait for tests to run but please take another look.

@cielf
Copy link
Collaborator

cielf commented Mar 29, 2023

@dorner Well, it looks like there are tests failing in the general area of the change -- I can take a look (probably tomorrow), but might I just as well wait until those are resolved?

@cielf
Copy link
Collaborator

cielf commented Apr 1, 2023

@dorner As to the interplay between this and.. #3429 .. How does someone know that they have been invited to a second partner or diaper bank -- We may need to take a step back and draw out all the scenarios.

@dorner
Copy link
Collaborator Author

dorner commented Apr 3, 2023

@cielf in this PR I added another e-mail to be sent out whenever a role is added to an existing user.

Not sure when I'll have time to look at the failing tests. 😦

@cielf
Copy link
Collaborator

cielf commented Apr 3, 2023

'Salright -- I expect to not see much of you for the next week. We're purposely not doing a release next weekend, also.

@dorner
Copy link
Collaborator Author

dorner commented Apr 14, 2023

Tests should all pass now! 🤞

@cielf
Copy link
Collaborator

cielf commented Apr 26, 2023

Hey @dorner... There's a specific situation that this is not covering.
The business scenario is that someone is working for a bank (using their own email), then they go and work for a partner. The bank disables them (naturally), but when the partner tries to add them, they will get a 'PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_users_on_email" DETAIL: Key (email)=(user_1@example.com) already exists.'

And it's not far-fetched, I'm afraid -- we have essentially that situation at the moment (see support starting at 3:38 on Monday April 24)
Does that needs to be a separate issue -- that when you deactivate a user as a bank, you are removing the role, rather than removing their ability to log in?

@dorner
Copy link
Collaborator Author

dorner commented Apr 27, 2023

Yeah that does sound like a separate issue.

@cielf
Copy link
Collaborator

cielf commented May 6, 2023

Have added the additional proto-issue to the backlog

@cielf
Copy link
Collaborator

cielf commented May 24, 2023

Putting a reminder for @awwaiid here too!

Copy link
Collaborator

@awwaiid awwaiid left a comment

Choose a reason for hiding this comment

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

All looks good


return current_role.resource if current_role.resource.is_a?(Organization)

Organization.find_by(short_name: params[:organization_id])
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see anything that ever sets the instance variable?

@awwaiid
Copy link
Collaborator

awwaiid commented Jun 11, 2023

(I walked through all the code changes and did local manual testing)

@awwaiid awwaiid merged commit 68a71c6 into main Jun 11, 2023
@awwaiid awwaiid deleted the 3372-multi-partner branch June 11, 2023 15:28
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.

Allowing users to have multiple partners (with a single email)
3 participants