* Add HasVerifiedDomainsAsync method to IOrganizationDomainService
* Add GetManagedUserIdsByOrganizationIdAsync method to IOrganizationUserRepository and the corresponding queries
* Fix case on the sproc OrganizationUser_ReadManagedIdsByOrganizationId parameter
* Update the EF query to use the Email from the User table
* dotnet format
* Fix IOrganizationDomainService.HasVerifiedDomainsAsync by checking that domains have been Verified and add unit tests
* Rename IOrganizationUserRepository.GetManagedUserIdsByOrganizationAsync
* Fix domain queries
* Add OrganizationUserRepository integration tests
* Add summary to IOrganizationDomainService.HasVerifiedDomainsAsync
* chore: Rename IOrganizationUserRepository.GetManagedUserIdsByOrganizationAsync to GetManyIdsManagedByOrganizationIdAsync
* Add IsManagedByAnyOrganizationAsync method to IUserRepository
* Add integration tests for UserRepository.IsManagedByAnyOrganizationAsync
* Refactor to IUserService.IsManagedByAnyOrganizationAsync and IOrganizationService.GetUsersOrganizationManagementStatusAsync
* chore: Refactor IsManagedByAnyOrganizationAsync method in UserService
* Refactor IOrganizationService.GetUsersOrganizationManagementStatusAsync to return IDictionary<Guid, bool>
* Extract IOrganizationService.GetUsersOrganizationManagementStatusAsync into a query
* Update comments in OrganizationDomainService to use proper capitalization
* Move OrganizationDomainService to AdminConsole ownership and update namespace
* feat: Add support for organization domains in enterprise plans
* feat: Add HasOrganizationDomains property to OrganizationAbility class
* refactor: Update GetOrganizationUsersManagementStatusQuery to use IApplicationCacheService
* Remove HasOrganizationDomains and use UseSso to check if Organization can have Verified Domains
* Refactor UserService.IsManagedByAnyOrganizationAsync to simply check the UseSso flag
* Add TODO comment for replacing 'UseSso' organization ability on user verified domain checks
* Bump date on migration script
* Add indexes to OrganizationDomain table
* Bump script migration date; Remove WITH ONLINE = ON from data migration.
* Added invoices and transaction history endpoints. Added cursor paging for each
* Removed try/catch since it's handled by middleware. Updated condition to use pattern matching
* Added unit tests for PaymentHistoryService
* Removed organizationId from account billing controller endpoints
* Add SQL script to migrate custom users with specific permissions to User type
Remove 'editAssignedCollections' and 'deleteAssignedCollections' properties from Permissions in OrganizationUser table. Migrate custom users who only have these permissions to the User type.
* Add MySQL migration to migrate custom users with specific permissions to User type
* Add Postgres migration to migrate custom users with specific permissions to User type
* Add Sqlite migration to migrate custom users with specific permissions to User type
* Update AutoFixture usage in tests to resolve creating ILogger mock instances
* Update EF integration tests database contexts to use each respective Migrations assembly. Configure Sqlite instance
* Add RunMigration method to BaseEntityFrameworkRepository
* Add FinalFlexibleCollectionsDataMigrationsTests
* Improve data migration efficiency by using OPENJSON instead of multiple JSON_EXTRACT
* Add batching to the sql data migrations
* Update DbMigrator to run a specific script based on its name
* Update DatabaseDataAttribute to be able to test a specific migration
* Add reference to the migration projects to Infrastructure.IntegrationTest
* Add integration test to test the migration FinalFlexibleCollectionsDataMigrations
* Remove EFIntegration tests and remove RunMigration method from BaseEntityFrameworkRepository
* Add IMigrationTesterService and implementations for SQL and EF migrations
* Add FinalFlexibleCollectionsDataMigrationsTests and remove test from OrganizationUserRepositoryTests
* Update sql data migration script based on performance feedback
* Bump date on EF migration scripts
* Add xmldoc comments to IMigrationTesterService and each implementation
* Bump up the date on the EF migration scripts
* Bump up dates on EF migrations
* Added tests to assert no unwanted changes are made to the permissions json. Refactor tests.
* Revert changes made to DbMigrator and refactor SqlMigrationTesterService to not use it.
* Add method description
* Fix test to assert no changes are made to custom user
* Remove unnecessary COALESCE and SELECT CASE
* Unident lines on SQL script
* Update DatabaseDataAttribute MigrationName property to be nullable
* Fix null reference checks
* Remove unnecessary COALESCE from Postgres script
* Bump dates on migration scripts
* Bump up dates on EF migrations
* Add migration tests for handling null
* Add test for non json values
* Fix test
* Remove migrations
* Recreate EF migrations
* Update Postgres data migration script to check for valid JSON in Permissions column
---------
Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com>
Co-authored-by: Thomas Rittson <trittson@bitwarden.com>
* [PM-10589] Update database defaults for collection management settings
* Update default values for 'LimitCollectionCreationDeletion' and 'AllowAdminAccessToAllCollectionItems' in Organization table
* Add checks before column constraint drop and constraint creation
* 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
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
* 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
* 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-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>
* Centralize database migration logic
* Clean up unused usings
* Prizatize
* Remove verbose flag from Docker invocation
* Allow certain database operations to be skipped
* Readonly
* [PM-2383] Add bulk add/remove collection cipher repository methods
* [PM-2383] Add additional authorization helpers for CiphersControlle
* [PM-2383] Add /bulk-collections endpoint to CiphersController.cs
* [PM-2383] Add EF implementation for new CollectionCipherRepository methods
* [PM-2383] Ensure V1 logic only applies when the flag is enabled for new bulk functionality