From 28d45f91aa2ea557f59d2a207d0a27731326b5d9 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Wed, 24 Jul 2024 09:03:09 +1000 Subject: [PATCH] Remove FlexibleCollections feature flag (#4481) --- src/Admin/Controllers/UsersController.cs | 17 +++---------- .../Auth/Controllers/AccountsController.cs | 3 --- src/Api/Controllers/CollectionsController.cs | 4 ++-- .../BulkCollectionAuthorizationHandler.cs | 2 +- .../Vault/Controllers/CiphersController.cs | 9 +++---- src/Api/Vault/Controllers/SyncController.cs | 13 +++------- .../Validators/CipherRotationValidator.cs | 11 ++------- .../Implementations/EmergencyAccessService.cs | 10 ++------ src/Core/Constants.cs | 5 ---- .../Repositories/ICollectionRepository.cs | 2 +- .../Implementations/CollectionService.cs | 11 +-------- .../Vault/Queries/OrganizationCiphersQuery.cs | 2 +- .../Vault/Repositories/ICipherRepository.cs | 2 +- .../Services/Implementations/CipherService.cs | 16 ++++--------- .../Repositories/CollectionRepository.cs | 8 ++----- .../Vault/Repositories/CipherRepository.cs | 6 ++--- .../Repositories/CollectionRepository.cs | 2 +- .../Vault/Repositories/CipherRepository.cs | 2 +- .../Controllers/CollectionsControllerTests.cs | 4 ++-- ...BulkCollectionAuthorizationHandlerTests.cs | 24 +++++++++---------- .../Vault/Controllers/SyncControllerTests.cs | 16 ++++++------- .../Services/CollectionServiceTests.cs | 4 ++-- .../Vault/Services/CipherServiceTests.cs | 4 ++-- 23 files changed, 57 insertions(+), 120 deletions(-) diff --git a/src/Admin/Controllers/UsersController.cs b/src/Admin/Controllers/UsersController.cs index aa71ebb92..ed162ee54 100644 --- a/src/Admin/Controllers/UsersController.cs +++ b/src/Admin/Controllers/UsersController.cs @@ -2,8 +2,6 @@ using Bit.Admin.Models; using Bit.Admin.Services; using Bit.Admin.Utilities; -using Bit.Core; -using Bit.Core.Context; using Bit.Core.Entities; using Bit.Core.Repositories; using Bit.Core.Services; @@ -23,28 +21,19 @@ public class UsersController : Controller private readonly IPaymentService _paymentService; private readonly GlobalSettings _globalSettings; private readonly IAccessControlService _accessControlService; - private readonly ICurrentContext _currentContext; - private readonly IFeatureService _featureService; - - private bool UseFlexibleCollections => - _featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections); public UsersController( IUserRepository userRepository, ICipherRepository cipherRepository, IPaymentService paymentService, GlobalSettings globalSettings, - IAccessControlService accessControlService, - ICurrentContext currentContext, - IFeatureService featureService) + IAccessControlService accessControlService) { _userRepository = userRepository; _cipherRepository = cipherRepository; _paymentService = paymentService; _globalSettings = globalSettings; _accessControlService = accessControlService; - _currentContext = currentContext; - _featureService = featureService; } [RequirePermission(Permission.User_List_View)] @@ -80,7 +69,7 @@ public class UsersController : Controller return RedirectToAction("Index"); } - var ciphers = await _cipherRepository.GetManyByUserIdAsync(id, useFlexibleCollections: UseFlexibleCollections); + var ciphers = await _cipherRepository.GetManyByUserIdAsync(id); return View(new UserViewModel(user, ciphers)); } @@ -93,7 +82,7 @@ public class UsersController : Controller return RedirectToAction("Index"); } - var ciphers = await _cipherRepository.GetManyByUserIdAsync(id, useFlexibleCollections: UseFlexibleCollections); + var ciphers = await _cipherRepository.GetManyByUserIdAsync(id); var billingInfo = await _paymentService.GetBillingAsync(user); var billingHistoryInfo = await _paymentService.GetBillingHistoryAsync(user); return View(new UserEditModel(user, ciphers, billingInfo, billingHistoryInfo, _globalSettings)); diff --git a/src/Api/Auth/Controllers/AccountsController.cs b/src/Api/Auth/Controllers/AccountsController.cs index 142617466..3370b8939 100644 --- a/src/Api/Auth/Controllers/AccountsController.cs +++ b/src/Api/Auth/Controllers/AccountsController.cs @@ -61,9 +61,6 @@ public class AccountsController : Controller private readonly IReferenceEventService _referenceEventService; private readonly ICurrentContext _currentContext; - private bool UseFlexibleCollections => - _featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections); - private readonly IRotationValidator, IEnumerable> _cipherValidator; private readonly IRotationValidator, IEnumerable> _folderValidator; private readonly IRotationValidator, IReadOnlyList> _sendValidator; diff --git a/src/Api/Controllers/CollectionsController.cs b/src/Api/Controllers/CollectionsController.cs index b4b1681dd..37b4fe266 100644 --- a/src/Api/Controllers/CollectionsController.cs +++ b/src/Api/Controllers/CollectionsController.cs @@ -107,7 +107,7 @@ public class CollectionsController : Controller } else { - var assignedCollections = await _collectionRepository.GetManyByUserIdAsync(_currentContext.UserId.Value, false); + var assignedCollections = await _collectionRepository.GetManyByUserIdAsync(_currentContext.UserId.Value); orgCollections = assignedCollections.Where(c => c.OrganizationId == orgId && c.Manage).ToList(); } @@ -119,7 +119,7 @@ public class CollectionsController : Controller public async Task> GetUser() { var collections = await _collectionRepository.GetManyByUserIdAsync( - _userService.GetProperUserId(User).Value, false); + _userService.GetProperUserId(User).Value); var responses = collections.Select(c => new CollectionDetailsResponseModel(c)); return new ListResponseModel(responses); } diff --git a/src/Api/Vault/AuthorizationHandlers/Collections/BulkCollectionAuthorizationHandler.cs b/src/Api/Vault/AuthorizationHandlers/Collections/BulkCollectionAuthorizationHandler.cs index d836b18e3..3fe5e7ecf 100644 --- a/src/Api/Vault/AuthorizationHandlers/Collections/BulkCollectionAuthorizationHandler.cs +++ b/src/Api/Vault/AuthorizationHandlers/Collections/BulkCollectionAuthorizationHandler.cs @@ -272,7 +272,7 @@ public class BulkCollectionAuthorizationHandler : BulkAuthorizationHandler c.Manage) diff --git a/src/Api/Vault/Controllers/CiphersController.cs b/src/Api/Vault/Controllers/CiphersController.cs index 378b0ef72..30296f0ae 100644 --- a/src/Api/Vault/Controllers/CiphersController.cs +++ b/src/Api/Vault/Controllers/CiphersController.cs @@ -46,9 +46,6 @@ public class CiphersController : Controller private readonly IApplicationCacheService _applicationCacheService; private readonly ICollectionRepository _collectionRepository; - private bool UseFlexibleCollections => - _featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections); - public CiphersController( ICipherRepository cipherRepository, ICollectionCipherRepository collectionCipherRepository, @@ -126,7 +123,7 @@ public class CiphersController : Controller var userId = _userService.GetProperUserId(User).Value; var hasOrgs = _currentContext.Organizations?.Any() ?? false; // TODO: Use hasOrgs proper for cipher listing here? - var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId, useFlexibleCollections: UseFlexibleCollections, withOrganizations: true || hasOrgs); + var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId, withOrganizations: true || hasOrgs); Dictionary> collectionCiphersGroupDict = null; if (hasOrgs) { @@ -550,7 +547,7 @@ public class CiphersController : Controller } var userId = _userService.GetProperUserId(User).Value; - var editableCollections = (await _collectionRepository.GetManyByUserIdAsync(userId, true)) + var editableCollections = (await _collectionRepository.GetManyByUserIdAsync(userId)) .Where(c => c.OrganizationId == organizationId && !c.ReadOnly) .ToDictionary(c => c.Id); @@ -922,7 +919,7 @@ public class CiphersController : Controller } var userId = _userService.GetProperUserId(User).Value; - var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId, useFlexibleCollections: UseFlexibleCollections, withOrganizations: false); + var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId, withOrganizations: false); var ciphersDict = ciphers.ToDictionary(c => c.Id); var shareCiphers = new List<(Cipher, DateTime?)>(); diff --git a/src/Api/Vault/Controllers/SyncController.cs b/src/Api/Vault/Controllers/SyncController.cs index 82ed82a2b..0381bdca6 100644 --- a/src/Api/Vault/Controllers/SyncController.cs +++ b/src/Api/Vault/Controllers/SyncController.cs @@ -1,5 +1,4 @@ using Bit.Api.Vault.Models.Response; -using Bit.Core; using Bit.Core.AdminConsole.Entities; using Bit.Core.AdminConsole.Enums.Provider; using Bit.Core.AdminConsole.Repositories; @@ -31,10 +30,6 @@ public class SyncController : Controller private readonly IPolicyRepository _policyRepository; private readonly ISendRepository _sendRepository; private readonly GlobalSettings _globalSettings; - private readonly IFeatureService _featureService; - - private bool UseFlexibleCollections => - _featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections); public SyncController( IUserService userService, @@ -46,8 +41,7 @@ public class SyncController : Controller IProviderUserRepository providerUserRepository, IPolicyRepository policyRepository, ISendRepository sendRepository, - GlobalSettings globalSettings, - IFeatureService featureService) + GlobalSettings globalSettings) { _userService = userService; _folderRepository = folderRepository; @@ -59,7 +53,6 @@ public class SyncController : Controller _policyRepository = policyRepository; _sendRepository = sendRepository; _globalSettings = globalSettings; - _featureService = featureService; } [HttpGet("")] @@ -81,7 +74,7 @@ public class SyncController : Controller var hasEnabledOrgs = organizationUserDetails.Any(o => o.Enabled); var folders = await _folderRepository.GetManyByUserIdAsync(user.Id); - var ciphers = await _cipherRepository.GetManyByUserIdAsync(user.Id, useFlexibleCollections: UseFlexibleCollections, withOrganizations: hasEnabledOrgs); + var ciphers = await _cipherRepository.GetManyByUserIdAsync(user.Id, withOrganizations: hasEnabledOrgs); var sends = await _sendRepository.GetManyByUserIdAsync(user.Id); IEnumerable collections = null; @@ -90,7 +83,7 @@ public class SyncController : Controller if (hasEnabledOrgs) { - collections = await _collectionRepository.GetManyByUserIdAsync(user.Id, UseFlexibleCollections); + collections = await _collectionRepository.GetManyByUserIdAsync(user.Id); var collectionCiphers = await _collectionCipherRepository.GetManyByUserIdAsync(user.Id); collectionCiphersGroupDict = collectionCiphers.GroupBy(c => c.CipherId).ToDictionary(s => s.Key); } diff --git a/src/Api/Vault/Validators/CipherRotationValidator.cs b/src/Api/Vault/Validators/CipherRotationValidator.cs index 836fe6fe1..77e437017 100644 --- a/src/Api/Vault/Validators/CipherRotationValidator.cs +++ b/src/Api/Vault/Validators/CipherRotationValidator.cs @@ -1,9 +1,7 @@ using Bit.Api.Auth.Validators; using Bit.Api.Vault.Models.Request; -using Bit.Core; using Bit.Core.Entities; using Bit.Core.Exceptions; -using Bit.Core.Services; using Bit.Core.Vault.Entities; using Bit.Core.Vault.Repositories; @@ -12,22 +10,17 @@ namespace Bit.Api.Vault.Validators; public class CipherRotationValidator : IRotationValidator, IEnumerable> { private readonly ICipherRepository _cipherRepository; - private readonly IFeatureService _featureService; - private bool UseFlexibleCollections => - _featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections); - - public CipherRotationValidator(ICipherRepository cipherRepository, IFeatureService featureService) + public CipherRotationValidator(ICipherRepository cipherRepository) { _cipherRepository = cipherRepository; - _featureService = featureService; } public async Task> ValidateAsync(User user, IEnumerable ciphers) { var result = new List(); - var existingCiphers = await _cipherRepository.GetManyByUserIdAsync(user.Id, UseFlexibleCollections); + var existingCiphers = await _cipherRepository.GetManyByUserIdAsync(user.Id); if (existingCiphers == null) { return result; diff --git a/src/Core/Auth/Services/Implementations/EmergencyAccessService.cs b/src/Core/Auth/Services/Implementations/EmergencyAccessService.cs index db14db7fe..38df8e598 100644 --- a/src/Core/Auth/Services/Implementations/EmergencyAccessService.cs +++ b/src/Core/Auth/Services/Implementations/EmergencyAccessService.cs @@ -33,10 +33,6 @@ public class EmergencyAccessService : IEmergencyAccessService private readonly IPasswordHasher _passwordHasher; private readonly IOrganizationService _organizationService; private readonly IDataProtectorTokenFactory _dataProtectorTokenizer; - private readonly IFeatureService _featureService; - - private bool UseFlexibleCollections => - _featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections); public EmergencyAccessService( IEmergencyAccessRepository emergencyAccessRepository, @@ -50,8 +46,7 @@ public class EmergencyAccessService : IEmergencyAccessService IPasswordHasher passwordHasher, GlobalSettings globalSettings, IOrganizationService organizationService, - IDataProtectorTokenFactory dataProtectorTokenizer, - IFeatureService featureService) + IDataProtectorTokenFactory dataProtectorTokenizer) { _emergencyAccessRepository = emergencyAccessRepository; _organizationUserRepository = organizationUserRepository; @@ -65,7 +60,6 @@ public class EmergencyAccessService : IEmergencyAccessService _globalSettings = globalSettings; _organizationService = organizationService; _dataProtectorTokenizer = dataProtectorTokenizer; - _featureService = featureService; } public async Task InviteAsync(User invitingUser, string email, EmergencyAccessType type, int waitTime) @@ -393,7 +387,7 @@ public class EmergencyAccessService : IEmergencyAccessService throw new BadRequestException("Emergency Access not valid."); } - var ciphers = await _cipherRepository.GetManyByUserIdAsync(emergencyAccess.GrantorId, useFlexibleCollections: UseFlexibleCollections, withOrganizations: false); + var ciphers = await _cipherRepository.GetManyByUserIdAsync(emergencyAccess.GrantorId, withOrganizations: false); return new EmergencyAccessViewData { diff --git a/src/Core/Constants.cs b/src/Core/Constants.cs index 29c99a161..34f499c96 100644 --- a/src/Core/Constants.cs +++ b/src/Core/Constants.cs @@ -104,11 +104,6 @@ public static class FeatureFlagKeys public const string BrowserFilelessImport = "browser-fileless-import"; public const string ReturnErrorOnExistingKeypair = "return-error-on-existing-keypair"; public const string UseTreeWalkerApiForPageDetailsCollection = "use-tree-walker-api-for-page-details-collection"; - - /// - /// Deprecated - never used, do not use. Will always default to false. Will be deleted as part of Flexible Collections cleanup - /// - public const string FlexibleCollections = "flexible-collections-disabled-do-not-use"; public const string FlexibleCollectionsV1 = "flexible-collections-v-1"; // v-1 is intentional public const string ItemShare = "item-share"; public const string KeyRotationImprovements = "key-rotation-improvements"; diff --git a/src/Core/Repositories/ICollectionRepository.cs b/src/Core/Repositories/ICollectionRepository.cs index 7710e7d93..d6d15c127 100644 --- a/src/Core/Repositories/ICollectionRepository.cs +++ b/src/Core/Repositories/ICollectionRepository.cs @@ -29,7 +29,7 @@ public interface ICollectionRepository : IRepository /// Return all collections a user has access to across all of the organization they're a member of. Includes permission /// details for each collection. /// - Task> GetManyByUserIdAsync(Guid userId, bool useFlexibleCollections); + Task> GetManyByUserIdAsync(Guid userId); /// /// Returns all collections for an organization, including permission info for the specified user. diff --git a/src/Core/Services/Implementations/CollectionService.cs b/src/Core/Services/Implementations/CollectionService.cs index 4b910470e..d0eed1d6d 100644 --- a/src/Core/Services/Implementations/CollectionService.cs +++ b/src/Core/Services/Implementations/CollectionService.cs @@ -15,8 +15,6 @@ public class CollectionService : ICollectionService private readonly IOrganizationRepository _organizationRepository; private readonly IOrganizationUserRepository _organizationUserRepository; private readonly ICollectionRepository _collectionRepository; - private readonly IUserRepository _userRepository; - private readonly IMailService _mailService; private readonly IReferenceEventService _referenceEventService; private readonly ICurrentContext _currentContext; private readonly IFeatureService _featureService; @@ -26,8 +24,6 @@ public class CollectionService : ICollectionService IOrganizationRepository organizationRepository, IOrganizationUserRepository organizationUserRepository, ICollectionRepository collectionRepository, - IUserRepository userRepository, - IMailService mailService, IReferenceEventService referenceEventService, ICurrentContext currentContext, IFeatureService featureService) @@ -36,8 +32,6 @@ public class CollectionService : ICollectionService _organizationRepository = organizationRepository; _organizationUserRepository = organizationUserRepository; _collectionRepository = collectionRepository; - _userRepository = userRepository; - _mailService = mailService; _referenceEventService = referenceEventService; _currentContext = currentContext; _featureService = featureService; @@ -128,10 +122,7 @@ public class CollectionService : ICollectionService } else { - var collections = await _collectionRepository.GetManyByUserIdAsync( - _currentContext.UserId.Value, - _featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections) - ); + var collections = await _collectionRepository.GetManyByUserIdAsync(_currentContext.UserId.Value); orgCollections = collections.Where(c => c.OrganizationId == organizationId); } diff --git a/src/Core/Vault/Queries/OrganizationCiphersQuery.cs b/src/Core/Vault/Queries/OrganizationCiphersQuery.cs index feed09808..0f01dc3be 100644 --- a/src/Core/Vault/Queries/OrganizationCiphersQuery.cs +++ b/src/Core/Vault/Queries/OrganizationCiphersQuery.cs @@ -32,7 +32,7 @@ public class OrganizationCiphersQuery : IOrganizationCiphersQuery throw new FeatureUnavailableException("Flexible collections is OFF when it should be ON."); } - var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId, useFlexibleCollections: true, withOrganizations: true); + var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId, withOrganizations: true); var orgCiphers = ciphers.Where(c => c.OrganizationId == organizationId).ToList(); var orgCipherIds = orgCiphers.Select(c => c.Id); diff --git a/src/Core/Vault/Repositories/ICipherRepository.cs b/src/Core/Vault/Repositories/ICipherRepository.cs index 630778e84..132aa5ac6 100644 --- a/src/Core/Vault/Repositories/ICipherRepository.cs +++ b/src/Core/Vault/Repositories/ICipherRepository.cs @@ -12,7 +12,7 @@ public interface ICipherRepository : IRepository Task GetOrganizationDetailsByIdAsync(Guid id); Task> GetManyOrganizationDetailsByOrganizationIdAsync(Guid organizationId); Task GetCanEditByIdAsync(Guid userId, Guid cipherId); - Task> GetManyByUserIdAsync(Guid userId, bool useFlexibleCollections, bool withOrganizations = true); + Task> GetManyByUserIdAsync(Guid userId, bool withOrganizations = true); Task> GetManyByOrganizationIdAsync(Guid organizationId); Task> GetManyUnassignedOrganizationDetailsByOrganizationIdAsync(Guid organizationId); Task CreateAsync(Cipher cipher, IEnumerable collectionIds); diff --git a/src/Core/Vault/Services/Implementations/CipherService.cs b/src/Core/Vault/Services/Implementations/CipherService.cs index 87a8343a3..d6947b541 100644 --- a/src/Core/Vault/Services/Implementations/CipherService.cs +++ b/src/Core/Vault/Services/Implementations/CipherService.cs @@ -38,10 +38,6 @@ public class CipherService : ICipherService private const long _fileSizeLeeway = 1024L * 1024L; // 1MB private readonly IReferenceEventService _referenceEventService; private readonly ICurrentContext _currentContext; - private readonly IFeatureService _featureService; - - private bool UseFlexibleCollections => - _featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections); public CipherService( ICipherRepository cipherRepository, @@ -58,8 +54,7 @@ public class CipherService : ICipherService IPolicyService policyService, GlobalSettings globalSettings, IReferenceEventService referenceEventService, - ICurrentContext currentContext, - IFeatureService featureService) + ICurrentContext currentContext) { _cipherRepository = cipherRepository; _folderRepository = folderRepository; @@ -76,7 +71,6 @@ public class CipherService : ICipherService _globalSettings = globalSettings; _referenceEventService = referenceEventService; _currentContext = currentContext; - _featureService = featureService; } public async Task SaveAsync(Cipher cipher, Guid savingUserId, DateTime? lastKnownRevisionDate, @@ -430,7 +424,7 @@ public class CipherService : ICipherService } else { - var ciphers = await _cipherRepository.GetManyByUserIdAsync(deletingUserId, useFlexibleCollections: UseFlexibleCollections); + var ciphers = await _cipherRepository.GetManyByUserIdAsync(deletingUserId); deletingCiphers = ciphers.Where(c => cipherIdsSet.Contains(c.Id) && c.Edit).Select(x => (Cipher)x).ToList(); await _cipherRepository.DeleteAsync(deletingCiphers.Select(c => c.Id), deletingUserId); @@ -872,7 +866,7 @@ public class CipherService : ICipherService } else { - var ciphers = await _cipherRepository.GetManyByUserIdAsync(deletingUserId, useFlexibleCollections: UseFlexibleCollections); + var ciphers = await _cipherRepository.GetManyByUserIdAsync(deletingUserId); deletingCiphers = ciphers.Where(c => cipherIdsSet.Contains(c.Id) && c.Edit).Select(x => (Cipher)x).ToList(); await _cipherRepository.SoftDeleteAsync(deletingCiphers.Select(c => c.Id), deletingUserId); @@ -938,7 +932,7 @@ public class CipherService : ICipherService } else { - var ciphers = await _cipherRepository.GetManyByUserIdAsync(restoringUserId, useFlexibleCollections: UseFlexibleCollections); + var ciphers = await _cipherRepository.GetManyByUserIdAsync(restoringUserId); restoringCiphers = ciphers.Where(c => cipherIdsSet.Contains(c.Id) && c.Edit).Select(c => (CipherOrganizationDetails)c).ToList(); revisionDate = await _cipherRepository.RestoreAsync(restoringCiphers.Select(c => c.Id), restoringUserId); @@ -976,7 +970,7 @@ public class CipherService : ICipherService } else { - var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId, useFlexibleCollections: UseFlexibleCollections, withOrganizations: true); + var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId, withOrganizations: true); orgCiphers = ciphers.Where(c => c.OrganizationId == organizationId); } diff --git a/src/Infrastructure.Dapper/Repositories/CollectionRepository.cs b/src/Infrastructure.Dapper/Repositories/CollectionRepository.cs index 30956c825..bd3f34413 100644 --- a/src/Infrastructure.Dapper/Repositories/CollectionRepository.cs +++ b/src/Infrastructure.Dapper/Repositories/CollectionRepository.cs @@ -120,16 +120,12 @@ public class CollectionRepository : Repository, ICollectionRep } } - public async Task> GetManyByUserIdAsync(Guid userId, bool useFlexibleCollections) + public async Task> GetManyByUserIdAsync(Guid userId) { - var sprocName = useFlexibleCollections - ? $"[{Schema}].[Collection_ReadByUserId_V2]" - : $"[{Schema}].[Collection_ReadByUserId]"; - using (var connection = new SqlConnection(ConnectionString)) { var results = await connection.QueryAsync( - sprocName, + $"[{Schema}].[Collection_ReadByUserId]", new { UserId = userId }, commandType: CommandType.StoredProcedure); diff --git a/src/Infrastructure.Dapper/Vault/Repositories/CipherRepository.cs b/src/Infrastructure.Dapper/Vault/Repositories/CipherRepository.cs index ca496b4a1..04ce6538a 100644 --- a/src/Infrastructure.Dapper/Vault/Repositories/CipherRepository.cs +++ b/src/Infrastructure.Dapper/Vault/Repositories/CipherRepository.cs @@ -77,14 +77,12 @@ public class CipherRepository : Repository, ICipherRepository } } - public async Task> GetManyByUserIdAsync(Guid userId, bool useFlexibleCollections, bool withOrganizations = true) + public async Task> GetManyByUserIdAsync(Guid userId, bool withOrganizations = true) { string sprocName = null; if (withOrganizations) { - sprocName = useFlexibleCollections - ? $"[{Schema}].[CipherDetails_ReadByUserId_V2]" - : $"[{Schema}].[CipherDetails_ReadByUserId]"; + sprocName = $"[{Schema}].[CipherDetails_ReadByUserId]"; } else { diff --git a/src/Infrastructure.EntityFramework/Repositories/CollectionRepository.cs b/src/Infrastructure.EntityFramework/Repositories/CollectionRepository.cs index a0f61ad3b..efc063eb5 100644 --- a/src/Infrastructure.EntityFramework/Repositories/CollectionRepository.cs +++ b/src/Infrastructure.EntityFramework/Repositories/CollectionRepository.cs @@ -221,7 +221,7 @@ public class CollectionRepository : Repository> GetManyByUserIdAsync(Guid userId, bool useFlexibleCollections) + public async Task> GetManyByUserIdAsync(Guid userId) { using (var scope = ServiceScopeFactory.CreateScope()) { diff --git a/src/Infrastructure.EntityFramework/Vault/Repositories/CipherRepository.cs b/src/Infrastructure.EntityFramework/Vault/Repositories/CipherRepository.cs index 345c77de1..23bd2b550 100644 --- a/src/Infrastructure.EntityFramework/Vault/Repositories/CipherRepository.cs +++ b/src/Infrastructure.EntityFramework/Vault/Repositories/CipherRepository.cs @@ -359,7 +359,7 @@ public class CipherRepository : Repository> GetManyByUserIdAsync(Guid userId, bool useFlexibleCollections, bool withOrganizations = true) + public async Task> GetManyByUserIdAsync(Guid userId, bool withOrganizations = true) { using (var scope = ServiceScopeFactory.CreateScope()) { diff --git a/test/Api.Test/Controllers/CollectionsControllerTests.cs b/test/Api.Test/Controllers/CollectionsControllerTests.cs index 3a59edffe..09e93d15f 100644 --- a/test/Api.Test/Controllers/CollectionsControllerTests.cs +++ b/test/Api.Test/Controllers/CollectionsControllerTests.cs @@ -214,13 +214,13 @@ public class CollectionsControllerTests .Returns(AuthorizationResult.Success()); sutProvider.GetDependency() - .GetManyByUserIdAsync(userId, false) + .GetManyByUserIdAsync(userId) .Returns(collections); var result = await sutProvider.Sut.Get(organization.Id); await sutProvider.GetDependency().DidNotReceive().GetManyByOrganizationIdAsync(organization.Id); - await sutProvider.GetDependency().Received(1).GetManyByUserIdAsync(userId, false); + await sutProvider.GetDependency().Received(1).GetManyByUserIdAsync(userId); Assert.Single(result.Data); Assert.All(result.Data, c => Assert.Equal(organization.Id, c.OrganizationId)); diff --git a/test/Api.Test/Vault/AuthorizationHandlers/BulkCollectionAuthorizationHandlerTests.cs b/test/Api.Test/Vault/AuthorizationHandlers/BulkCollectionAuthorizationHandlerTests.cs index 5b5b2b1b4..a9f5a16aa 100644 --- a/test/Api.Test/Vault/AuthorizationHandlers/BulkCollectionAuthorizationHandlerTests.cs +++ b/test/Api.Test/Vault/AuthorizationHandlers/BulkCollectionAuthorizationHandlerTests.cs @@ -236,7 +236,7 @@ public class BulkCollectionAuthorizationHandlerTests { sutProvider.GetDependency().UserId.Returns(actingUserId); sutProvider.GetDependency().GetOrganization(organization.Id).Returns(organization); - sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId, Arg.Any()).Returns(collections); + sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId).Returns(collections); var context = new AuthorizationHandlerContext( new[] { BulkCollectionOperations.Read }, @@ -439,7 +439,7 @@ public class BulkCollectionAuthorizationHandlerTests sutProvider.GetDependency().UserId.Returns(actingUserId); sutProvider.GetDependency().GetOrganization(organization.Id).Returns(organization); - sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId, Arg.Any()).Returns(collections); + sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId).Returns(collections); var context = new AuthorizationHandlerContext( new[] { BulkCollectionOperations.ReadWithAccess }, @@ -469,7 +469,7 @@ public class BulkCollectionAuthorizationHandlerTests sutProvider.GetDependency().UserId.Returns(actingUserId); sutProvider.GetDependency().GetOrganization(organization.Id).Returns(organization); - sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId, Arg.Any()).Returns(collections); + sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId).Returns(collections); var context = new AuthorizationHandlerContext( new[] { BulkCollectionOperations.ReadWithAccess }, @@ -725,7 +725,7 @@ public class BulkCollectionAuthorizationHandlerTests { sutProvider.GetDependency().UserId.Returns(actingUserId); sutProvider.GetDependency().GetOrganization(organization.Id).Returns(organization); - sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId, Arg.Any()).Returns(collections); + sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId).Returns(collections); var context = new AuthorizationHandlerContext( new[] { op }, @@ -1090,7 +1090,7 @@ public class BulkCollectionAuthorizationHandlerTests sutProvider.GetDependency().UserId.Returns(actingUserId); sutProvider.GetDependency().GetOrganization(organization.Id).Returns(organization); - sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId, Arg.Any()).Returns(collections); + sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId).Returns(collections); foreach (var c in collections) { @@ -1126,7 +1126,7 @@ public class BulkCollectionAuthorizationHandlerTests sutProvider.GetDependency().UserId.Returns(actingUserId); sutProvider.GetDependency().GetOrganization(organization.Id).Returns(organization); - sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId, Arg.Any()).Returns(collections); + sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId).Returns(collections); sutProvider.GetDependency().IsEnabled(FeatureFlagKeys.FlexibleCollectionsV1).Returns(true); foreach (var c in collections) @@ -1162,7 +1162,7 @@ public class BulkCollectionAuthorizationHandlerTests sutProvider.GetDependency().UserId.Returns(actingUserId); sutProvider.GetDependency().GetOrganization(organization.Id).Returns(organization); - sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId, Arg.Any()).Returns(collections); + sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId).Returns(collections); sutProvider.GetDependency().IsEnabled(FeatureFlagKeys.FlexibleCollectionsV1).Returns(true); foreach (var c in collections) @@ -1198,7 +1198,7 @@ public class BulkCollectionAuthorizationHandlerTests sutProvider.GetDependency().UserId.Returns(actingUserId); sutProvider.GetDependency().GetOrganization(organization.Id).Returns(organization); - sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId, Arg.Any()).Returns(collections); + sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId).Returns(collections); sutProvider.GetDependency().IsEnabled(FeatureFlagKeys.FlexibleCollectionsV1).Returns(true); sutProvider.GetDependency().ProviderUserForOrgAsync(Arg.Any()).Returns(false); @@ -1232,7 +1232,7 @@ public class BulkCollectionAuthorizationHandlerTests sutProvider.GetDependency().UserId.Returns(actingUserId); sutProvider.GetDependency().GetOrganization(organization.Id).Returns(organization); - sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId, Arg.Any()).Returns(collections); + sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId).Returns(collections); sutProvider.GetDependency().IsEnabled(FeatureFlagKeys.FlexibleCollectionsV1).Returns(true); sutProvider.GetDependency().ProviderUserForOrgAsync(Arg.Any()).Returns(false); @@ -1266,7 +1266,7 @@ public class BulkCollectionAuthorizationHandlerTests sutProvider.GetDependency().UserId.Returns(actingUserId); sutProvider.GetDependency().GetOrganization(organization.Id).Returns(organization); - sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId, Arg.Any()).Returns(collections); + sutProvider.GetDependency().GetManyByUserIdAsync(actingUserId).Returns(collections); sutProvider.GetDependency().IsEnabled(FeatureFlagKeys.FlexibleCollectionsV1).Returns(true); sutProvider.GetDependency().ProviderUserForOrgAsync(Arg.Any()).Returns(false); @@ -1449,7 +1449,7 @@ public class BulkCollectionAuthorizationHandlerTests sutProvider.GetDependency().UserId.Returns(actingUserId); sutProvider.GetDependency().GetOrganization(organization.Id).Returns(organization); sutProvider.GetDependency() - .GetManyByUserIdAsync(actingUserId, Arg.Any()) + .GetManyByUserIdAsync(actingUserId) .Returns(new List() { collection1, collection2 }); var context1 = new AuthorizationHandlerContext( @@ -1467,7 +1467,7 @@ public class BulkCollectionAuthorizationHandlerTests await sutProvider.Sut.HandleAsync(context2); // Expect: only calls the database once - await sutProvider.GetDependency().Received(1).GetManyByUserIdAsync(Arg.Any(), Arg.Any()); + await sutProvider.GetDependency().Received(1).GetManyByUserIdAsync(Arg.Any()); } private static void ArrangeOrganizationAbility( diff --git a/test/Api.Test/Vault/Controllers/SyncControllerTests.cs b/test/Api.Test/Vault/Controllers/SyncControllerTests.cs index 6e8578df0..e36f17221 100644 --- a/test/Api.Test/Vault/Controllers/SyncControllerTests.cs +++ b/test/Api.Test/Vault/Controllers/SyncControllerTests.cs @@ -107,7 +107,7 @@ public class SyncControllerTests .Returns(providerUserOrganizationDetails); folderRepository.GetManyByUserIdAsync(user.Id).Returns(folders); - cipherRepository.GetManyByUserIdAsync(user.Id, useFlexibleCollections: Arg.Any()).Returns(ciphers); + cipherRepository.GetManyByUserIdAsync(user.Id).Returns(ciphers); sendRepository .GetManyByUserIdAsync(user.Id).Returns(sends); @@ -115,7 +115,7 @@ public class SyncControllerTests policyRepository.GetManyByUserIdAsync(user.Id).Returns(policies); // Returns for methods only called if we have enabled orgs - collectionRepository.GetManyByUserIdAsync(user.Id, Arg.Any()).Returns(collections); + collectionRepository.GetManyByUserIdAsync(user.Id).Returns(collections); collectionCipherRepository.GetManyByUserIdAsync(user.Id).Returns(new List()); // Back to standard test setup userService.TwoFactorIsEnabledAsync(user).Returns(false); @@ -197,7 +197,7 @@ public class SyncControllerTests .Returns(providerUserOrganizationDetails); folderRepository.GetManyByUserIdAsync(user.Id).Returns(folders); - cipherRepository.GetManyByUserIdAsync(user.Id, useFlexibleCollections: Arg.Any()).Returns(ciphers); + cipherRepository.GetManyByUserIdAsync(user.Id).Returns(ciphers); sendRepository .GetManyByUserIdAsync(user.Id).Returns(sends); @@ -271,7 +271,7 @@ public class SyncControllerTests .Returns(providerUserOrganizationDetails); folderRepository.GetManyByUserIdAsync(user.Id).Returns(folders); - cipherRepository.GetManyByUserIdAsync(user.Id, useFlexibleCollections: Arg.Any()).Returns(ciphers); + cipherRepository.GetManyByUserIdAsync(user.Id).Returns(ciphers); sendRepository .GetManyByUserIdAsync(user.Id).Returns(sends); @@ -279,7 +279,7 @@ public class SyncControllerTests policyRepository.GetManyByUserIdAsync(user.Id).Returns(policies); // Returns for methods only called if we have enabled orgs - collectionRepository.GetManyByUserIdAsync(user.Id, Arg.Any()).Returns(collections); + collectionRepository.GetManyByUserIdAsync(user.Id).Returns(collections); collectionCipherRepository.GetManyByUserIdAsync(user.Id).Returns(new List()); // Back to standard test setup userService.TwoFactorIsEnabledAsync(user).Returns(false); @@ -333,7 +333,7 @@ public class SyncControllerTests .GetManyByUserIdAsync(default); await cipherRepository.ReceivedWithAnyArgs(1) - .GetManyByUserIdAsync(default, useFlexibleCollections: default); + .GetManyByUserIdAsync(default); await sendRepository.ReceivedWithAnyArgs(1) .GetManyByUserIdAsync(default); @@ -342,7 +342,7 @@ public class SyncControllerTests if (hasEnabledOrgs) { await collectionRepository.ReceivedWithAnyArgs(1) - .GetManyByUserIdAsync(default, default); + .GetManyByUserIdAsync(default); await collectionCipherRepository.ReceivedWithAnyArgs(1) .GetManyByUserIdAsync(default); } @@ -350,7 +350,7 @@ public class SyncControllerTests { // all disabled orgs await collectionRepository.ReceivedWithAnyArgs(0) - .GetManyByUserIdAsync(default, default); + .GetManyByUserIdAsync(default); await collectionCipherRepository.ReceivedWithAnyArgs(0) .GetManyByUserIdAsync(default); } diff --git a/test/Core.Test/Services/CollectionServiceTests.cs b/test/Core.Test/Services/CollectionServiceTests.cs index aa8097d2c..0923a655e 100644 --- a/test/Core.Test/Services/CollectionServiceTests.cs +++ b/test/Core.Test/Services/CollectionServiceTests.cs @@ -197,7 +197,7 @@ public class CollectionServiceTest Assert.Equal(collection, result.First()); await sutProvider.GetDependency().Received(1).GetManyByOrganizationIdAsync(organizationId); - await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().GetManyByUserIdAsync(default, default); + await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().GetManyByUserIdAsync(default); } [Theory, BitAutoData] @@ -207,6 +207,6 @@ public class CollectionServiceTest await Assert.ThrowsAsync(() => sutProvider.Sut.GetOrganizationCollectionsAsync(organizationId)); await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().GetManyByOrganizationIdAsync(default); - await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().GetManyByUserIdAsync(default, default); + await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().GetManyByUserIdAsync(default); } } diff --git a/test/Core.Test/Vault/Services/CipherServiceTests.cs b/test/Core.Test/Vault/Services/CipherServiceTests.cs index a0623a6c7..9cc01e0e2 100644 --- a/test/Core.Test/Vault/Services/CipherServiceTests.cs +++ b/test/Core.Test/Vault/Services/CipherServiceTests.cs @@ -677,7 +677,7 @@ public class CipherServiceTests cipher.RevisionDate = previousRevisionDate; } - sutProvider.GetDependency().GetManyByUserIdAsync(restoringUserId, useFlexibleCollections: Arg.Any()).Returns(ciphers); + sutProvider.GetDependency().GetManyByUserIdAsync(restoringUserId).Returns(ciphers); var revisionDate = previousRevisionDate + TimeSpan.FromMinutes(1); sutProvider.GetDependency().RestoreAsync(Arg.Any>(), restoringUserId).Returns(revisionDate); @@ -791,7 +791,7 @@ public class CipherServiceTests await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().GetManyOrganizationDetailsByOrganizationIdAsync(default); await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().RestoreByIdsOrganizationIdAsync(default, default); await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().RestoreByIdsOrganizationIdAsync(default, default); - await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().GetManyByUserIdAsync(default, useFlexibleCollections: default); + await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().GetManyByUserIdAsync(default); await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().RestoreAsync(default, default); await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().LogCipherEventsAsync(default); await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().PushSyncCiphersAsync(default);