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 tighter control on project owner management #3194

Merged
merged 12 commits into from
Oct 7, 2024
Merged

Add tighter control on project owner management #3194

merged 12 commits into from
Oct 7, 2024

Conversation

imnasnainaec
Copy link
Collaborator

@imnasnainaec imnasnainaec commented Jun 28, 2024

Resolves #3114

  • Adds a single controller function, ChangeOwner, for changing the Owner of a project;
  • Prevents all other role-updating functions from adding/removing project owners.
    • The one exception is that CreateUserRole can be used to create a project's first owner (when the project is initially created), but can no longer be used to add a second owner.

This change is Reviewable

Copy link

codecov bot commented Jun 28, 2024

Codecov Report

Attention: Patch coverage is 85.29412% with 10 lines in your changes missing coverage. Please review.

Project coverage is 74.71%. Comparing base (f34f053) to head (56056e0).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
Backend/Controllers/UserRoleController.cs 86.56% 5 Missing and 4 partials ⚠️
...nts/ProjectUsers/CancelConfirmDialogCollection.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3194      +/-   ##
==========================================
+ Coverage   74.59%   74.71%   +0.12%     
==========================================
  Files         280      280              
  Lines       10773    10838      +65     
  Branches     1299     1314      +15     
==========================================
+ Hits         8036     8098      +62     
  Misses       2370     2370              
- Partials      367      370       +3     
Flag Coverage Δ
backend 83.92% <86.56%> (+0.11%) ⬆️
frontend 66.63% <0.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@imnasnainaec imnasnainaec marked this pull request as ready for review July 1, 2024 19:51

// Change the old owner to a project admin
oldUserRole.Role = Role.Administrator;
var oldResult = await _userRoleRepo.Update(oldRoleId, oldUserRole);
Copy link
Contributor

Choose a reason for hiding this comment

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

if this fails doesn't that mean there will be 2 owners? is this work being done in some kind of db transaction?

Copy link
Collaborator Author

@imnasnainaec imnasnainaec Sep 25, 2024

Choose a reason for hiding this comment

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

@hahn-kev You are correct that this failing could result in two owners. The primary motive for this pr was an edge case that could result in 0 owners. While much of this pr is also avoiding multiple owners, I think it's a less critical problem for that unlikely event to happen.

Though perhaps some sort of grouped/pipeline transaction would be the right way to do this. I'll poke at that idea.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

One could use Transactions (https://www.mongodb.com/docs/drivers/csharp/current/fundamentals/transactions/) to make multiple changes and commit them all at once, but it appears to me to require a major refactor of how we interface with the database.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@hahn-kev Thanks for introducing me to transactions.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're welcome.

Yeah transactions are definitely the way to go when you want all your changes to either fail or succeed together.

Copy link
Collaborator Author

@imnasnainaec imnasnainaec left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 5 files reviewed, 1 unresolved discussion (waiting on @hahn-kev and @imnasnainaec)


Backend/Controllers/UserRoleController.cs line 373 at r2 (raw file):

Previously, hahn-kev (Kevin Hahn) wrote…

You're welcome.

Yeah transactions are definitely the way to go when you want all your changes to either fail or succeed together.

Since transactions are not supported in Standalone MongoDB deployments, we'll hold off implementing them until some other month after we've switched to Replica Set deployment.

Copy link
Contributor

@jasonleenaylor jasonleenaylor left a comment

Choose a reason for hiding this comment

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

:lgtm: The transactions will wait. This is a good step in the meantime.

Reviewed 4 of 5 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @hahn-kev)

@imnasnainaec imnasnainaec merged commit f36a699 into master Oct 7, 2024
17 of 18 checks passed
@imnasnainaec imnasnainaec deleted the owner branch October 7, 2024 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Project Settings] Edge case: brand new owner can remove themselves
3 participants