@ -27,6 +27,7 @@ public class CipherService : ICipherService
@@ -27,6 +27,7 @@ public class CipherService : ICipherService
private readonly ICollectionRepository _ collectionRepository ;
private readonly IUserRepository _ userRepository ;
private readonly IOrganizationRepository _ organizationRepository ;
private readonly IOrganizationUserRepository _ organizationUserRepository ;
private readonly ICollectionCipherRepository _ collectionCipherRepository ;
private readonly IPushNotificationService _ pushService ;
private readonly IAttachmentStorageService _ attachmentStorageService ;
@ -34,7 +35,7 @@ public class CipherService : ICipherService
@@ -34,7 +35,7 @@ public class CipherService : ICipherService
private readonly IUserService _ userService ;
private readonly IPolicyService _ policyService ;
private readonly GlobalSettings _ globalSettings ;
private const long _f ileSizeLeeway = 1 0 2 4L * 1 0 2 4L ; // 1MB
private const long _f ileSizeLeeway = 1 0 2 4L * 1 0 2 4L ; // 1MB
private readonly IReferenceEventService _ referenceEventService ;
private readonly ICurrentContext _ currentContext ;
@ -44,6 +45,7 @@ public class CipherService : ICipherService
@@ -44,6 +45,7 @@ public class CipherService : ICipherService
ICollectionRepository collectionRepository ,
IUserRepository userRepository ,
IOrganizationRepository organizationRepository ,
IOrganizationUserRepository organizationUserRepository ,
ICollectionCipherRepository collectionCipherRepository ,
IPushNotificationService pushService ,
IAttachmentStorageService attachmentStorageService ,
@ -59,6 +61,7 @@ public class CipherService : ICipherService
@@ -59,6 +61,7 @@ public class CipherService : ICipherService
_ collectionRepository = collectionRepository ;
_ userRepository = userRepository ;
_ organizationRepository = organizationRepository ;
_ organizationUserRepository = organizationUserRepository ;
_ collectionCipherRepository = collectionCipherRepository ;
_ pushService = pushService ;
_ attachmentStorageService = attachmentStorageService ;
@ -652,7 +655,7 @@ public class CipherService : ICipherService
@@ -652,7 +655,7 @@ public class CipherService : ICipherService
cipher . RevisionDate = DateTime . UtcNow ;
// The sprocs will validate that all collections belong to this org/user and that they have
// The sprocs will validate that all collections belong to this org/user and that they have
// proper write permissions.
if ( orgAdmin )
{
@ -747,6 +750,7 @@ public class CipherService : ICipherService
@@ -747,6 +750,7 @@ public class CipherService : ICipherService
var org = collections . Count > 0 ?
await _ organizationRepository . GetByIdAsync ( collections [ 0 ] . OrganizationId ) :
await _ organizationRepository . GetByIdAsync ( ciphers . FirstOrDefault ( c = > c . OrganizationId . HasValue ) . OrganizationId . Value ) ;
var importingOrgUser = await _ organizationUserRepository . GetByOrganizationAsync ( org . Id , importingUserId ) ;
if ( collections . Count > 0 & & org ! = null & & org . MaxCollections . HasValue )
{
@ -764,18 +768,25 @@ public class CipherService : ICipherService
@@ -764,18 +768,25 @@ public class CipherService : ICipherService
cipher . SetNewId ( ) ;
}
var user CollectionsIds = ( await _ collectionRepository . GetManyByOrganizationIdAsync ( org . Id ) ) . Select ( c = > c . Id ) . ToList ( ) ;
var organization CollectionsIds = ( await _ collectionRepository . GetManyByOrganizationIdAsync ( org . Id ) ) . Select ( c = > c . Id ) . ToList ( ) ;
//Assign id to the ones that don't exist in DB
//Need to keep the list order to create the relationships
List < Collection > newCollections = new List < Collection > ( ) ;
var newCollections = new List < Collection > ( ) ;
var newCollectionUsers = new List < CollectionUser > ( ) ;
foreach ( var collection in collections )
{
if ( ! user CollectionsIds. Contains ( collection . Id ) )
if ( ! organization CollectionsIds. Contains ( collection . Id ) )
{
collection . SetNewId ( ) ;
newCollections . Add ( collection ) ;
newCollectionUsers . Add ( new CollectionUser
{
CollectionId = collection . Id ,
OrganizationUserId = importingOrgUser . Id ,
Manage = true
} ) ;
}
}
@ -799,7 +810,7 @@ public class CipherService : ICipherService
@@ -799,7 +810,7 @@ public class CipherService : ICipherService
}
// Create it all
await _ cipherRepository . CreateAsync ( ciphers , newCollections , collectionCiphers ) ;
await _ cipherRepository . CreateAsync ( ciphers , newCollections , collectionCiphers , newCollectionUsers ) ;
// push
await _ pushService . PushSyncVaultAsync ( importingUserId ) ;