* feat: Add stored procedure for reading organization user details with premium access by organization ID
The code changes include:
- Addition of a new stored procedure [dbo].[OrganizationUserUserDetailsWithPremiumAccess_ReadByOrganizationId] to read organization user details with premium access by organization ID
- Modification of the IUserService interface to include an optional parameter for checking two-factor authentication with premium access
- Modification of the UserService class to handle the new optional parameter in the TwoFactorIsEnabledAsync method
- Addition of a new method GetManyDetailsWithPremiumAccessByOrganizationAsync in the IOrganizationUserRepository interface to retrieve organization user details with premium access by organization ID
- Addition of a new view [dbo].[OrganizationUserUserDetailsWithPremiumAccessView] to retrieve organization user details with premium access
* Add IUserRepository.SearchDetailsAsync that includes the field HasPremiumAccess
* Check the feature flag on Admin.UsersController to see if the optimization runs
* Modify PolicyService to run query optimization if the feature flag is enabled
* Refactor the parameter check on UserService.TwoFactorIsEnabledAsync
* Run query optimization on public MembersController if feature flag is enabled
* Restore refactor
* Reverted change used for development
* Add unit tests for OrganizationService.RestoreUser
* Separate new CheckPoliciesBeforeRestoreAsync optimization into new method
* Add more unit tests
* Apply refactor to bulk restore
* Add GetManyDetailsAsync method to IUserRepository. Add ConfirmUsersAsync_vNext method to IOrganizationService
* Add unit tests for ConfirmUser_vNext
* Refactor the optimization to use the new TwoFactorIsEnabledAsync method instead of changing the existing one
* Removed unused sql scripts and added migration script
* Remove unnecessary view
* chore: Remove unused SearchDetailsAsync method from IUserRepository and UserRepository
* refactor: Use UserDetails constructor in UserRepository
* Add summary to IUserRepository.GetManyDetailsAsync
* Add summary descriptions to IUserService.TwoFactorIsEnabledAsync
* Remove obsolete annotation from IUserRepository.UpdateUserKeyAndEncryptedDataAsync
* refactor: Rename UserDetails to UserWithCalculatedPremium across the codebase
* Extract IUserService.TwoFactorIsEnabledAsync into a new TwoFactorIsEnabledQuery class
* Add unit tests for TwoFactorIsEnabledQuery
* Update TwoFactorIsEnabledQueryTests to include additional provider types
* Refactor TwoFactorIsEnabledQuery
* Refactor TwoFactorIsEnabledQuery and update tests
* refactor: Update TwoFactorIsEnabledQueryTests to include test for null TwoFactorProviders
* refactor: Improve TwoFactorIsEnabledQuery and update tests
* refactor: Improve TwoFactorIsEnabledQuery and update tests
* Remove empty <returns> from summary
* Update User_ReadByIdsWithCalculatedPremium stored procedure to accept JSON array of IDs
* Updated org edit form scripts to dynamically update expected values
* Added script to update null values on organization table
* Updated script to only add MaxStorageGb for premium tiers. Removed setting of seats since it's not a valid edge case
* Updated GetPlansHelper() to not use annonymous properties
* Remove Organization.FlexibleCollections from code
* Drop Organization.FlexibleCollections column in EF databases
(MSSQL column to be retained for 1 additional deployment to support rollback in cloud)
These sprocs were used to remove AccessAll from
cipher access logic. Now the original sprocs have been
updated with the new logic, these v2 sprocs are unused
and are being dropped to complete the EDD cycle.
These updated sprocs removed AccessAll from cipher access logic.
The non-versioned sprocs have been updated with the new logic and
these v2 copies are now unused. They are being dropped to complete
the EDD cycle.
Final removal of AccessAll logic in CollectionCipher sprocs. We had v2 sprocs already
containing this updated logic that were never used; copy the v2 logic back to the
original sprocs so that we start using it. v2 sprocs will be dropped later.
* Sql-backed IDistributedCache
* sqlserver cache table
* remove unused using
* setup EF entity
* cache indexes
* add back cipher
* revert SetupEntityFramework change
* ef cache
* EntityFrameworkCache
* IServiceScopeFactory for db context
* implement EntityFrameworkCache
* move to _serviceScopeFactory
* move to config file
* ef migrations
* fixes
* datetime and error codes
* revert migrations
* migrations
* format
* static and namespace fix
* use time provider
* Move SQL migration and remove EF one for the moment
* Add clean migration of just the new table
* Formatting
* Test Custom `IDistributedCache` Implementation
* Add Back Logging
* Remove Double Logging
* Skip Test When Not EntityFrameworkCache
* Format
---------
Co-authored-by: Matt Bishop <mbishop@bitwarden.com>
Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>
* Added check for revoked users
* removed check for users as any user status with can manage access should hide the add access badge
* updated comments
* [deps] DbOps: Update EntityFrameworkCore to v8
* Only Run EnsureDeleted If Factory Owns Connection
This only worked because of a bug in dotnet/efcore#33930 that was fixed in 8.0.
---------
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>
* Moved AccountsBilling controller to be owned by Billing
* Added org billing history endpoint
* Updated GetBillingInvoicesAsync to only retrieve paid, open, and uncollectible invoices, and added option to limit results
* Removed invoices and transactions from GetBillingAsync
* Limiting the number of invoices and transactions returned
* Moved Billing models to Billing namespace
* Split billing info and billing history objects
* Removed billing method GetBillingBalanceAndSourceAsync
* Removed unused using
* Cleaned up BillingInfo a bit
* Update migration scripts to use `CREATE OR ALTER` instead of checking for the `OBJECT_ID`
* Applying limit to aggregated invoices after they return from Stripe
* inital changes
* add provider GatewayType migrations
* db provider migrations
* removed duo migrations added v2 metadata to duo response
* removed helper scripts
* remove signature from org duo
* added backward compatibility for Duo v2
* added tests for duo request + response models
* refactors to TwoFactorController
* updated test methods to be compartmentalized by usage
* fix organization add duo
* Assert.Empty() fix for validator
* Add new stored procedure for reading reset password details for multiple organization user IDs
* Add method IOrganizationUserRepository.GetManyResetPasswordDetailsByOrganizationUserAsync
* Add new API endpoint for getting reset password details for multiple organization users
* Add unit tests for bulk OrganizationUsersController.GetResetPasswordDetails
* Add alias to sql query result column
* Add constructor for automatic mapping
* Fix http method type for endpoint
* dotnet format
* Simplify the constructor in the OrganizationUserResetPasswordDetails
* Refactor stored procedure and repository method names for retrieving account recovery details
* Add integration tests for GetManyAccountRecoveryDetailsByOrganizationUserAsync
* Lock endpoint behind BulkDeviceApproval feature flag
* Update feature flag key value
* Declare a new repository interface method
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.
* Stub out method implementations to enable unit testing
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.
* Assert a happy path integration test
* Establish a user defined SQL type for Auth Requests
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`.
* Establish a new stored procedure
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.
* Apply a SQL server migration script
This commit simply applies a migration script containing the new user
defined type and stored procedure comitted previously.
* Enable converting an `IEnumerable<AuthRequest>` to a `DataTable`
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()`.
* Implement `Dapper/../AuthRequestRepository.UpdateMany()`
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.
* Implement `EntityFramework/../AuthRequestRepository.UpdateMany()`
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.
* Assert that `UpdateManyAsync` can not create any new auth requests
* Use a json object as stored procedure input
* Fix the build
* Continuing to troubleshoot the build
* Move `AuthRequest_UpdateMany` to the Auth folder
* Remove extra comment
* Delete type that never got used
* intentionally break a test
* Unbreak it
* update OrganizationUsersController PUT and POST
* enforces new collection access checks when updating members
* refactor BulkCollectionAuthorizationHandler to avoid repeated db calls
* [AC-1682] Added MySql migration and script
(cherry picked from commit d367f6de6b)
* [AC-1682] Added Postgres migration and script
(cherry picked from commit 9bde1604da)
* [AC-1682] Added Sqlite migration and script
(cherry picked from commit 262887f9c3)
* [AC-1682] dotnet format
(cherry picked from commit 00eea0621c)
* [AC-1682] Fixed Sqlite query
(cherry picked from commit 26f5bf8afd)
* [AC-1682] Drop temp tables if they exist when starting the scripts
(cherry picked from commit c20912f95c)
* [AC-1682] Removed MySql transaction from script because EF migration already wraps it under its own transaction
(cherry picked from commit 7b54d78d67)
* [AC-1682] Setting FlexibleCollections = 1 only for Orgs that had data migrated in previous steps
(cherry picked from commit 28bba94d81)
* [AC-1682] Updated queries to check for OrganizationId
(cherry picked from commit a957530d5e)
* [AC-1682] Fixed MySql script
(cherry picked from commit deee483ab7)
* [AC-1682] Fixed Postgres query
(cherry picked from commit c3ca9ec3c8)
* [AC-1682] Fix Sqlite query
(cherry picked from commit fada0a81bf)
* [AC-1682] Reverted scripts back to enabling Flexible Collections to all existing Orgs
(cherry picked from commit bd3b21b969)
* [AC-1682] Removed dropping temporary table from scripts
(cherry picked from commit eb7794d592)
* [AC-1682] Removed other temp table drops
(cherry picked from commit 26768b7bf8)
* [AC-1978] Fix issue that allows the web app to have the user type Manager available
(cherry picked from commit 2890f78870)
* [AC-1682] Bump dates on migration scripts
---------
Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com>
* [AC-2323] Added script to migrate all sql organizations to use flexible collections
* [AC-2323] Overriding FlexibleCollectionsSignup to true for local usage
* [AC-2323] Fix script comment
* [AC-2323] Fixed typo
* [AC-2323] Bump up date on migration script
* [AC-2323] Bump migration script date
---------
Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com>