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
Allow for bulk updating AuthRequest
database objects
#4053
base: main
Are you sure you want to change the base?
Allow for bulk updating AuthRequest
database objects
#4053
Conversation
bb61771
to
c6974aa
Compare
afe11b7
to
d16f587
Compare
To facilitate a new bulk device login request approval workflow in the admin console we need to update `IAuthRequestRepisitory` (owned by Auth team) to include an`UpdateManyAsync()` method. It should accept a list of `AuthRequest` table objects, and implementations will do a very simple 1:1 update of the passed in data. This commit adds an `UpdateManyAsync()` method to the `AuthRequestRepository` interface.
This commit stubs out implementations of `IAuthRequestRepository.UpdateManyAsync()` so the method signature can be called in unit tests. At this stage the methods are not implemented.
To facilitate a bulk update operation for auth requests a new user defined type will need to be written that can be used as a table input to the stored procedure. This will follow a similar pattern to how the `OragnizationSponsorshipType` works and is used by the stored procedure `OrganizationSponsorship_UpdateMany`.
To facilitate the bulk updating of auth request table objects this commit adds a new stored procedure to update a collection of entities on `AuthRequest` table by their primary key. It updates all properties, for convention, but the endpoint created later will only change the `Approved`, `ResponseDate`, `Key`, `MasterPasswordHash`, and `AuthenticationDate` properties.
This commit simply applies a migration script containing the new user defined type and stored procedure comitted previously.
The current pattern in place for bulk update stored procedures is to pass a `DataTable` through Dapper as an input for the update stored procedure being run. In order to facilitate the new bulk update procedure for the`AuthRequest` type we need a function added that can convert an `IEnumerable<AuthRequest>` to a `DataTable`. This is commit follows the convention of having a static class with a conversion method in a `Helpers` folder: `AuthRequestHelpers.ToDataTable()`.
This commit implements `AuthRequestRepository.UpdateMany()` for the Dapper implementation of `AuthRequestRepository`. It connects the stored procedure, `DataTable` converter, and Dapper-focused unit test commits written previously into one exposed method that can be referenced by service callers.
This commit implements the new `IAuthRequestRepository.UpdateManyAsync()`method in the Entity Framework skew of the repository layer. It checks to make sure the passed in list has auth requests, converts them all to an Entity Framework entity, and then uses `UpdateRange` to apply the whole thing over in the database context.
d16f587
to
9d5b27e
Compare
New Issues
Fixed Issues
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4053 +/- ##
==========================================
- Coverage 38.44% 38.42% -0.03%
==========================================
Files 1209 1209
Lines 58545 58577 +32
Branches 5585 5589 +4
==========================================
Hits 22509 22509
- Misses 34991 35023 +32
Partials 1045 1045 ☔ View full report in Codecov by Sentry. |
is_user_defined = 1 | ||
) | ||
BEGIN | ||
CREATE TYPE [dbo].[AuthRequestType] AS TABLE( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In discussions with @withinfocus, we would like to move away from creating type objects in sql server and use something a little more generic like json for bulk inserts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some concerns with the Entity Framework and Stored Procedure implementations not matching in function.
@@ -69,4 +69,29 @@ public async Task<ICollection<OrganizationAdminAuthRequest>> GetManyPendingByOrg | |||
return orgUserAuthRequests; | |||
} | |||
} | |||
|
|||
public async Task UpdateManyAsync(IEnumerable<Core.Auth.Entities.AuthRequest> authRequests) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ : Since this is doing more than updating the name might make more sense to be SavingManyAsync
.
@@ -0,0 +1,30 @@ | |||
CREATE PROCEDURE [dbo].[AuthRequest_UpdateMany] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ : I don't think this accomplishes the same "add or update" methodology of the EF implementation. This method only updates the Auth Requests, it doesn't also add them if they don't exist. Should Auth Requests even be approved if they don't exist?
5d2c926
to
fab5fde
Compare
fab5fde
to
cea0589
Compare
Type of change
Objective
To facilitate a new bulk device login request approval workflow in the admin
console we need to update
IAuthRequestRepisitory
to include anUpdateManyAsync()
method. It should accept a list ofAuthRequest
tableobjects, and implementations will do a very simple 1:1 update of the passed
in data.
This pull request implements this behavior in the repository and database
layers of the bitwarden server.
Code changes
See the commits tab
References
to the more general and high level functions written in this PR for the repository layer.