mirror of
https://github.com/bitwarden/server.git
synced 2024-11-24 12:35:25 +01:00
Remove FlexibleCollections feature flag (#4481)
This commit is contained in:
parent
903c412943
commit
28d45f91aa
@ -2,8 +2,6 @@
|
|||||||
using Bit.Admin.Models;
|
using Bit.Admin.Models;
|
||||||
using Bit.Admin.Services;
|
using Bit.Admin.Services;
|
||||||
using Bit.Admin.Utilities;
|
using Bit.Admin.Utilities;
|
||||||
using Bit.Core;
|
|
||||||
using Bit.Core.Context;
|
|
||||||
using Bit.Core.Entities;
|
using Bit.Core.Entities;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
@ -23,28 +21,19 @@ public class UsersController : Controller
|
|||||||
private readonly IPaymentService _paymentService;
|
private readonly IPaymentService _paymentService;
|
||||||
private readonly GlobalSettings _globalSettings;
|
private readonly GlobalSettings _globalSettings;
|
||||||
private readonly IAccessControlService _accessControlService;
|
private readonly IAccessControlService _accessControlService;
|
||||||
private readonly ICurrentContext _currentContext;
|
|
||||||
private readonly IFeatureService _featureService;
|
|
||||||
|
|
||||||
private bool UseFlexibleCollections =>
|
|
||||||
_featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections);
|
|
||||||
|
|
||||||
public UsersController(
|
public UsersController(
|
||||||
IUserRepository userRepository,
|
IUserRepository userRepository,
|
||||||
ICipherRepository cipherRepository,
|
ICipherRepository cipherRepository,
|
||||||
IPaymentService paymentService,
|
IPaymentService paymentService,
|
||||||
GlobalSettings globalSettings,
|
GlobalSettings globalSettings,
|
||||||
IAccessControlService accessControlService,
|
IAccessControlService accessControlService)
|
||||||
ICurrentContext currentContext,
|
|
||||||
IFeatureService featureService)
|
|
||||||
{
|
{
|
||||||
_userRepository = userRepository;
|
_userRepository = userRepository;
|
||||||
_cipherRepository = cipherRepository;
|
_cipherRepository = cipherRepository;
|
||||||
_paymentService = paymentService;
|
_paymentService = paymentService;
|
||||||
_globalSettings = globalSettings;
|
_globalSettings = globalSettings;
|
||||||
_accessControlService = accessControlService;
|
_accessControlService = accessControlService;
|
||||||
_currentContext = currentContext;
|
|
||||||
_featureService = featureService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[RequirePermission(Permission.User_List_View)]
|
[RequirePermission(Permission.User_List_View)]
|
||||||
@ -80,7 +69,7 @@ public class UsersController : Controller
|
|||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
var ciphers = await _cipherRepository.GetManyByUserIdAsync(id, useFlexibleCollections: UseFlexibleCollections);
|
var ciphers = await _cipherRepository.GetManyByUserIdAsync(id);
|
||||||
return View(new UserViewModel(user, ciphers));
|
return View(new UserViewModel(user, ciphers));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +82,7 @@ public class UsersController : Controller
|
|||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
var ciphers = await _cipherRepository.GetManyByUserIdAsync(id, useFlexibleCollections: UseFlexibleCollections);
|
var ciphers = await _cipherRepository.GetManyByUserIdAsync(id);
|
||||||
var billingInfo = await _paymentService.GetBillingAsync(user);
|
var billingInfo = await _paymentService.GetBillingAsync(user);
|
||||||
var billingHistoryInfo = await _paymentService.GetBillingHistoryAsync(user);
|
var billingHistoryInfo = await _paymentService.GetBillingHistoryAsync(user);
|
||||||
return View(new UserEditModel(user, ciphers, billingInfo, billingHistoryInfo, _globalSettings));
|
return View(new UserEditModel(user, ciphers, billingInfo, billingHistoryInfo, _globalSettings));
|
||||||
|
@ -61,9 +61,6 @@ public class AccountsController : Controller
|
|||||||
private readonly IReferenceEventService _referenceEventService;
|
private readonly IReferenceEventService _referenceEventService;
|
||||||
private readonly ICurrentContext _currentContext;
|
private readonly ICurrentContext _currentContext;
|
||||||
|
|
||||||
private bool UseFlexibleCollections =>
|
|
||||||
_featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections);
|
|
||||||
|
|
||||||
private readonly IRotationValidator<IEnumerable<CipherWithIdRequestModel>, IEnumerable<Cipher>> _cipherValidator;
|
private readonly IRotationValidator<IEnumerable<CipherWithIdRequestModel>, IEnumerable<Cipher>> _cipherValidator;
|
||||||
private readonly IRotationValidator<IEnumerable<FolderWithIdRequestModel>, IEnumerable<Folder>> _folderValidator;
|
private readonly IRotationValidator<IEnumerable<FolderWithIdRequestModel>, IEnumerable<Folder>> _folderValidator;
|
||||||
private readonly IRotationValidator<IEnumerable<SendWithIdRequestModel>, IReadOnlyList<Send>> _sendValidator;
|
private readonly IRotationValidator<IEnumerable<SendWithIdRequestModel>, IReadOnlyList<Send>> _sendValidator;
|
||||||
|
@ -107,7 +107,7 @@ public class CollectionsController : Controller
|
|||||||
}
|
}
|
||||||
else
|
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();
|
orgCollections = assignedCollections.Where(c => c.OrganizationId == orgId && c.Manage).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ public class CollectionsController : Controller
|
|||||||
public async Task<ListResponseModel<CollectionDetailsResponseModel>> GetUser()
|
public async Task<ListResponseModel<CollectionDetailsResponseModel>> GetUser()
|
||||||
{
|
{
|
||||||
var collections = await _collectionRepository.GetManyByUserIdAsync(
|
var collections = await _collectionRepository.GetManyByUserIdAsync(
|
||||||
_userService.GetProperUserId(User).Value, false);
|
_userService.GetProperUserId(User).Value);
|
||||||
var responses = collections.Select(c => new CollectionDetailsResponseModel(c));
|
var responses = collections.Select(c => new CollectionDetailsResponseModel(c));
|
||||||
return new ListResponseModel<CollectionDetailsResponseModel>(responses);
|
return new ListResponseModel<CollectionDetailsResponseModel>(responses);
|
||||||
}
|
}
|
||||||
|
@ -272,7 +272,7 @@ public class BulkCollectionAuthorizationHandler : BulkAuthorizationHandler<BulkC
|
|||||||
if (_managedCollectionsIds == null)
|
if (_managedCollectionsIds == null)
|
||||||
{
|
{
|
||||||
var allUserCollections = await _collectionRepository
|
var allUserCollections = await _collectionRepository
|
||||||
.GetManyByUserIdAsync(_currentContext.UserId!.Value, useFlexibleCollections: true);
|
.GetManyByUserIdAsync(_currentContext.UserId!.Value);
|
||||||
|
|
||||||
var managedCollectionIds = allUserCollections
|
var managedCollectionIds = allUserCollections
|
||||||
.Where(c => c.Manage)
|
.Where(c => c.Manage)
|
||||||
|
@ -46,9 +46,6 @@ public class CiphersController : Controller
|
|||||||
private readonly IApplicationCacheService _applicationCacheService;
|
private readonly IApplicationCacheService _applicationCacheService;
|
||||||
private readonly ICollectionRepository _collectionRepository;
|
private readonly ICollectionRepository _collectionRepository;
|
||||||
|
|
||||||
private bool UseFlexibleCollections =>
|
|
||||||
_featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections);
|
|
||||||
|
|
||||||
public CiphersController(
|
public CiphersController(
|
||||||
ICipherRepository cipherRepository,
|
ICipherRepository cipherRepository,
|
||||||
ICollectionCipherRepository collectionCipherRepository,
|
ICollectionCipherRepository collectionCipherRepository,
|
||||||
@ -126,7 +123,7 @@ public class CiphersController : Controller
|
|||||||
var userId = _userService.GetProperUserId(User).Value;
|
var userId = _userService.GetProperUserId(User).Value;
|
||||||
var hasOrgs = _currentContext.Organizations?.Any() ?? false;
|
var hasOrgs = _currentContext.Organizations?.Any() ?? false;
|
||||||
// TODO: Use hasOrgs proper for cipher listing here?
|
// 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<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersGroupDict = null;
|
Dictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersGroupDict = null;
|
||||||
if (hasOrgs)
|
if (hasOrgs)
|
||||||
{
|
{
|
||||||
@ -550,7 +547,7 @@ public class CiphersController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
var userId = _userService.GetProperUserId(User).Value;
|
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)
|
.Where(c => c.OrganizationId == organizationId && !c.ReadOnly)
|
||||||
.ToDictionary(c => c.Id);
|
.ToDictionary(c => c.Id);
|
||||||
|
|
||||||
@ -922,7 +919,7 @@ public class CiphersController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
var userId = _userService.GetProperUserId(User).Value;
|
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 ciphersDict = ciphers.ToDictionary(c => c.Id);
|
||||||
|
|
||||||
var shareCiphers = new List<(Cipher, DateTime?)>();
|
var shareCiphers = new List<(Cipher, DateTime?)>();
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using Bit.Api.Vault.Models.Response;
|
using Bit.Api.Vault.Models.Response;
|
||||||
using Bit.Core;
|
|
||||||
using Bit.Core.AdminConsole.Entities;
|
using Bit.Core.AdminConsole.Entities;
|
||||||
using Bit.Core.AdminConsole.Enums.Provider;
|
using Bit.Core.AdminConsole.Enums.Provider;
|
||||||
using Bit.Core.AdminConsole.Repositories;
|
using Bit.Core.AdminConsole.Repositories;
|
||||||
@ -31,10 +30,6 @@ public class SyncController : Controller
|
|||||||
private readonly IPolicyRepository _policyRepository;
|
private readonly IPolicyRepository _policyRepository;
|
||||||
private readonly ISendRepository _sendRepository;
|
private readonly ISendRepository _sendRepository;
|
||||||
private readonly GlobalSettings _globalSettings;
|
private readonly GlobalSettings _globalSettings;
|
||||||
private readonly IFeatureService _featureService;
|
|
||||||
|
|
||||||
private bool UseFlexibleCollections =>
|
|
||||||
_featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections);
|
|
||||||
|
|
||||||
public SyncController(
|
public SyncController(
|
||||||
IUserService userService,
|
IUserService userService,
|
||||||
@ -46,8 +41,7 @@ public class SyncController : Controller
|
|||||||
IProviderUserRepository providerUserRepository,
|
IProviderUserRepository providerUserRepository,
|
||||||
IPolicyRepository policyRepository,
|
IPolicyRepository policyRepository,
|
||||||
ISendRepository sendRepository,
|
ISendRepository sendRepository,
|
||||||
GlobalSettings globalSettings,
|
GlobalSettings globalSettings)
|
||||||
IFeatureService featureService)
|
|
||||||
{
|
{
|
||||||
_userService = userService;
|
_userService = userService;
|
||||||
_folderRepository = folderRepository;
|
_folderRepository = folderRepository;
|
||||||
@ -59,7 +53,6 @@ public class SyncController : Controller
|
|||||||
_policyRepository = policyRepository;
|
_policyRepository = policyRepository;
|
||||||
_sendRepository = sendRepository;
|
_sendRepository = sendRepository;
|
||||||
_globalSettings = globalSettings;
|
_globalSettings = globalSettings;
|
||||||
_featureService = featureService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("")]
|
[HttpGet("")]
|
||||||
@ -81,7 +74,7 @@ public class SyncController : Controller
|
|||||||
var hasEnabledOrgs = organizationUserDetails.Any(o => o.Enabled);
|
var hasEnabledOrgs = organizationUserDetails.Any(o => o.Enabled);
|
||||||
|
|
||||||
var folders = await _folderRepository.GetManyByUserIdAsync(user.Id);
|
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);
|
var sends = await _sendRepository.GetManyByUserIdAsync(user.Id);
|
||||||
|
|
||||||
IEnumerable<CollectionDetails> collections = null;
|
IEnumerable<CollectionDetails> collections = null;
|
||||||
@ -90,7 +83,7 @@ public class SyncController : Controller
|
|||||||
|
|
||||||
if (hasEnabledOrgs)
|
if (hasEnabledOrgs)
|
||||||
{
|
{
|
||||||
collections = await _collectionRepository.GetManyByUserIdAsync(user.Id, UseFlexibleCollections);
|
collections = await _collectionRepository.GetManyByUserIdAsync(user.Id);
|
||||||
var collectionCiphers = await _collectionCipherRepository.GetManyByUserIdAsync(user.Id);
|
var collectionCiphers = await _collectionCipherRepository.GetManyByUserIdAsync(user.Id);
|
||||||
collectionCiphersGroupDict = collectionCiphers.GroupBy(c => c.CipherId).ToDictionary(s => s.Key);
|
collectionCiphersGroupDict = collectionCiphers.GroupBy(c => c.CipherId).ToDictionary(s => s.Key);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
using Bit.Api.Auth.Validators;
|
using Bit.Api.Auth.Validators;
|
||||||
using Bit.Api.Vault.Models.Request;
|
using Bit.Api.Vault.Models.Request;
|
||||||
using Bit.Core;
|
|
||||||
using Bit.Core.Entities;
|
using Bit.Core.Entities;
|
||||||
using Bit.Core.Exceptions;
|
using Bit.Core.Exceptions;
|
||||||
using Bit.Core.Services;
|
|
||||||
using Bit.Core.Vault.Entities;
|
using Bit.Core.Vault.Entities;
|
||||||
using Bit.Core.Vault.Repositories;
|
using Bit.Core.Vault.Repositories;
|
||||||
|
|
||||||
@ -12,22 +10,17 @@ namespace Bit.Api.Vault.Validators;
|
|||||||
public class CipherRotationValidator : IRotationValidator<IEnumerable<CipherWithIdRequestModel>, IEnumerable<Cipher>>
|
public class CipherRotationValidator : IRotationValidator<IEnumerable<CipherWithIdRequestModel>, IEnumerable<Cipher>>
|
||||||
{
|
{
|
||||||
private readonly ICipherRepository _cipherRepository;
|
private readonly ICipherRepository _cipherRepository;
|
||||||
private readonly IFeatureService _featureService;
|
|
||||||
|
|
||||||
private bool UseFlexibleCollections =>
|
public CipherRotationValidator(ICipherRepository cipherRepository)
|
||||||
_featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections);
|
|
||||||
|
|
||||||
public CipherRotationValidator(ICipherRepository cipherRepository, IFeatureService featureService)
|
|
||||||
{
|
{
|
||||||
_cipherRepository = cipherRepository;
|
_cipherRepository = cipherRepository;
|
||||||
_featureService = featureService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<Cipher>> ValidateAsync(User user, IEnumerable<CipherWithIdRequestModel> ciphers)
|
public async Task<IEnumerable<Cipher>> ValidateAsync(User user, IEnumerable<CipherWithIdRequestModel> ciphers)
|
||||||
{
|
{
|
||||||
var result = new List<Cipher>();
|
var result = new List<Cipher>();
|
||||||
|
|
||||||
var existingCiphers = await _cipherRepository.GetManyByUserIdAsync(user.Id, UseFlexibleCollections);
|
var existingCiphers = await _cipherRepository.GetManyByUserIdAsync(user.Id);
|
||||||
if (existingCiphers == null)
|
if (existingCiphers == null)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
|
@ -33,10 +33,6 @@ public class EmergencyAccessService : IEmergencyAccessService
|
|||||||
private readonly IPasswordHasher<User> _passwordHasher;
|
private readonly IPasswordHasher<User> _passwordHasher;
|
||||||
private readonly IOrganizationService _organizationService;
|
private readonly IOrganizationService _organizationService;
|
||||||
private readonly IDataProtectorTokenFactory<EmergencyAccessInviteTokenable> _dataProtectorTokenizer;
|
private readonly IDataProtectorTokenFactory<EmergencyAccessInviteTokenable> _dataProtectorTokenizer;
|
||||||
private readonly IFeatureService _featureService;
|
|
||||||
|
|
||||||
private bool UseFlexibleCollections =>
|
|
||||||
_featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections);
|
|
||||||
|
|
||||||
public EmergencyAccessService(
|
public EmergencyAccessService(
|
||||||
IEmergencyAccessRepository emergencyAccessRepository,
|
IEmergencyAccessRepository emergencyAccessRepository,
|
||||||
@ -50,8 +46,7 @@ public class EmergencyAccessService : IEmergencyAccessService
|
|||||||
IPasswordHasher<User> passwordHasher,
|
IPasswordHasher<User> passwordHasher,
|
||||||
GlobalSettings globalSettings,
|
GlobalSettings globalSettings,
|
||||||
IOrganizationService organizationService,
|
IOrganizationService organizationService,
|
||||||
IDataProtectorTokenFactory<EmergencyAccessInviteTokenable> dataProtectorTokenizer,
|
IDataProtectorTokenFactory<EmergencyAccessInviteTokenable> dataProtectorTokenizer)
|
||||||
IFeatureService featureService)
|
|
||||||
{
|
{
|
||||||
_emergencyAccessRepository = emergencyAccessRepository;
|
_emergencyAccessRepository = emergencyAccessRepository;
|
||||||
_organizationUserRepository = organizationUserRepository;
|
_organizationUserRepository = organizationUserRepository;
|
||||||
@ -65,7 +60,6 @@ public class EmergencyAccessService : IEmergencyAccessService
|
|||||||
_globalSettings = globalSettings;
|
_globalSettings = globalSettings;
|
||||||
_organizationService = organizationService;
|
_organizationService = organizationService;
|
||||||
_dataProtectorTokenizer = dataProtectorTokenizer;
|
_dataProtectorTokenizer = dataProtectorTokenizer;
|
||||||
_featureService = featureService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<EmergencyAccess> InviteAsync(User invitingUser, string email, EmergencyAccessType type, int waitTime)
|
public async Task<EmergencyAccess> InviteAsync(User invitingUser, string email, EmergencyAccessType type, int waitTime)
|
||||||
@ -393,7 +387,7 @@ public class EmergencyAccessService : IEmergencyAccessService
|
|||||||
throw new BadRequestException("Emergency Access not valid.");
|
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
|
return new EmergencyAccessViewData
|
||||||
{
|
{
|
||||||
|
@ -104,11 +104,6 @@ public static class FeatureFlagKeys
|
|||||||
public const string BrowserFilelessImport = "browser-fileless-import";
|
public const string BrowserFilelessImport = "browser-fileless-import";
|
||||||
public const string ReturnErrorOnExistingKeypair = "return-error-on-existing-keypair";
|
public const string ReturnErrorOnExistingKeypair = "return-error-on-existing-keypair";
|
||||||
public const string UseTreeWalkerApiForPageDetailsCollection = "use-tree-walker-api-for-page-details-collection";
|
public const string UseTreeWalkerApiForPageDetailsCollection = "use-tree-walker-api-for-page-details-collection";
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deprecated - never used, do not use. Will always default to false. Will be deleted as part of Flexible Collections cleanup
|
|
||||||
/// </summary>
|
|
||||||
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 FlexibleCollectionsV1 = "flexible-collections-v-1"; // v-1 is intentional
|
||||||
public const string ItemShare = "item-share";
|
public const string ItemShare = "item-share";
|
||||||
public const string KeyRotationImprovements = "key-rotation-improvements";
|
public const string KeyRotationImprovements = "key-rotation-improvements";
|
||||||
|
@ -29,7 +29,7 @@ public interface ICollectionRepository : IRepository<Collection, Guid>
|
|||||||
/// Return all collections a user has access to across all of the organization they're a member of. Includes permission
|
/// Return all collections a user has access to across all of the organization they're a member of. Includes permission
|
||||||
/// details for each collection.
|
/// details for each collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Task<ICollection<CollectionDetails>> GetManyByUserIdAsync(Guid userId, bool useFlexibleCollections);
|
Task<ICollection<CollectionDetails>> GetManyByUserIdAsync(Guid userId);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns all collections for an organization, including permission info for the specified user.
|
/// Returns all collections for an organization, including permission info for the specified user.
|
||||||
|
@ -15,8 +15,6 @@ public class CollectionService : ICollectionService
|
|||||||
private readonly IOrganizationRepository _organizationRepository;
|
private readonly IOrganizationRepository _organizationRepository;
|
||||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||||
private readonly ICollectionRepository _collectionRepository;
|
private readonly ICollectionRepository _collectionRepository;
|
||||||
private readonly IUserRepository _userRepository;
|
|
||||||
private readonly IMailService _mailService;
|
|
||||||
private readonly IReferenceEventService _referenceEventService;
|
private readonly IReferenceEventService _referenceEventService;
|
||||||
private readonly ICurrentContext _currentContext;
|
private readonly ICurrentContext _currentContext;
|
||||||
private readonly IFeatureService _featureService;
|
private readonly IFeatureService _featureService;
|
||||||
@ -26,8 +24,6 @@ public class CollectionService : ICollectionService
|
|||||||
IOrganizationRepository organizationRepository,
|
IOrganizationRepository organizationRepository,
|
||||||
IOrganizationUserRepository organizationUserRepository,
|
IOrganizationUserRepository organizationUserRepository,
|
||||||
ICollectionRepository collectionRepository,
|
ICollectionRepository collectionRepository,
|
||||||
IUserRepository userRepository,
|
|
||||||
IMailService mailService,
|
|
||||||
IReferenceEventService referenceEventService,
|
IReferenceEventService referenceEventService,
|
||||||
ICurrentContext currentContext,
|
ICurrentContext currentContext,
|
||||||
IFeatureService featureService)
|
IFeatureService featureService)
|
||||||
@ -36,8 +32,6 @@ public class CollectionService : ICollectionService
|
|||||||
_organizationRepository = organizationRepository;
|
_organizationRepository = organizationRepository;
|
||||||
_organizationUserRepository = organizationUserRepository;
|
_organizationUserRepository = organizationUserRepository;
|
||||||
_collectionRepository = collectionRepository;
|
_collectionRepository = collectionRepository;
|
||||||
_userRepository = userRepository;
|
|
||||||
_mailService = mailService;
|
|
||||||
_referenceEventService = referenceEventService;
|
_referenceEventService = referenceEventService;
|
||||||
_currentContext = currentContext;
|
_currentContext = currentContext;
|
||||||
_featureService = featureService;
|
_featureService = featureService;
|
||||||
@ -128,10 +122,7 @@ public class CollectionService : ICollectionService
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var collections = await _collectionRepository.GetManyByUserIdAsync(
|
var collections = await _collectionRepository.GetManyByUserIdAsync(_currentContext.UserId.Value);
|
||||||
_currentContext.UserId.Value,
|
|
||||||
_featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections)
|
|
||||||
);
|
|
||||||
orgCollections = collections.Where(c => c.OrganizationId == organizationId);
|
orgCollections = collections.Where(c => c.OrganizationId == organizationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ public class OrganizationCiphersQuery : IOrganizationCiphersQuery
|
|||||||
throw new FeatureUnavailableException("Flexible collections is OFF when it should be ON.");
|
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 orgCiphers = ciphers.Where(c => c.OrganizationId == organizationId).ToList();
|
||||||
var orgCipherIds = orgCiphers.Select(c => c.Id);
|
var orgCipherIds = orgCiphers.Select(c => c.Id);
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ public interface ICipherRepository : IRepository<Cipher, Guid>
|
|||||||
Task<CipherOrganizationDetails> GetOrganizationDetailsByIdAsync(Guid id);
|
Task<CipherOrganizationDetails> GetOrganizationDetailsByIdAsync(Guid id);
|
||||||
Task<ICollection<CipherOrganizationDetails>> GetManyOrganizationDetailsByOrganizationIdAsync(Guid organizationId);
|
Task<ICollection<CipherOrganizationDetails>> GetManyOrganizationDetailsByOrganizationIdAsync(Guid organizationId);
|
||||||
Task<bool> GetCanEditByIdAsync(Guid userId, Guid cipherId);
|
Task<bool> GetCanEditByIdAsync(Guid userId, Guid cipherId);
|
||||||
Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId, bool useFlexibleCollections, bool withOrganizations = true);
|
Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId, bool withOrganizations = true);
|
||||||
Task<ICollection<Cipher>> GetManyByOrganizationIdAsync(Guid organizationId);
|
Task<ICollection<Cipher>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||||
Task<ICollection<CipherOrganizationDetails>> GetManyUnassignedOrganizationDetailsByOrganizationIdAsync(Guid organizationId);
|
Task<ICollection<CipherOrganizationDetails>> GetManyUnassignedOrganizationDetailsByOrganizationIdAsync(Guid organizationId);
|
||||||
Task CreateAsync(Cipher cipher, IEnumerable<Guid> collectionIds);
|
Task CreateAsync(Cipher cipher, IEnumerable<Guid> collectionIds);
|
||||||
|
@ -38,10 +38,6 @@ public class CipherService : ICipherService
|
|||||||
private const long _fileSizeLeeway = 1024L * 1024L; // 1MB
|
private const long _fileSizeLeeway = 1024L * 1024L; // 1MB
|
||||||
private readonly IReferenceEventService _referenceEventService;
|
private readonly IReferenceEventService _referenceEventService;
|
||||||
private readonly ICurrentContext _currentContext;
|
private readonly ICurrentContext _currentContext;
|
||||||
private readonly IFeatureService _featureService;
|
|
||||||
|
|
||||||
private bool UseFlexibleCollections =>
|
|
||||||
_featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections);
|
|
||||||
|
|
||||||
public CipherService(
|
public CipherService(
|
||||||
ICipherRepository cipherRepository,
|
ICipherRepository cipherRepository,
|
||||||
@ -58,8 +54,7 @@ public class CipherService : ICipherService
|
|||||||
IPolicyService policyService,
|
IPolicyService policyService,
|
||||||
GlobalSettings globalSettings,
|
GlobalSettings globalSettings,
|
||||||
IReferenceEventService referenceEventService,
|
IReferenceEventService referenceEventService,
|
||||||
ICurrentContext currentContext,
|
ICurrentContext currentContext)
|
||||||
IFeatureService featureService)
|
|
||||||
{
|
{
|
||||||
_cipherRepository = cipherRepository;
|
_cipherRepository = cipherRepository;
|
||||||
_folderRepository = folderRepository;
|
_folderRepository = folderRepository;
|
||||||
@ -76,7 +71,6 @@ public class CipherService : ICipherService
|
|||||||
_globalSettings = globalSettings;
|
_globalSettings = globalSettings;
|
||||||
_referenceEventService = referenceEventService;
|
_referenceEventService = referenceEventService;
|
||||||
_currentContext = currentContext;
|
_currentContext = currentContext;
|
||||||
_featureService = featureService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SaveAsync(Cipher cipher, Guid savingUserId, DateTime? lastKnownRevisionDate,
|
public async Task SaveAsync(Cipher cipher, Guid savingUserId, DateTime? lastKnownRevisionDate,
|
||||||
@ -430,7 +424,7 @@ public class CipherService : ICipherService
|
|||||||
}
|
}
|
||||||
else
|
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();
|
deletingCiphers = ciphers.Where(c => cipherIdsSet.Contains(c.Id) && c.Edit).Select(x => (Cipher)x).ToList();
|
||||||
|
|
||||||
await _cipherRepository.DeleteAsync(deletingCiphers.Select(c => c.Id), deletingUserId);
|
await _cipherRepository.DeleteAsync(deletingCiphers.Select(c => c.Id), deletingUserId);
|
||||||
@ -872,7 +866,7 @@ public class CipherService : ICipherService
|
|||||||
}
|
}
|
||||||
else
|
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();
|
deletingCiphers = ciphers.Where(c => cipherIdsSet.Contains(c.Id) && c.Edit).Select(x => (Cipher)x).ToList();
|
||||||
|
|
||||||
await _cipherRepository.SoftDeleteAsync(deletingCiphers.Select(c => c.Id), deletingUserId);
|
await _cipherRepository.SoftDeleteAsync(deletingCiphers.Select(c => c.Id), deletingUserId);
|
||||||
@ -938,7 +932,7 @@ public class CipherService : ICipherService
|
|||||||
}
|
}
|
||||||
else
|
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();
|
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);
|
revisionDate = await _cipherRepository.RestoreAsync(restoringCiphers.Select(c => c.Id), restoringUserId);
|
||||||
@ -976,7 +970,7 @@ public class CipherService : ICipherService
|
|||||||
}
|
}
|
||||||
else
|
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);
|
orgCiphers = ciphers.Where(c => c.OrganizationId == organizationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,16 +120,12 @@ public class CollectionRepository : Repository<Collection, Guid>, ICollectionRep
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ICollection<CollectionDetails>> GetManyByUserIdAsync(Guid userId, bool useFlexibleCollections)
|
public async Task<ICollection<CollectionDetails>> GetManyByUserIdAsync(Guid userId)
|
||||||
{
|
{
|
||||||
var sprocName = useFlexibleCollections
|
|
||||||
? $"[{Schema}].[Collection_ReadByUserId_V2]"
|
|
||||||
: $"[{Schema}].[Collection_ReadByUserId]";
|
|
||||||
|
|
||||||
using (var connection = new SqlConnection(ConnectionString))
|
using (var connection = new SqlConnection(ConnectionString))
|
||||||
{
|
{
|
||||||
var results = await connection.QueryAsync<CollectionDetails>(
|
var results = await connection.QueryAsync<CollectionDetails>(
|
||||||
sprocName,
|
$"[{Schema}].[Collection_ReadByUserId]",
|
||||||
new { UserId = userId },
|
new { UserId = userId },
|
||||||
commandType: CommandType.StoredProcedure);
|
commandType: CommandType.StoredProcedure);
|
||||||
|
|
||||||
|
@ -77,14 +77,12 @@ public class CipherRepository : Repository<Cipher, Guid>, ICipherRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId, bool useFlexibleCollections, bool withOrganizations = true)
|
public async Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId, bool withOrganizations = true)
|
||||||
{
|
{
|
||||||
string sprocName = null;
|
string sprocName = null;
|
||||||
if (withOrganizations)
|
if (withOrganizations)
|
||||||
{
|
{
|
||||||
sprocName = useFlexibleCollections
|
sprocName = $"[{Schema}].[CipherDetails_ReadByUserId]";
|
||||||
? $"[{Schema}].[CipherDetails_ReadByUserId_V2]"
|
|
||||||
: $"[{Schema}].[CipherDetails_ReadByUserId]";
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -221,7 +221,7 @@ public class CollectionRepository : Repository<Core.Entities.Collection, Collect
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ICollection<CollectionDetails>> GetManyByUserIdAsync(Guid userId, bool useFlexibleCollections)
|
public async Task<ICollection<CollectionDetails>> GetManyByUserIdAsync(Guid userId)
|
||||||
{
|
{
|
||||||
using (var scope = ServiceScopeFactory.CreateScope())
|
using (var scope = ServiceScopeFactory.CreateScope())
|
||||||
{
|
{
|
||||||
|
@ -359,7 +359,7 @@ public class CipherRepository : Repository<Core.Vault.Entities.Cipher, Cipher, G
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId, bool useFlexibleCollections, bool withOrganizations = true)
|
public async Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId, bool withOrganizations = true)
|
||||||
{
|
{
|
||||||
using (var scope = ServiceScopeFactory.CreateScope())
|
using (var scope = ServiceScopeFactory.CreateScope())
|
||||||
{
|
{
|
||||||
|
@ -214,13 +214,13 @@ public class CollectionsControllerTests
|
|||||||
.Returns(AuthorizationResult.Success());
|
.Returns(AuthorizationResult.Success());
|
||||||
|
|
||||||
sutProvider.GetDependency<ICollectionRepository>()
|
sutProvider.GetDependency<ICollectionRepository>()
|
||||||
.GetManyByUserIdAsync(userId, false)
|
.GetManyByUserIdAsync(userId)
|
||||||
.Returns(collections);
|
.Returns(collections);
|
||||||
|
|
||||||
var result = await sutProvider.Sut.Get(organization.Id);
|
var result = await sutProvider.Sut.Get(organization.Id);
|
||||||
|
|
||||||
await sutProvider.GetDependency<ICollectionRepository>().DidNotReceive().GetManyByOrganizationIdAsync(organization.Id);
|
await sutProvider.GetDependency<ICollectionRepository>().DidNotReceive().GetManyByOrganizationIdAsync(organization.Id);
|
||||||
await sutProvider.GetDependency<ICollectionRepository>().Received(1).GetManyByUserIdAsync(userId, false);
|
await sutProvider.GetDependency<ICollectionRepository>().Received(1).GetManyByUserIdAsync(userId);
|
||||||
|
|
||||||
Assert.Single(result.Data);
|
Assert.Single(result.Data);
|
||||||
Assert.All(result.Data, c => Assert.Equal(organization.Id, c.OrganizationId));
|
Assert.All(result.Data, c => Assert.Equal(organization.Id, c.OrganizationId));
|
||||||
|
@ -236,7 +236,7 @@ public class BulkCollectionAuthorizationHandlerTests
|
|||||||
{
|
{
|
||||||
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
||||||
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
||||||
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId, Arg.Any<bool>()).Returns(collections);
|
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId).Returns(collections);
|
||||||
|
|
||||||
var context = new AuthorizationHandlerContext(
|
var context = new AuthorizationHandlerContext(
|
||||||
new[] { BulkCollectionOperations.Read },
|
new[] { BulkCollectionOperations.Read },
|
||||||
@ -439,7 +439,7 @@ public class BulkCollectionAuthorizationHandlerTests
|
|||||||
|
|
||||||
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
||||||
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
||||||
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId, Arg.Any<bool>()).Returns(collections);
|
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId).Returns(collections);
|
||||||
|
|
||||||
var context = new AuthorizationHandlerContext(
|
var context = new AuthorizationHandlerContext(
|
||||||
new[] { BulkCollectionOperations.ReadWithAccess },
|
new[] { BulkCollectionOperations.ReadWithAccess },
|
||||||
@ -469,7 +469,7 @@ public class BulkCollectionAuthorizationHandlerTests
|
|||||||
|
|
||||||
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
||||||
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
||||||
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId, Arg.Any<bool>()).Returns(collections);
|
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId).Returns(collections);
|
||||||
|
|
||||||
var context = new AuthorizationHandlerContext(
|
var context = new AuthorizationHandlerContext(
|
||||||
new[] { BulkCollectionOperations.ReadWithAccess },
|
new[] { BulkCollectionOperations.ReadWithAccess },
|
||||||
@ -725,7 +725,7 @@ public class BulkCollectionAuthorizationHandlerTests
|
|||||||
{
|
{
|
||||||
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
||||||
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
||||||
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId, Arg.Any<bool>()).Returns(collections);
|
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId).Returns(collections);
|
||||||
|
|
||||||
var context = new AuthorizationHandlerContext(
|
var context = new AuthorizationHandlerContext(
|
||||||
new[] { op },
|
new[] { op },
|
||||||
@ -1090,7 +1090,7 @@ public class BulkCollectionAuthorizationHandlerTests
|
|||||||
|
|
||||||
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
||||||
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
||||||
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId, Arg.Any<bool>()).Returns(collections);
|
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId).Returns(collections);
|
||||||
|
|
||||||
foreach (var c in collections)
|
foreach (var c in collections)
|
||||||
{
|
{
|
||||||
@ -1126,7 +1126,7 @@ public class BulkCollectionAuthorizationHandlerTests
|
|||||||
|
|
||||||
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
||||||
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
||||||
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId, Arg.Any<bool>()).Returns(collections);
|
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId).Returns(collections);
|
||||||
sutProvider.GetDependency<IFeatureService>().IsEnabled(FeatureFlagKeys.FlexibleCollectionsV1).Returns(true);
|
sutProvider.GetDependency<IFeatureService>().IsEnabled(FeatureFlagKeys.FlexibleCollectionsV1).Returns(true);
|
||||||
|
|
||||||
foreach (var c in collections)
|
foreach (var c in collections)
|
||||||
@ -1162,7 +1162,7 @@ public class BulkCollectionAuthorizationHandlerTests
|
|||||||
|
|
||||||
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
||||||
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
||||||
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId, Arg.Any<bool>()).Returns(collections);
|
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId).Returns(collections);
|
||||||
sutProvider.GetDependency<IFeatureService>().IsEnabled(FeatureFlagKeys.FlexibleCollectionsV1).Returns(true);
|
sutProvider.GetDependency<IFeatureService>().IsEnabled(FeatureFlagKeys.FlexibleCollectionsV1).Returns(true);
|
||||||
|
|
||||||
foreach (var c in collections)
|
foreach (var c in collections)
|
||||||
@ -1198,7 +1198,7 @@ public class BulkCollectionAuthorizationHandlerTests
|
|||||||
|
|
||||||
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
||||||
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
||||||
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId, Arg.Any<bool>()).Returns(collections);
|
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId).Returns(collections);
|
||||||
sutProvider.GetDependency<IFeatureService>().IsEnabled(FeatureFlagKeys.FlexibleCollectionsV1).Returns(true);
|
sutProvider.GetDependency<IFeatureService>().IsEnabled(FeatureFlagKeys.FlexibleCollectionsV1).Returns(true);
|
||||||
sutProvider.GetDependency<ICurrentContext>().ProviderUserForOrgAsync(Arg.Any<Guid>()).Returns(false);
|
sutProvider.GetDependency<ICurrentContext>().ProviderUserForOrgAsync(Arg.Any<Guid>()).Returns(false);
|
||||||
|
|
||||||
@ -1232,7 +1232,7 @@ public class BulkCollectionAuthorizationHandlerTests
|
|||||||
|
|
||||||
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
||||||
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
||||||
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId, Arg.Any<bool>()).Returns(collections);
|
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId).Returns(collections);
|
||||||
sutProvider.GetDependency<IFeatureService>().IsEnabled(FeatureFlagKeys.FlexibleCollectionsV1).Returns(true);
|
sutProvider.GetDependency<IFeatureService>().IsEnabled(FeatureFlagKeys.FlexibleCollectionsV1).Returns(true);
|
||||||
sutProvider.GetDependency<ICurrentContext>().ProviderUserForOrgAsync(Arg.Any<Guid>()).Returns(false);
|
sutProvider.GetDependency<ICurrentContext>().ProviderUserForOrgAsync(Arg.Any<Guid>()).Returns(false);
|
||||||
|
|
||||||
@ -1266,7 +1266,7 @@ public class BulkCollectionAuthorizationHandlerTests
|
|||||||
|
|
||||||
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
||||||
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
||||||
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId, Arg.Any<bool>()).Returns(collections);
|
sutProvider.GetDependency<ICollectionRepository>().GetManyByUserIdAsync(actingUserId).Returns(collections);
|
||||||
sutProvider.GetDependency<IFeatureService>().IsEnabled(FeatureFlagKeys.FlexibleCollectionsV1).Returns(true);
|
sutProvider.GetDependency<IFeatureService>().IsEnabled(FeatureFlagKeys.FlexibleCollectionsV1).Returns(true);
|
||||||
sutProvider.GetDependency<ICurrentContext>().ProviderUserForOrgAsync(Arg.Any<Guid>()).Returns(false);
|
sutProvider.GetDependency<ICurrentContext>().ProviderUserForOrgAsync(Arg.Any<Guid>()).Returns(false);
|
||||||
|
|
||||||
@ -1449,7 +1449,7 @@ public class BulkCollectionAuthorizationHandlerTests
|
|||||||
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(actingUserId);
|
||||||
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
sutProvider.GetDependency<ICurrentContext>().GetOrganization(organization.Id).Returns(organization);
|
||||||
sutProvider.GetDependency<ICollectionRepository>()
|
sutProvider.GetDependency<ICollectionRepository>()
|
||||||
.GetManyByUserIdAsync(actingUserId, Arg.Any<bool>())
|
.GetManyByUserIdAsync(actingUserId)
|
||||||
.Returns(new List<CollectionDetails>() { collection1, collection2 });
|
.Returns(new List<CollectionDetails>() { collection1, collection2 });
|
||||||
|
|
||||||
var context1 = new AuthorizationHandlerContext(
|
var context1 = new AuthorizationHandlerContext(
|
||||||
@ -1467,7 +1467,7 @@ public class BulkCollectionAuthorizationHandlerTests
|
|||||||
await sutProvider.Sut.HandleAsync(context2);
|
await sutProvider.Sut.HandleAsync(context2);
|
||||||
|
|
||||||
// Expect: only calls the database once
|
// Expect: only calls the database once
|
||||||
await sutProvider.GetDependency<ICollectionRepository>().Received(1).GetManyByUserIdAsync(Arg.Any<Guid>(), Arg.Any<bool>());
|
await sutProvider.GetDependency<ICollectionRepository>().Received(1).GetManyByUserIdAsync(Arg.Any<Guid>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ArrangeOrganizationAbility(
|
private static void ArrangeOrganizationAbility(
|
||||||
|
@ -107,7 +107,7 @@ public class SyncControllerTests
|
|||||||
.Returns(providerUserOrganizationDetails);
|
.Returns(providerUserOrganizationDetails);
|
||||||
|
|
||||||
folderRepository.GetManyByUserIdAsync(user.Id).Returns(folders);
|
folderRepository.GetManyByUserIdAsync(user.Id).Returns(folders);
|
||||||
cipherRepository.GetManyByUserIdAsync(user.Id, useFlexibleCollections: Arg.Any<bool>()).Returns(ciphers);
|
cipherRepository.GetManyByUserIdAsync(user.Id).Returns(ciphers);
|
||||||
|
|
||||||
sendRepository
|
sendRepository
|
||||||
.GetManyByUserIdAsync(user.Id).Returns(sends);
|
.GetManyByUserIdAsync(user.Id).Returns(sends);
|
||||||
@ -115,7 +115,7 @@ public class SyncControllerTests
|
|||||||
policyRepository.GetManyByUserIdAsync(user.Id).Returns(policies);
|
policyRepository.GetManyByUserIdAsync(user.Id).Returns(policies);
|
||||||
|
|
||||||
// Returns for methods only called if we have enabled orgs
|
// Returns for methods only called if we have enabled orgs
|
||||||
collectionRepository.GetManyByUserIdAsync(user.Id, Arg.Any<bool>()).Returns(collections);
|
collectionRepository.GetManyByUserIdAsync(user.Id).Returns(collections);
|
||||||
collectionCipherRepository.GetManyByUserIdAsync(user.Id).Returns(new List<CollectionCipher>());
|
collectionCipherRepository.GetManyByUserIdAsync(user.Id).Returns(new List<CollectionCipher>());
|
||||||
// Back to standard test setup
|
// Back to standard test setup
|
||||||
userService.TwoFactorIsEnabledAsync(user).Returns(false);
|
userService.TwoFactorIsEnabledAsync(user).Returns(false);
|
||||||
@ -197,7 +197,7 @@ public class SyncControllerTests
|
|||||||
.Returns(providerUserOrganizationDetails);
|
.Returns(providerUserOrganizationDetails);
|
||||||
|
|
||||||
folderRepository.GetManyByUserIdAsync(user.Id).Returns(folders);
|
folderRepository.GetManyByUserIdAsync(user.Id).Returns(folders);
|
||||||
cipherRepository.GetManyByUserIdAsync(user.Id, useFlexibleCollections: Arg.Any<bool>()).Returns(ciphers);
|
cipherRepository.GetManyByUserIdAsync(user.Id).Returns(ciphers);
|
||||||
|
|
||||||
sendRepository
|
sendRepository
|
||||||
.GetManyByUserIdAsync(user.Id).Returns(sends);
|
.GetManyByUserIdAsync(user.Id).Returns(sends);
|
||||||
@ -271,7 +271,7 @@ public class SyncControllerTests
|
|||||||
.Returns(providerUserOrganizationDetails);
|
.Returns(providerUserOrganizationDetails);
|
||||||
|
|
||||||
folderRepository.GetManyByUserIdAsync(user.Id).Returns(folders);
|
folderRepository.GetManyByUserIdAsync(user.Id).Returns(folders);
|
||||||
cipherRepository.GetManyByUserIdAsync(user.Id, useFlexibleCollections: Arg.Any<bool>()).Returns(ciphers);
|
cipherRepository.GetManyByUserIdAsync(user.Id).Returns(ciphers);
|
||||||
|
|
||||||
sendRepository
|
sendRepository
|
||||||
.GetManyByUserIdAsync(user.Id).Returns(sends);
|
.GetManyByUserIdAsync(user.Id).Returns(sends);
|
||||||
@ -279,7 +279,7 @@ public class SyncControllerTests
|
|||||||
policyRepository.GetManyByUserIdAsync(user.Id).Returns(policies);
|
policyRepository.GetManyByUserIdAsync(user.Id).Returns(policies);
|
||||||
|
|
||||||
// Returns for methods only called if we have enabled orgs
|
// Returns for methods only called if we have enabled orgs
|
||||||
collectionRepository.GetManyByUserIdAsync(user.Id, Arg.Any<bool>()).Returns(collections);
|
collectionRepository.GetManyByUserIdAsync(user.Id).Returns(collections);
|
||||||
collectionCipherRepository.GetManyByUserIdAsync(user.Id).Returns(new List<CollectionCipher>());
|
collectionCipherRepository.GetManyByUserIdAsync(user.Id).Returns(new List<CollectionCipher>());
|
||||||
// Back to standard test setup
|
// Back to standard test setup
|
||||||
userService.TwoFactorIsEnabledAsync(user).Returns(false);
|
userService.TwoFactorIsEnabledAsync(user).Returns(false);
|
||||||
@ -333,7 +333,7 @@ public class SyncControllerTests
|
|||||||
.GetManyByUserIdAsync(default);
|
.GetManyByUserIdAsync(default);
|
||||||
|
|
||||||
await cipherRepository.ReceivedWithAnyArgs(1)
|
await cipherRepository.ReceivedWithAnyArgs(1)
|
||||||
.GetManyByUserIdAsync(default, useFlexibleCollections: default);
|
.GetManyByUserIdAsync(default);
|
||||||
|
|
||||||
await sendRepository.ReceivedWithAnyArgs(1)
|
await sendRepository.ReceivedWithAnyArgs(1)
|
||||||
.GetManyByUserIdAsync(default);
|
.GetManyByUserIdAsync(default);
|
||||||
@ -342,7 +342,7 @@ public class SyncControllerTests
|
|||||||
if (hasEnabledOrgs)
|
if (hasEnabledOrgs)
|
||||||
{
|
{
|
||||||
await collectionRepository.ReceivedWithAnyArgs(1)
|
await collectionRepository.ReceivedWithAnyArgs(1)
|
||||||
.GetManyByUserIdAsync(default, default);
|
.GetManyByUserIdAsync(default);
|
||||||
await collectionCipherRepository.ReceivedWithAnyArgs(1)
|
await collectionCipherRepository.ReceivedWithAnyArgs(1)
|
||||||
.GetManyByUserIdAsync(default);
|
.GetManyByUserIdAsync(default);
|
||||||
}
|
}
|
||||||
@ -350,7 +350,7 @@ public class SyncControllerTests
|
|||||||
{
|
{
|
||||||
// all disabled orgs
|
// all disabled orgs
|
||||||
await collectionRepository.ReceivedWithAnyArgs(0)
|
await collectionRepository.ReceivedWithAnyArgs(0)
|
||||||
.GetManyByUserIdAsync(default, default);
|
.GetManyByUserIdAsync(default);
|
||||||
await collectionCipherRepository.ReceivedWithAnyArgs(0)
|
await collectionCipherRepository.ReceivedWithAnyArgs(0)
|
||||||
.GetManyByUserIdAsync(default);
|
.GetManyByUserIdAsync(default);
|
||||||
}
|
}
|
||||||
|
@ -197,7 +197,7 @@ public class CollectionServiceTest
|
|||||||
Assert.Equal(collection, result.First());
|
Assert.Equal(collection, result.First());
|
||||||
|
|
||||||
await sutProvider.GetDependency<ICollectionRepository>().Received(1).GetManyByOrganizationIdAsync(organizationId);
|
await sutProvider.GetDependency<ICollectionRepository>().Received(1).GetManyByOrganizationIdAsync(organizationId);
|
||||||
await sutProvider.GetDependency<ICollectionRepository>().DidNotReceiveWithAnyArgs().GetManyByUserIdAsync(default, default);
|
await sutProvider.GetDependency<ICollectionRepository>().DidNotReceiveWithAnyArgs().GetManyByUserIdAsync(default);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
@ -207,6 +207,6 @@ public class CollectionServiceTest
|
|||||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.GetOrganizationCollectionsAsync(organizationId));
|
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.GetOrganizationCollectionsAsync(organizationId));
|
||||||
|
|
||||||
await sutProvider.GetDependency<ICollectionRepository>().DidNotReceiveWithAnyArgs().GetManyByOrganizationIdAsync(default);
|
await sutProvider.GetDependency<ICollectionRepository>().DidNotReceiveWithAnyArgs().GetManyByOrganizationIdAsync(default);
|
||||||
await sutProvider.GetDependency<ICollectionRepository>().DidNotReceiveWithAnyArgs().GetManyByUserIdAsync(default, default);
|
await sutProvider.GetDependency<ICollectionRepository>().DidNotReceiveWithAnyArgs().GetManyByUserIdAsync(default);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -677,7 +677,7 @@ public class CipherServiceTests
|
|||||||
cipher.RevisionDate = previousRevisionDate;
|
cipher.RevisionDate = previousRevisionDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
sutProvider.GetDependency<ICipherRepository>().GetManyByUserIdAsync(restoringUserId, useFlexibleCollections: Arg.Any<bool>()).Returns(ciphers);
|
sutProvider.GetDependency<ICipherRepository>().GetManyByUserIdAsync(restoringUserId).Returns(ciphers);
|
||||||
var revisionDate = previousRevisionDate + TimeSpan.FromMinutes(1);
|
var revisionDate = previousRevisionDate + TimeSpan.FromMinutes(1);
|
||||||
sutProvider.GetDependency<ICipherRepository>().RestoreAsync(Arg.Any<IEnumerable<Guid>>(), restoringUserId).Returns(revisionDate);
|
sutProvider.GetDependency<ICipherRepository>().RestoreAsync(Arg.Any<IEnumerable<Guid>>(), restoringUserId).Returns(revisionDate);
|
||||||
|
|
||||||
@ -791,7 +791,7 @@ public class CipherServiceTests
|
|||||||
await sutProvider.GetDependency<ICipherRepository>().DidNotReceiveWithAnyArgs().GetManyOrganizationDetailsByOrganizationIdAsync(default);
|
await sutProvider.GetDependency<ICipherRepository>().DidNotReceiveWithAnyArgs().GetManyOrganizationDetailsByOrganizationIdAsync(default);
|
||||||
await sutProvider.GetDependency<ICipherRepository>().DidNotReceiveWithAnyArgs().RestoreByIdsOrganizationIdAsync(default, default);
|
await sutProvider.GetDependency<ICipherRepository>().DidNotReceiveWithAnyArgs().RestoreByIdsOrganizationIdAsync(default, default);
|
||||||
await sutProvider.GetDependency<ICipherRepository>().DidNotReceiveWithAnyArgs().RestoreByIdsOrganizationIdAsync(default, default);
|
await sutProvider.GetDependency<ICipherRepository>().DidNotReceiveWithAnyArgs().RestoreByIdsOrganizationIdAsync(default, default);
|
||||||
await sutProvider.GetDependency<ICipherRepository>().DidNotReceiveWithAnyArgs().GetManyByUserIdAsync(default, useFlexibleCollections: default);
|
await sutProvider.GetDependency<ICipherRepository>().DidNotReceiveWithAnyArgs().GetManyByUserIdAsync(default);
|
||||||
await sutProvider.GetDependency<ICipherRepository>().DidNotReceiveWithAnyArgs().RestoreAsync(default, default);
|
await sutProvider.GetDependency<ICipherRepository>().DidNotReceiveWithAnyArgs().RestoreAsync(default, default);
|
||||||
await sutProvider.GetDependency<IEventService>().DidNotReceiveWithAnyArgs().LogCipherEventsAsync(default);
|
await sutProvider.GetDependency<IEventService>().DidNotReceiveWithAnyArgs().LogCipherEventsAsync(default);
|
||||||
await sutProvider.GetDependency<IPushNotificationService>().DidNotReceiveWithAnyArgs().PushSyncCiphersAsync(default);
|
await sutProvider.GetDependency<IPushNotificationService>().DidNotReceiveWithAnyArgs().PushSyncCiphersAsync(default);
|
||||||
|
Loading…
Reference in New Issue
Block a user