mirror of
https://github.com/bitwarden/server.git
synced 2025-04-16 18:48:16 -05:00
check collection count on org import
This commit is contained in:
parent
2307c8c19c
commit
c92ef08664
@ -16,6 +16,7 @@ namespace Bit.Core.Services
|
|||||||
{
|
{
|
||||||
private readonly ICipherRepository _cipherRepository;
|
private readonly ICipherRepository _cipherRepository;
|
||||||
private readonly IFolderRepository _folderRepository;
|
private readonly IFolderRepository _folderRepository;
|
||||||
|
private readonly ICollectionRepository _collectionRepository;
|
||||||
private readonly IUserRepository _userRepository;
|
private readonly IUserRepository _userRepository;
|
||||||
private readonly IOrganizationRepository _organizationRepository;
|
private readonly IOrganizationRepository _organizationRepository;
|
||||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||||
@ -27,6 +28,7 @@ namespace Bit.Core.Services
|
|||||||
public CipherService(
|
public CipherService(
|
||||||
ICipherRepository cipherRepository,
|
ICipherRepository cipherRepository,
|
||||||
IFolderRepository folderRepository,
|
IFolderRepository folderRepository,
|
||||||
|
ICollectionRepository collectionRepository,
|
||||||
IUserRepository userRepository,
|
IUserRepository userRepository,
|
||||||
IOrganizationRepository organizationRepository,
|
IOrganizationRepository organizationRepository,
|
||||||
IOrganizationUserRepository organizationUserRepository,
|
IOrganizationUserRepository organizationUserRepository,
|
||||||
@ -37,6 +39,7 @@ namespace Bit.Core.Services
|
|||||||
{
|
{
|
||||||
_cipherRepository = cipherRepository;
|
_cipherRepository = cipherRepository;
|
||||||
_folderRepository = folderRepository;
|
_folderRepository = folderRepository;
|
||||||
|
_collectionRepository = collectionRepository;
|
||||||
_userRepository = userRepository;
|
_userRepository = userRepository;
|
||||||
_organizationRepository = organizationRepository;
|
_organizationRepository = organizationRepository;
|
||||||
_organizationUserRepository = organizationUserRepository;
|
_organizationUserRepository = organizationUserRepository;
|
||||||
@ -529,6 +532,20 @@ namespace Bit.Core.Services
|
|||||||
IEnumerable<KeyValuePair<int, int>> collectionRelationships,
|
IEnumerable<KeyValuePair<int, int>> collectionRelationships,
|
||||||
Guid importingUserId)
|
Guid importingUserId)
|
||||||
{
|
{
|
||||||
|
if(collections.Count > 0)
|
||||||
|
{
|
||||||
|
var org = await _organizationRepository.GetByIdAsync(collections[0].OrganizationId);
|
||||||
|
if(org != null && org.MaxCollections.HasValue)
|
||||||
|
{
|
||||||
|
var collectionCount = await _collectionRepository.GetCountByOrganizationIdAsync(org.Id);
|
||||||
|
if(org.MaxCollections.Value <= (collectionCount + collections.Count))
|
||||||
|
{
|
||||||
|
throw new BadRequestException("This organization can only have a maximum of " +
|
||||||
|
$"{org.MaxCollections.Value} collections.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Init. ids for ciphers
|
// Init. ids for ciphers
|
||||||
foreach(var cipher in ciphers)
|
foreach(var cipher in ciphers)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user